cleaned up a bit.....
This commit is contained in:
parent
510af8705b
commit
d5d06cf18d
1 changed files with 13 additions and 64 deletions
77
4_2/main.c
77
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)&0b10111111);
|
||||
printf(ANSI_COLOR_GREEN"%d\t", (surrounds[(x)*(width+2)+(y)]-0x80));
|
||||
}else{
|
||||
//printf("%c", input[(x)*(width+1)+(y)]);
|
||||
printf(ANSI_COLOR_RED "%d\t", surrounds[(x)*(width+2)+(y)]&0b10111111);
|
||||
printf(ANSI_COLOR_RED "%d\t", surrounds[(x)*(width+2)+(y)]);
|
||||
}
|
||||
}
|
||||
printf(ANSI_COLOR_RESET "\n");
|
||||
|
|
@ -74,15 +74,8 @@ int main(int argc, char *argv[]){
|
|||
surrounds[(x+1)*(width+2)+(y)] += 1;
|
||||
surrounds[(x+1)*(width+2)+(y+1)] += 1;
|
||||
}
|
||||
//if(surrounds[(x)*width+(y)] < 8 && input[(x)*(width+1)+(y)] == '@'){
|
||||
// printf("%d", surrounds[(x)*(width+2)+(y)]);
|
||||
//}else{
|
||||
// printf("%c", input[(x)*(width+1)+(y)]);
|
||||
//}
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
//print_field(surrounds);
|
||||
|
||||
uint64_t count = 0;
|
||||
uint64_t count_2 = 0;
|
||||
|
|
@ -99,28 +92,14 @@ int main(int argc, char *argv[]){
|
|||
removes[count_2*2] = x;
|
||||
removes[count_2*2+1] = y;
|
||||
count_2++;
|
||||
//printf("removing %d, %d\n", x, y);
|
||||
//input[(x)*(width+1)+(y)] = 'x';
|
||||
//printf("%d", surrounds[(x)*width+(y)]);
|
||||
}//if((surrounds[(x)*(width+2)+(y)]&0x7f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
//cont = false;
|
||||
//}
|
||||
surrounds[(x)*(width+2)+(y)] -= 0x80;
|
||||
}
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
//print_field(surrounds);
|
||||
count += count_2;
|
||||
|
||||
//printf("count = %lu\n========\n", count);
|
||||
if(count_2 == 0){
|
||||
cont = false;
|
||||
}
|
||||
//printf("cont: %s\n", cont ? "true" : "false");
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
//printf("count = %lu\n", count);
|
||||
|
||||
while (cont){
|
||||
while (count_2 != 0){
|
||||
for(int i = 0; i < count_2; i++){
|
||||
int x = removes[i*2];
|
||||
int y = removes[i*2+1];
|
||||
|
|
@ -128,17 +107,11 @@ int main(int argc, char *argv[]){
|
|||
surrounds[(x-1)*(width+2)+(y)] -= 1;
|
||||
surrounds[(x-1)*(width+2)+(y+1)] -= 1;
|
||||
surrounds[(x)*(width+2)+(y-1)] -= 1;
|
||||
surrounds[(x)*(width+2)+(y)] -= 0x80;
|
||||
surrounds[(x)*(width+2)+(y+1)] -= 1;
|
||||
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);
|
||||
}
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
|
||||
new_count_2 = 0;
|
||||
for(int i = 0; i < count_2; i++){
|
||||
|
|
@ -146,49 +119,25 @@ 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)]&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)){
|
||||
|
||||
new_removes[new_count_2*2] = x+xd;
|
||||
new_removes[new_count_2*2+1] = y+yd;
|
||||
if((surrounds[(x+xd)*(width+2)+(y+yd)]) < 132 && (surrounds[(x+xd)*(width+2)+(y+yd)]) >= 128){
|
||||
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++;
|
||||
surrounds[(x+xd)*(width+2)+(y+yd)] -= 0x80;
|
||||
new_count_2++;
|
||||
//}
|
||||
}//if((surrounds[(x)*(width+2)+(y)]&0x4f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
//cont = false;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//for(int i = 0; i < new_count_2; i++){
|
||||
// printf("removed %d, %d\n", new_removes[i*2], new_removes[i*2+1]);
|
||||
//}
|
||||
|
||||
memcpy(removes, new_removes, new_count_2*2*sizeof(int));
|
||||
count_2 = new_count_2;
|
||||
//print_field(surrounds);
|
||||
count += count_2;
|
||||
|
||||
//printf("count_2 = %lu\n========\n", count_2);
|
||||
if(count_2 == 0){
|
||||
cont = false;
|
||||
}
|
||||
//printf("cont: %s\n", cont ? "true" : "false");
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
//printf("count = %lu\n", count);
|
||||
|
||||
|
||||
//print_field(surrounds);
|
||||
//sleep(1);
|
||||
}
|
||||
|
||||
//free(removes);
|
||||
//free(surrounds-width-1);
|
||||
free(removes);
|
||||
free(surrounds-width-1);
|
||||
|
||||
end = clock();
|
||||
printf("count: %lu\n", count);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue