From 5c5462085cd151a0c78c8dc9c35d98da77765075 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 6 Jan 2026 23:43:18 +0100 Subject: [PATCH] Gather data --- src/main/java/puzzle/SwedishGenerator.java | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/puzzle/SwedishGenerator.java b/src/main/java/puzzle/SwedishGenerator.java index 7619c1e..898bc4a 100644 --- a/src/main/java/puzzle/SwedishGenerator.java +++ b/src/main/java/puzzle/SwedishGenerator.java @@ -111,6 +111,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) int digitAt(int r, int c) { return g[offset(r, c)] - 48; } byte byteAt(int r, int c) { return g[offset(r, c)]; } void setCharAt(int r, int c, char ch) { g[offset(r, c)] = (byte) ch; } + void setCharAt(UndoPlace pl) { g[offset(pl.ur, pl.uc)] = (byte) pl.up; } boolean isLetterAt(int r, int c) { return ((g[offset(r, c)] & 64) != 0); } boolean isDigitAt(int r, int c) { return (g[offset(r, c)] & 48) == 48; } } @@ -246,7 +247,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) return new Dict(map.values().toArray(Lemma[]::new)); } - int[] intersectSorted(int[] a, int aLen, int[] b, int bLen) { + private static int[] intersectSorted(int[] buff, int[] a, int aLen, int[] b, int bLen) { //var out = new int[Math.min(aLen, bLen)]; int i = 0, j = 0, k = 0, x = 0, y = 0; while (i < aLen && j < bLen) { @@ -262,7 +263,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) return Arrays.copyOf(buff, k); } - CandidateInfo candidateInfoForPattern(DictEntry entry, char[] pattern ) { + CandidateInfo candidateInfoForPattern(DictEntry entry, char[] pattern) { var lists = new ArrayList(); for (var i = 0; i < pattern.length; i++) { var ch = pattern[i]; @@ -283,7 +284,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) var nxt = lists.get(k); var nextArr = nxt.data(); var nextLen = nxt.size(); - cur = intersectSorted(cur, curLen, nextArr, nextLen); + cur = intersectSorted(buff, cur, curLen, nextArr, nextLen); curLen = cur.length; if (curLen == 0) break; } @@ -572,9 +573,10 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) pop.sort(Comparator.comparingLong(g -> maskFitness(g, lenCounts))); return pop.get(0); } + record UndoPlace(int ur, int uc, char up) { } // ---------------- Fill (CSP) ---------------- - record Undo(int[] rs, int[] cs, char[] prev, int n) { } + record Undo(UndoPlace[] ur, int n) { } public static final class FillStats { @@ -620,34 +622,36 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) } static Undo placeWord(Grid grid, Slot s, Lemma w) { - var urs = new int[s.len]; + var ur = new UndoPlace[s.len]; + /* var urs = new int[s.len]; var ucs = new int[s.len]; - var up = new char[s.len]; - var n = 0; + var up = new char[s.len];*/ + var n = 0; for (var i = 0; i < s.len; i++) { int r = s.rs[i], c = s.cs[i]; char cur = grid.getCharAt(r, c); var ch = w.charAt(i); if (cur == C_DASH) { - urs[n] = r; + ur[n] = new UndoPlace(r, c, C_DASH); + /*urs[n] = r; ucs[n] = c; - up[n] = C_DASH; + up[n] = C_DASH;*/ n++; grid.setCharAt(r, c, ch); } else { if (cur != ch) { // rollback immediate changes - for (var j = 0; j < n; j++) grid.setCharAt(urs[j], ucs[j], up[j]); + for (var j = 0; j < n; j++) grid.setCharAt(ur[j]); return null; } } } - return new Undo(urs, ucs, up, n); + return new Undo(ur, n); } static void undoPlace(Grid grid, Undo u) { - for (var i = 0; i < u.n; i++) grid.setCharAt(u.rs[i], u.cs[i], u.prev[i]); + for (var i = 0; i < u.n; i++) grid.setCharAt(u.ur[i]); } public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex, @@ -760,6 +764,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff) if (used.get(w.index())) return false; for (var i = 0; i < pat.length; i++) { + // if ((pat[i] != w.charAt(i)) != (pat[i] != C_DASH)) throw new RuntimeException("word does not match pattern"); if (pat[i] != C_DASH && pat[i] != w.charAt(i)) return false; }