Gather data

This commit is contained in:
mike
2026-01-08 23:30:59 +01:00
parent 70f3878b32
commit fb99a7aab4
4 changed files with 98 additions and 69 deletions

View File

@@ -51,10 +51,10 @@ public record ExportFormat() {
var g = puz.filled().grid();
var placed = new ArrayList<Placed>();
var clueMap = puz.filled().clueMap();
puz.swe().forEachSlot(g, (int key, long rs, long cs, int len) -> {
puz.swe().forEachSlot(g, (int key, long packedPos, int len) -> {
var word = clueMap.get(key);
if (word != null) {
var p = extractPlacedFromSlot(Slot.from(key, rs, cs, len), word);
var p = extractPlacedFromSlot(Slot.from(key, packedPos, len), word);
if (p != null) placed.add(p);
}
});

View File

@@ -327,25 +327,21 @@ public record SwedishGenerator(int[] buff) {
return new CandidateInfo(cur, curLen);
}
static record Slot(int key, long rs, long cs, int len) {
//perhaps just put len into key and use hash-code and derrive index from key. or just put both ints into tail of the two longs.
static Slot from(int key, long rs, long cs, int len) {
/* if ((Long.highestOneBit(rs | cs) >> 2) != (len - 1)) throw new RuntimeException();
if ((Long.highestOneBit(cs) >> 2) != (len - 1)) throw new RuntimeException();
if ((Long.highestOneBit(rs) >> 2) != (len - 1)) throw new RuntimeException();*/
return new Slot(key, rs, cs, len);
static record Slot(int key, long packedPos) {
static Slot from(int key, long packedPos, int len) {
return new Slot(key, packedPos | ((long) len << 56));
}
//public int len() { return (int) (Long.highestOneBit(rs | cs) >> 2); }
public int clueR() { return (key >> 8) & 15; }
public int clueC() { return (key >> 4) & 15; }
public int dir() { return key & 15; }
public boolean horiz() { return horiz(key); }
public int r(int i) { return r(rs, i); }
public int c(int i) { return c(cs, i); }
public static boolean horiz(int key) { return ((key & 15) & 1) == 0; }
public static int r(long rs, int i) { return (int) ((rs >> (i << 2)) & 15); }
public static int c(long cs, int i) { return (int) ((cs >> (i << 2)) & 15); }
public int len() { return (int) (packedPos >>> 56); }
public int clueR() { return (key >> 8) & 15; }
public int clueC() { return (key >> 4) & 15; }
public int dir() { return key & 15; }
public boolean horiz() { return horiz(key); }
public int r(int i) { return Grid.r(offset(packedPos, i)); }
public int c(int i) { return Grid.c(offset(packedPos, i)); }
public static boolean horiz(int key) { return ((key & 15) & 1) == 0; }
public static int offset(long packedPos, int i) { return (int) ((packedPos >> (i * 7)) & 127); }
}
static void undoPlace(Grid grid, long[] undoBuffer, int offset, int n) {
for (var i = 0; i < n; i++) {
@@ -356,7 +352,7 @@ public record SwedishGenerator(int[] buff) {
@FunctionalInterface
interface SlotVisitor {
void visit(int key, long rs, long cs, int len);
void visit(int key, long packedPos, int len);
}
void forEachSlot(Grid grid, SlotVisitor visitor) {
@@ -368,19 +364,17 @@ public record SwedishGenerator(int[] buff) {
int rr = r + nbrs16.r, cc = c + nbrs16.c;
if (rr < 0 || rr >= R || cc < 0 || cc >= C || grid.isDigitAt(rr, cc)) continue;
long packedRs = 0;
long packedCs = 0;
var n = 0;
long packedPos = 0;
var n = 0;
while (rr >= 0 && rr < R && cc >= 0 && cc < C && grid.isLettercell(rr, cc) && n < MAX_WORD_LENGTH) {
packedRs |= (long) rr << (n << 2);
packedCs |= (long) cc << (n << 2);
packedPos |= (long) Grid.offset(rr, cc) << (n * 7);
n++;
rr += nbrs16.dr;
cc += nbrs16.dc;
}
if (n > 0) {
visitor.visit((r << 8) | (c << 4) | d, packedRs, packedCs, n);
visitor.visit((r << 8) | (c << 4) | d, packedPos, n);
}
}
}
@@ -388,7 +382,7 @@ public record SwedishGenerator(int[] buff) {
ArrayList<Slot> extractSlots(Grid grid) {
var slots = new ArrayList<Slot>(64);
forEachSlot(grid, (key, rs, cs, len) -> slots.add(Slot.from(key, rs, cs, len)));
forEachSlot(grid, (key, packedPos, len) -> slots.add(Slot.from(key, packedPos, len)));
return slots;
}
@@ -428,14 +422,12 @@ public record SwedishGenerator(int[] buff) {
int rr = r + nbrs16.r, cc = c + nbrs16.c;
if (rr < 0 || rr >= R || cc < 0 || cc >= C || grid.isDigitAt(rr, cc)) continue;
long packedRs = 0;
long packedCs = 0;
var n = 0;
long packedPos = 0;
var n = 0;
while (rr >= 0 && rr < R && cc >= 0 && cc < C && n < MAX_WORD_LENGTH) {
if (grid.isDigitAt(rr, cc)) break;
packedRs |= (long) rr << (n << 2);
packedCs |= (long) cc << (n << 2);
packedPos |= (long) Grid.offset(rr, cc) << (n * 7);
n++;
rr += nbrs16.dr;
cc += nbrs16.dc;
@@ -450,7 +442,7 @@ public record SwedishGenerator(int[] buff) {
}
var horiz = Slot.horiz(d) ? covH : covV;
for (var i = 0; i < n; i++) horiz[Grid.offset(Slot.r(packedRs, i), Slot.c(packedCs, i))] += 1;
for (var i = 0; i < n; i++) horiz[Slot.offset(packedPos, i)] += 1;
}
}
@@ -730,12 +722,11 @@ public record SwedishGenerator(int[] buff) {
}
}
static int patternForSlot(Grid grid, Slot s, char[] pat) {
static void patternForSlot(Grid grid, Slot s, char[] pat) {
for (var i = 0; i < s.len(); i++) {
var ch = grid.getCharAt(s.r(i), s.c(i));
pat[i] = isLetter(ch) ? ch : C_DASH;
}
return s.len();
}
static int slotScore(int[] cellCount, Slot s, Grid grid) {
@@ -821,9 +812,9 @@ public record SwedishGenerator(int[] buff) {
if (entry == null) {
return new Pick(null, null, false);
}
var patLen = patternForSlot(grid, s, ctx.pattern);
var info = candidateInfoForPattern(ctx, entry, patLen);
var patLen = s.len();
patternForSlot(grid, s, ctx.pattern);
var info = candidateInfoForPattern(ctx, entry, patLen);
if (info.count == 0) {
return new Pick(null, null, false);
@@ -863,11 +854,12 @@ public record SwedishGenerator(int[] buff) {
stats.lastMRV = pick.info.count;
renderProgress.run();
var s = pick.slot;
var k = s.key();
var entry = dictIndex[s.len()];
var pat = new char[s.len()];
int patLen = patternForSlot(grid, s, pat);
var s = pick.slot;
var k = s.key();
int patLen = s.len();
var entry = dictIndex[patLen];
var pat = new char[patLen];
patternForSlot(grid, s, pat);
int undoOffset = depth * SIZE;
if (pick.info.indices != null && pick.info.indices.length > 0) {
var idxs = pick.info.indices;