Gather data

This commit is contained in:
mike
2026-01-07 01:31:42 +01:00
parent bc24f0ba1a
commit 5561cfe62b
2 changed files with 44 additions and 22 deletions

View File

@@ -291,18 +291,26 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
return new CandidateInfo(cur, curLen);
}
static record Slot(String key, int clueR, int clueC, int dir, long rs, long cs, int len, boolean horiz) {
static record Slot(int key, long rs, long cs, int len) {
public Slot(int clueR, int clueC, int d, long rs, long cs, int len) {
this(clueR + "," + clueC + ":" + d, clueR, clueC, d, rs, cs, len, d == 2 || d == 4);
this((clueR << 8) | (clueC << 4) | d, rs, cs, len);
}
public int clueR() { return (key >> 8) & 15; }
public int clueC() { return (key >> 4) & 15; }
public int dir() { return key & 15; }
public boolean horiz() {
return (dir() & 1) == 0;
/* var d = dir();
return d == 2 || d == 4;*/
}
public int r(int i) { return (int) ((rs >> (i << 2)) & 15); }
public int c(int i) { return (int) ((cs >> (i << 2)) & 15); }
}
ArrayList<Slot> extractSlots(Grid grid) {
var slots = new ArrayList<Slot>();
var slots = new ArrayList<Slot>(64);
for (var r = 0; r < H; r++) {
for (var c = 0; c < W; c++) {
if (!grid.isDigitAt(r, c)) continue;
@@ -364,16 +372,20 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
var covV = new int[H][W];
for (var s : slots) {
if (s.len < MIN_LEN) penalty += 8000;
if (s.len > MAX_LEN) penalty += 8000 + (long) (s.len - MAX_LEN) * 500L;
if (s.len >= MIN_LEN && s.len <= MAX_LEN) {
if (s.len < MIN_LEN) {
penalty += 8000;
}
/* else if (s.len > MAX_LEN) {
penalty += 8000 + (long) (s.len - MAX_LEN) * 500L;
throw new RuntimeException();
}*/
else {
if (lenCounts[s.len] <= 0) penalty += 12000;
}
for (var i = 0; i < s.len; i++) {
int r = s.r(i), c = s.c(i);
if (s.horiz) covH[r][c] += 1;
if (s.horiz()) covH[r][c] += 1;
else covV[r][c] += 1;
}
}
@@ -597,11 +609,11 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
public static final record FillResult(boolean ok,
Grid grid,
HashMap<String, Lemma> clueMap,
HashMap<Integer, Lemma> clueMap,
FillStats stats,
double simplicity) {
public FillResult(boolean ok, Grid grid, HashMap<String, Lemma> assigned, FillStats stats) {
public FillResult(boolean ok, Grid grid, HashMap<Integer, Lemma> assigned, FillStats stats) {
double totalSimplicity = 0;
if (ok) {
for (var w : assigned.values()) totalSimplicity += w.simpel;
@@ -628,10 +640,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
static Undo placeWord(Grid grid, Slot s, Lemma w) {
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 n = 0;
for (var i = 0; i < s.len; i++) {
int r = s.r(i), c = s.c(i);
@@ -639,9 +648,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
var ch = w.charAt(i);
if (cur == C_DASH) {
ur[n] = new UndoPlace(r, c, C_DASH);
/*urs[n] = r;
ucs[n] = c;
up[n] = C_DASH;*/
n++;
grid.setCharAt(r, c, ch);
} else {
@@ -662,13 +668,11 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
int logEveryMs, int timeLimitMs, boolean verbose) {
var grid = mask.deepCopyGrid();
var allSlots = extractSlots(grid);
var slots = new ArrayList<Slot>();
for (var s : allSlots) if (s.len >= MIN_LEN && s.len <= MAX_LEN) slots.add(s);
var grid = mask.deepCopyGrid();
var slots = extractSlots(grid);
var used = new BitSet();
var assigned = new HashMap<String, Lemma>();
var assigned = new HashMap<Integer, Lemma>();
var cellCount = new int[H][W];
for (var s : slots) for (var i = 0; i < s.len; i++) cellCount[s.r(i)][s.c(i)]++;

View File

@@ -0,0 +1,18 @@
package puzzle;
import org.junit.jupiter.api.Test;
import puzzle.SwedishGenerator.Slot;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SlotTest {
@Test
public void testHoriz() {
assertTrue(new Slot(0, 0, 2, 0L, 0L, 5).horiz());
assertTrue(new Slot(0, 0, 4, 0L, 0L, 5).horiz());
assertFalse(new Slot(0, 0, 1, 0L, 3L, 5).horiz());
assertFalse(new Slot(0, 0, 3, 0L, 3L, 5).horiz());
assertFalse(new Slot(0, 0, 5, 0L, 3L, 5).horiz());
}
}