Add error checking and better reporting

This commit is contained in:
2025-03-22 13:33:38 +00:00
parent ac48d84a81
commit 3d4cfc7a0c
3 changed files with 75 additions and 17 deletions

37
puzz.c
View File

@@ -38,17 +38,35 @@ void gen(void)
}
}
void print(void)
void print(puzz_t puzz)
{
puts("Solution:");
for (int y = 0; y < HEIGHT; ++y) {
for (int x = 0; x < WIDTH; ++x)
putchar(soln[x][y] == MINE ? 'x' : '0' + soln[x][y]);
for (int x = 0; x < WIDTH; ++x) {
char c;
switch (puzz[x][y]) {
case MINE:
c = 'x';
break;
case UNKNOWN:
c = '.';
break;
default:
c = '0' + puzz[x][y];
break;
}
putchar(c);
}
putchar('\n');
}
putchar('\n');
}
void printsoln(void)
{
puts("Solution:");
print(soln);
}
static void scan_copy(int x, int y, puzz_t out)
{
assert(x >= 0 && x < WIDTH);
@@ -84,6 +102,17 @@ status_t probe(int x, int y, puzz_t out)
return OK;
}
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])
return INCORRECT;
}
}
return OK;
}
int countadj(puzz_t field, int x, int y, uint8_t val)
{
int n = 0;