improved performance, <400 microseconds on my machine :3
This commit is contained in:
parent
e1dadd9fbf
commit
510af8705b
4 changed files with 17 additions and 8931 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
30
4_2/main.c
30
4_2/main.c
|
|
@ -33,10 +33,10 @@ void print_field(uint8_t* surrounds){
|
|||
for(int x = 0; x < height; x++){
|
||||
for(int y = 0; y < width; y++){
|
||||
if((surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
printf(ANSI_COLOR_GREEN"%d\t", surrounds[(x)*(width+2)+(y)]-0x80);
|
||||
printf(ANSI_COLOR_GREEN"%d\t", (surrounds[(x)*(width+2)+(y)]-0x80)&0b10111111);
|
||||
}else{
|
||||
//printf("%c", input[(x)*(width+1)+(y)]);
|
||||
printf(ANSI_COLOR_RED "%d\t", surrounds[(x)*(width+2)+(y)]);
|
||||
printf(ANSI_COLOR_RED "%d\t", surrounds[(x)*(width+2)+(y)]&0b10111111);
|
||||
}
|
||||
}
|
||||
printf(ANSI_COLOR_RESET "\n");
|
||||
|
|
@ -133,6 +133,8 @@ int main(int argc, char *argv[]){
|
|||
surrounds[(x+1)*(width+2)+(y-1)] -= 1;
|
||||
surrounds[(x+1)*(width+2)+(y)] -= 1;
|
||||
surrounds[(x+1)*(width+2)+(y+1)] -= 1;
|
||||
|
||||
surrounds[(x)*(width+2)+(y)] -= 0x40;
|
||||
//printf("removed %d, %d\n", removes[i*2], removes[i*2+1]);
|
||||
//print_field(surrounds);
|
||||
}
|
||||
|
|
@ -144,28 +146,22 @@ int main(int argc, char *argv[]){
|
|||
int y = removes[i*2+1];
|
||||
for(int xd = -1; xd<=1; xd++){
|
||||
for(int yd = -1; yd<=1; yd++){
|
||||
if((surrounds[(x+xd)*(width+2)+(y+yd)]&0x7f) < 4 && (surrounds[(x+xd)*(width+2)+(y+yd)]&0x80) == 0x80){
|
||||
if((surrounds[(x+xd)*(width+2)+(y+yd)]&0x3f) < 4 && (surrounds[(x+xd)*(width+2)+(y+yd)]&0x80) == 0x80 && (surrounds[(x+xd)*(width+2)+(y+yd)]&0x40) != 0x40){
|
||||
//this if clause should be irrellevant, because the paper roll is already removed
|
||||
if(!(xd == 0 && yd == 0)){
|
||||
bool repeat = false;
|
||||
for(int o = 0; o < new_count_2; o++){
|
||||
if(new_removes[o*2] == x+xd &&
|
||||
new_removes[o*2+1] == y+yd){
|
||||
repeat = true;
|
||||
}
|
||||
}
|
||||
//if(!(xd == 0 && yd == 0)){
|
||||
|
||||
if(!repeat){
|
||||
new_removes[new_count_2*2] = x+xd;
|
||||
new_removes[new_count_2*2+1] = y+yd;
|
||||
|
||||
//tag for removal in surrounds, for quicker checking
|
||||
surrounds[(x+xd)*(width+2)+(y+yd)] += 0x40;
|
||||
//printf("Tagged for removal %d, %d\n", new_removes[new_count_2*2], new_removes[new_count_2*2+1]);
|
||||
new_count_2++;
|
||||
}
|
||||
}
|
||||
}if((surrounds[(x)*(width+2)+(y)]&0x7f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//}
|
||||
}//if((surrounds[(x)*(width+2)+(y)]&0x4f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
cont = false;
|
||||
}
|
||||
//cont = false;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue