Keep track of total mines and total unknowns
This commit is contained in:
parent
127b7a17ea
commit
4ffed4e4ce
19
main.c
19
main.c
@ -59,7 +59,7 @@ int main(void)
|
||||
puzz_t field;
|
||||
memset(field, UNKNOWN, sizeof(field));
|
||||
|
||||
bool solved = false;
|
||||
int total_mines = 0, total_unknowns = WIDTH * HEIGHT;
|
||||
do {
|
||||
int x = rand() % WIDTH;
|
||||
int y = rand() % HEIGHT;
|
||||
@ -71,6 +71,13 @@ int main(void)
|
||||
}
|
||||
|
||||
update:
|
||||
total_mines = total_unknowns = 0;
|
||||
for (y = 0; y < HEIGHT; ++y) {
|
||||
for (x = 0; x < WIDTH; ++x) {
|
||||
total_mines += field[x][y] == MINE ? 1 : 0;
|
||||
total_unknowns += field[x][y] == UNKNOWN ? 1 : 0;
|
||||
}
|
||||
}
|
||||
for (y = 0; y < HEIGHT; ++y) {
|
||||
for (x = 0; x < WIDTH; ++x) {
|
||||
if (field[x][y] == UNKNOWN || field[x][y] == MINE)
|
||||
@ -92,14 +99,8 @@ int main(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
solved = true;
|
||||
for (y = 0; y < HEIGHT; ++y) {
|
||||
for (x = 0; x < WIDTH; ++x)
|
||||
solved &= field[x][y] != UNKNOWN;
|
||||
}
|
||||
} while (!solved);
|
||||
puts(solved ? "Solved" : "Dead");
|
||||
} while (total_mines < NMINES);
|
||||
puts(total_mines == NMINES ? "Solved" : "Died");
|
||||
|
||||
putchar('\n');
|
||||
for (int y = 0; y < HEIGHT; ++y) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user