Create countadj helper function
This commit is contained in:
parent
01d5376f31
commit
cdf4ccc1a9
22
puzz.c
22
puzz.c
@ -33,13 +33,7 @@ void gen(void)
|
|||||||
for (int x = 0; x < WIDTH; ++x) {
|
for (int x = 0; x < WIDTH; ++x) {
|
||||||
if (soln[x][y] == MINE)
|
if (soln[x][y] == MINE)
|
||||||
continue;
|
continue;
|
||||||
for (int yp = y - 1; yp < y + 2; ++yp) {
|
soln[x][y] = countadj(soln, x, y, MINE);
|
||||||
for (int xp = x - 1; xp < x + 2; ++xp) {
|
|
||||||
if (xp < 0 || xp >= WIDTH || yp < 0 || yp >= HEIGHT)
|
|
||||||
continue;
|
|
||||||
soln[x][y] += soln[xp][yp] == MINE ? 1 : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,3 +85,17 @@ status_t probe(int x, int y, puzz_t out)
|
|||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int countadj(puzz_t field, int x, int y, uint8_t val)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
for (int yp = y - 1; yp < y + 2; ++yp) {
|
||||||
|
for (int xp = x - 1; xp < x + 2; ++xp) {
|
||||||
|
if (xp < 0 || xp >= WIDTH || yp < 0 || yp >= HEIGHT
|
||||||
|
|| (xp == x && yp == y))
|
||||||
|
continue;
|
||||||
|
n += field[xp][yp] == val ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user