Make macro for looping through adjacent tiles

This commit is contained in:
2025-03-22 13:33:38 +00:00
parent 7156efc99c
commit 5b20a3e97b
3 changed files with 22 additions and 34 deletions

22
puzz.c
View File

@@ -78,13 +78,11 @@ static void scan_copy(int x, int y, puzz_t out)
if (soln[x][y] != 0)
return;
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
|| scanned[xp][yp] == YES)
continue;
scan_copy(xp, yp, out);
}
FORADJ(x, y, xi, yi)
{
if (scanned[xi][yi] == YES)
continue;
scan_copy(xi, yi, out);
}
}
@@ -126,13 +124,7 @@ status_t check(puzz_t puzz)
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;
}
}
FORADJ(x, y, xi, yi)
n += field[xi][yi] == val ? 1 : 0;
return n;
}