Gather data

This commit is contained in:
mike
2026-01-09 03:11:49 +01:00
parent 5ae1e7f6a1
commit 5bfea6f116
3 changed files with 21 additions and 42 deletions

View File

@@ -66,7 +66,7 @@ public record ExportFormat() {
for (var r = 0; r < R; r++) {
var sb = new StringBuilder(C);
for (var c = 0; c < C; c++) {
sb.append(g.isLetterAt(r, c) ? g.getCharAt(r, c) : '#');
sb.append(g.isLetterAt(r, c) ? (char) g.byteAt(r, c) : '#');
}
gridv2.add(sb.toString());
}
@@ -97,7 +97,7 @@ public record ExportFormat() {
for (var c : p.cells) {
int rr = Grid.r(c), cc = Grid.c(c);
if (inBounds(rr, cc) && g.isLetterAt(rr, cc)) {
letterAt.put(pack(rr, cc), g.getCharAt(rr, cc));
letterAt.put(pack(rr, cc), (char) g.byteAt(rr, cc));
}
}
}

View File

@@ -1,5 +1,4 @@
package puzzle;
import lombok.Data;
import lombok.Getter;
import puzzle.ExportFormat.Bit;
@@ -138,7 +137,6 @@ public record SwedishGenerator(int[] buff) {
static int offset(int r, int c) { return r | (c << 3); }
Grid deepCopyGrid() { return new Grid(g.clone()); }
char getCharAt(int r, int c) { return (char) (g[offset(r, c)]); }
char getCharAt(int pos) { return (char) (g[pos]); }
byte byteAt(int r, int c) { return g[offset(r, c)]; }
byte byteAt(int pos) { return g[pos]; }
byte byteAtStatic(int r, int c) { return g[offset(r, c)]; }
@@ -167,7 +165,7 @@ public record SwedishGenerator(int[] buff) {
var sb = new StringBuilder();
for (var r = 0; r < R; r++) {
if (r > 0) sb.append('\n');
for (var c = 0; c < C; c++) sb.append(g.getCharAt(r, c));
for (var c = 0; c < C; c++) sb.append((char) g.byteAt(r, c));
}
return sb.toString();
}
@@ -177,7 +175,7 @@ public record SwedishGenerator(int[] buff) {
for (var r = 0; r < R; r++) {
if (r > 0) sb.append('\n');
for (var c = 0; c < C; c++) {
sb.append(g.isDigitAt(r, c) ? ' ' : g.getCharAt(r, c));
sb.append(g.isDigitAt(r, c) ? ' ' : (char) g.byteAt(r, c));
}
}
return sb.toString();
@@ -417,18 +415,6 @@ public record SwedishGenerator(int[] buff) {
}
return false;
}
boolean hasRoomForClue(Grid grid, int r, int c, char d) {
var nbrs16 = OFFSETS[d - '0'];
int rr = r + nbrs16.r, cc = c + nbrs16.c;
var run = 0;
while (rr >= 0 && rr < R && cc >= 0 && cc < C && (grid.isLettercell(rr, cc)) && run < MAX_WORD_LENGTH) {
run++;
rr += nbrs16.dr;
cc += nbrs16.dc;
if (run >= MIN_LEN) return true;
}
return false;
}
long maskFitness(Grid grid, int[] lenCounts) {
long penalty = 0;
@@ -479,16 +465,14 @@ public record SwedishGenerator(int[] buff) {
if (!hasSlots) return 1_000_000_000L;
int idx, h, v;
for (var r = 0; r < R; r++)
for (var c = 0; c < C; c++) {
idx = Grid.offset(r, c);
if (grid.isDigitAt(idx)) continue;
h = covH[idx];
v = covV[idx];
if (h == 0 && v == 0) penalty += 1500;
else if (h > 0 && v > 0) { /* ok */ } else if (h + v == 1) penalty += 200;
else penalty += 600;
}
for (idx = 0; idx < SIZE; idx++) {
if (grid.isDigitAt(idx)) continue;
h = covH[idx];
v = covV[idx];
if (h == 0 && v == 0) penalty += 1500;
else if (h > 0 && v > 0) { /* ok */ } else if (h + v == 1) penalty += 200;
else penalty += 600;
}
// clue clustering (8-connected)
var seen = ctx.seen;
@@ -540,9 +524,9 @@ public record SwedishGenerator(int[] buff) {
return penalty;
}
Grid randomMask(Rng rng) {
var g = makeEmptyGrid();
int placed = 0, guard = 0;
SwedishGenerator.Grid randomMask(SwedishGenerator.Rng rng) {
var g = makeEmptyGrid();
int placed = 0, guard = 0;
while (placed < TARGET_CLUES && guard++ < 4000) {
var idx = Grid.offset(rng.randint(0, R - 1),
@@ -592,7 +576,7 @@ public record SwedishGenerator(int[] buff) {
for (var r = 0; r < R; r++)
for (var c = 0; c < C; c++) {
if (out.isDigitAt(r, c) && !hasRoomForClue(out, r, c, out.getCharAt(r, c))) out.clear(r, c);
if (out.isDigitAt(r, c) && !hasRoomForClue(out, Grid.offset(r, c), OFFSETS[out.digitAt(r, c)])) out.clear(r, c);
}
return out;
}
@@ -730,11 +714,11 @@ public record SwedishGenerator(int[] buff) {
public int lastMRV;
}
record Pick(Slot slot, CandidateInfo info, boolean done) { }
record Pick(SwedishGenerator.Slot slot, SwedishGenerator.CandidateInfo info, boolean done) { }
public static record FillResult(boolean ok,
Grid grid,
HashMap<Integer, Lemma> clueMap,
HashMap<Integer, SwedishGenerator.Lemma> clueMap,
FillStats stats,
double simplicity) {
@@ -766,7 +750,7 @@ public record SwedishGenerator(int[] buff) {
int idx = s.pos(i);
var cur = grid.byteAt(idx);
var ch = w.byteAt(i);
if (cur == C_DASH) {
if (cur == DASH) {
mask |= (1 << i);
grid.setByteAt(idx, ch);
} else if (cur != ch) {
@@ -782,7 +766,7 @@ public record SwedishGenerator(int[] buff) {
return 1;
}
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
public FillResult fillMask(Rng rng, Grid mask, SwedishGenerator.DictEntry[] dictIndex,
int logEveryMs, int timeLimitMs, boolean verbose) {
boolean multiThreaded = Thread.currentThread().getName().contains("pool");
var grid = mask.deepCopyGrid();
@@ -938,7 +922,7 @@ public record SwedishGenerator(int[] buff) {
boolean match = true;
for (var i = 0; i < patLen; i++) {
if (pat[i] != C_DASH && pat[i] != w.byteAt(i)) {
if (pat[i] != DASH && pat[i] != w.byteAt(i)) {
match = false;
break;
}

View File

@@ -1,19 +1,14 @@
package puzzle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import puzzle.Main.PuzzleResult;
import puzzle.SwedishGenerator.Dict;
import puzzle.SwedishGenerator.Lemma;
import puzzle.SwedishGenerator.Rng;
import puzzle.SwedishGenerator.Slot;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static puzzle.Main.indentLines;
import static puzzle.SwedishGenerator.C_DASH;
import static puzzle.SwedishGenerator.DASH;
public class MainTest {