Add SAFE state to indicate un-probed safe tile

This commit is contained in:
Camden Dixie O'Brien 2025-03-22 13:33:38 +00:00
parent 3d4cfc7a0c
commit 49417b4840
3 changed files with 15 additions and 4 deletions

3
main.c
View File

@ -68,7 +68,8 @@ static update_res_t update(state_t *state, int *x_out, int *y_out)
for (int y = 0; y < HEIGHT; ++y) {
for (int x = 0; x < WIDTH; ++x) {
if (state->field[x][y] == UNKNOWN || state->field[x][y] == MINE)
if (state->field[x][y] == UNKNOWN || state->field[x][y] == MINE
|| state->field[x][y] == SAFE)
continue;
const int mines = countadj(state->field, x, y, MINE);

12
puzz.c
View File

@ -106,8 +106,18 @@ status_t check(puzz_t puzz)
{
for (int y = 0; y < HEIGHT; ++y) {
for (int x = 0; x < WIDTH; ++x) {
if (puzz[x][y] != UNKNOWN && puzz[x][y] != soln[x][y])
switch (puzz[x][y]) {
case UNKNOWN:
continue;
case SAFE:
if (soln[x][y] == MINE)
return INCORRECT;
break;
default:
if (puzz[x][y] != soln[x][y])
return INCORRECT;
break;
}
}
}
return OK;

2
puzz.h
View File

@ -12,7 +12,7 @@
#include <stdint.h>
enum { MINE = 0xff, UNKNOWN = 0xfe };
enum { MINE = 0xff, UNKNOWN = 0xfe, SAFE = 0xfd };
typedef uint8_t puzz_t[WIDTH][HEIGHT];
typedef enum { DEAD, OK, INCORRECT } status_t;