feat: allow flexible clue placement in all four directions for puzzles

Co-authored-by: aider (gpt-4o) <aider@aider.chat>
This commit is contained in:
mike
2025-12-26 19:54:24 +01:00
parent 541e101ae0
commit dd8a6bffa3

View File

@@ -326,29 +326,31 @@ public class SwedishGenerator {
var d = grid[r][c]; var d = grid[r][c];
if (!isDigit(d)) continue; if (!isDigit(d)) continue;
var di = d - '0'; // Check all four possible directions for clue placement
int dr = DIRS[di][0], dc = DIRS[di][1]; for (int dir = 1; dir <= 4; dir++) {
int dr = DIRS[dir][0], dc = DIRS[dir][1];
int rr = r + dr, cc = c + dc; int rr = r + dr, cc = c + dc;
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue; if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
if (!isLetterCell(grid[rr][cc])) continue; if (!isLetterCell(grid[rr][cc])) continue;
var rs = new int[MAX_LEN + 1]; // allow MAX_LEN+1 like JS loop var rs = new int[MAX_LEN + 1]; // allow MAX_LEN+1 like JS loop
var cs = new int[MAX_LEN + 1]; var cs = new int[MAX_LEN + 1];
var n = 0; var n = 0;
while (rr >= 0 && rr < H && cc >= 0 && cc < W) { while (rr >= 0 && rr < H && cc >= 0 && cc < W) {
var ch = grid[rr][cc]; var ch = grid[rr][cc];
if (!isLetterCell(ch)) break; if (!isLetterCell(ch)) break;
rs[n] = rr; rs[n] = rr;
cs[n] = cc; cs[n] = cc;
n++; n++;
rr += dr; rr += dr;
cc += dc; cc += dc;
if (n > MAX_LEN) break; // allow n==MAX_LEN+1 if (n > MAX_LEN) break; // allow n==MAX_LEN+1
}
slots.add(new Slot(r, c, (char) ('0' + dir), Arrays.copyOf(rs, n), Arrays.copyOf(cs, n)));
} }
slots.add(new Slot(r, c, d, Arrays.copyOf(rs, n), Arrays.copyOf(cs, n)));
} }
} }
return slots; return slots;