From dd8a6bffa3febc9f10ad0a8c1cf469d0673a5c56 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 26 Dec 2025 19:54:24 +0100 Subject: [PATCH] feat: allow flexible clue placement in all four directions for puzzles Co-authored-by: aider (gpt-4o) --- src/puzzle/SwedishGenerator.java | 48 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/puzzle/SwedishGenerator.java b/src/puzzle/SwedishGenerator.java index a0b89fe..9854eab 100644 --- a/src/puzzle/SwedishGenerator.java +++ b/src/puzzle/SwedishGenerator.java @@ -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;