Add error checking and better reporting
This commit is contained in:
37
puzz.c
37
puzz.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user