Gather data

This commit is contained in:
mike
2026-01-09 00:39:43 +01:00
parent fb99a7aab4
commit a269584ad6
3 changed files with 93 additions and 29 deletions

View File

@@ -125,9 +125,13 @@ 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]); }
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(int idx, char ch) { g[idx] = (byte) ch; }
void clear(int r, int c) { g[offset(r, c)] = 0; }
void clear(int idx) { g[idx] = 0; }
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; }
boolean isDigitAt(int index) { return (g[index] & 48) == 48; }
@@ -339,6 +343,7 @@ public record SwedishGenerator(int[] buff) {
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 pos(int i) { return 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); }
@@ -346,7 +351,7 @@ public record SwedishGenerator(int[] buff) {
static void undoPlace(Grid grid, long[] undoBuffer, int offset, int n) {
for (var i = 0; i < n; i++) {
long v = undoBuffer[offset + i];
grid.setCharAt((int) (v >> 16) & 0xFF, (int) (v >> 8) & 0xFF, (char) (v & 0xFF));
grid.clear((int)v);
}
}
@FunctionalInterface
@@ -724,32 +729,53 @@ public record SwedishGenerator(int[] buff) {
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));
var ch = grid.getCharAt(s.pos(i));
pat[i] = isLetter(ch) ? ch : C_DASH;
}
}
static int slotScore(int[] cellCount, Slot s, Grid grid) {
var cross = 0;
for (var i = 0; i < s.len(); i++) cross += (cellCount[Grid.offset(s.r(i), s.c(i))] - 1);
for (var i = 0; i < s.len(); i++) cross += (cellCount[s.pos(i)] - 1);
return cross * 10 + s.len();
}
static int placeWord(Grid grid, Slot s, Lemma w, long[] undoBuffer, int offset) {
static int placeWord1(Grid grid, Slot s, Lemma w, long[] undoBuffer, int offset) {
int n = 0;
for (var i = 0; i < s.len(); i++) {
int r = s.r(i), c = s.c(i);
char cur = grid.getCharAt(r, c);
var ch = w.charAt(i);
if (cur == C_DASH) {
undoBuffer[offset + n] = ((long) r << 16) | ((long) c << 8) | (long) C_DASH;
undoBuffer[offset + n] = ((long) r << 16) | ((long) c << 8);
n++;
grid.setCharAt(r, c, ch);
} else {
if (cur != ch) {
for (var j = 0; j < n; j++) {
long v = undoBuffer[offset + j];
grid.setCharAt((int) (v >> 16) & 0xFF, (int) (v >> 8) & 0xFF, (char) (v & 0xFF));
grid.clear((int) (v >> 16) & 0xFF, (int) (v >> 8) & 0xFF);
}
return -1;
}
}
}
return n;
}
static int placeWord(Grid grid, Slot s, Lemma w, long[] undoBuffer, int offset) {
int n = 0;
for (var i = 0; i < s.len(); i++) {
int idx = s.pos(i);
char cur = grid.getCharAt(idx);
var ch = w.charAt(i);
if (cur == C_DASH) {
undoBuffer[offset + n] = idx;
n++;
grid.setCharAt(idx, ch);
} else {
if (cur != ch) {
for (var j = 0; j < n; j++) {
long v = undoBuffer[offset + j];
grid.clear((int) v);
}
return -1;
}
@@ -770,7 +796,7 @@ public record SwedishGenerator(int[] buff) {
var ctx = CTX.get();
var cellCount = ctx.cellCount;
Arrays.fill(cellCount, 0, SIZE, 0);
for (var s : slots) for (var i = 0; i < s.len(); i++) cellCount[Grid.offset(s.r(i), s.c(i))]++;
for (var s : slots) for (var i = 0; i < s.len(); i++) cellCount[s.pos(i)]++;
var t0 = System.currentTimeMillis();
final var lastLog = new AtomicLong(t0);