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:
@@ -325,30 +325,32 @@ public class SwedishGenerator {
|
||||
for (var c = 0; c < W; c++) {
|
||||
var d = grid[r][c];
|
||||
if (!isDigit(d)) continue;
|
||||
|
||||
var di = d - '0';
|
||||
int dr = DIRS[di][0], dc = DIRS[di][1];
|
||||
|
||||
int rr = r + dr, cc = c + dc;
|
||||
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
|
||||
if (!isLetterCell(grid[rr][cc])) continue;
|
||||
|
||||
var rs = new int[MAX_LEN + 1]; // allow MAX_LEN+1 like JS loop
|
||||
var cs = new int[MAX_LEN + 1];
|
||||
var n = 0;
|
||||
|
||||
while (rr >= 0 && rr < H && cc >= 0 && cc < W) {
|
||||
var ch = grid[rr][cc];
|
||||
if (!isLetterCell(ch)) break;
|
||||
rs[n] = rr;
|
||||
cs[n] = cc;
|
||||
n++;
|
||||
rr += dr;
|
||||
cc += dc;
|
||||
if (n > MAX_LEN) break; // allow n==MAX_LEN+1
|
||||
|
||||
// Check all four possible directions for clue placement
|
||||
for (int dir = 1; dir <= 4; dir++) {
|
||||
int dr = DIRS[dir][0], dc = DIRS[dir][1];
|
||||
|
||||
int rr = r + dr, cc = c + dc;
|
||||
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
|
||||
if (!isLetterCell(grid[rr][cc])) continue;
|
||||
|
||||
var rs = new int[MAX_LEN + 1]; // allow MAX_LEN+1 like JS loop
|
||||
var cs = new int[MAX_LEN + 1];
|
||||
var n = 0;
|
||||
|
||||
while (rr >= 0 && rr < H && cc >= 0 && cc < W) {
|
||||
var ch = grid[rr][cc];
|
||||
if (!isLetterCell(ch)) break;
|
||||
rs[n] = rr;
|
||||
cs[n] = cc;
|
||||
n++;
|
||||
rr += dr;
|
||||
cc += dc;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user