Gather data
This commit is contained in:
@@ -85,11 +85,11 @@ public record SwedishGenerator(int[] buff) {
|
||||
Bit seen,
|
||||
char[] pattern,
|
||||
IntList[] intListBuffer,
|
||||
long[] undoBuffer) {
|
||||
int[] undoBuffer) {
|
||||
|
||||
public Context() {
|
||||
this(new int[SIZE], new int[SIZE], new int[SIZE], new int[SIZE], new Bit(), new char[MAX_WORD_LENGTH], new IntList[MAX_WORD_LENGTH],
|
||||
new long[2048]);
|
||||
new int[2048]);
|
||||
}
|
||||
void setPatter(char[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
|
||||
}
|
||||
@@ -342,16 +342,15 @@ public record SwedishGenerator(int[] buff) {
|
||||
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 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); }
|
||||
}
|
||||
static void undoPlace(Grid grid, long[] undoBuffer, int offset, int n) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
long v = undoBuffer[offset + i];
|
||||
grid.clear((int)v);
|
||||
static void undoPlace(Grid grid, Slot s, int mask) {
|
||||
for (var i = 0; i < s.len(); i++) {
|
||||
if ((mask & (1L << i)) != 0) {
|
||||
grid.clear(s.pos(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@FunctionalInterface
|
||||
@@ -739,49 +738,26 @@ public record SwedishGenerator(int[] buff) {
|
||||
for (var i = 0; i < s.len(); i++) cross += (cellCount[s.pos(i)] - 1);
|
||||
return cross * 10 + s.len();
|
||||
}
|
||||
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);
|
||||
n++;
|
||||
grid.setCharAt(r, c, ch);
|
||||
} else {
|
||||
if (cur != ch) {
|
||||
for (var j = 0; j < n; j++) {
|
||||
long v = undoBuffer[offset + j];
|
||||
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;
|
||||
static int placeWord(Grid grid, Slot s, Lemma w, int[] undoBuffer, int offset) {
|
||||
int mask = 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++;
|
||||
mask |= (1 << i);
|
||||
grid.setCharAt(idx, ch);
|
||||
} else {
|
||||
if (cur != ch) {
|
||||
for (var j = 0; j < n; j++) {
|
||||
long v = undoBuffer[offset + j];
|
||||
grid.clear((int) v);
|
||||
} else if (cur != ch) {
|
||||
for (var j = 0; j < i; j++) {
|
||||
if ((mask & (1 << j)) != 0) {
|
||||
grid.clear(s.pos(j));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
undoBuffer[offset] = mask;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
|
||||
@@ -886,7 +862,6 @@ public record SwedishGenerator(int[] buff) {
|
||||
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;
|
||||
var L = idxs.length;
|
||||
@@ -909,7 +884,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
if (!match) continue;
|
||||
|
||||
int nPlaced = placeWord(grid, s, w, ctx.undoBuffer, undoOffset);
|
||||
int nPlaced = placeWord(grid, s, w, ctx.undoBuffer, depth);
|
||||
if (nPlaced < 0) continue;
|
||||
|
||||
used.set(w.index());
|
||||
@@ -919,7 +894,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
assigned.remove(k);
|
||||
used.clear(w.index);
|
||||
undoPlace(grid, ctx.undoBuffer, undoOffset, nPlaced);
|
||||
undoPlace(grid, s, ctx.undoBuffer[depth]);
|
||||
}
|
||||
stats.backtracks++;
|
||||
return false;
|
||||
@@ -948,7 +923,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
if (!match) continue;
|
||||
|
||||
int nPlaced = placeWord(grid, s, w, ctx.undoBuffer, undoOffset);
|
||||
int nPlaced = placeWord(grid, s, w, ctx.undoBuffer, depth);
|
||||
if (nPlaced < 0) continue;
|
||||
|
||||
used.set(w.index());
|
||||
@@ -958,7 +933,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
assigned.remove(k);
|
||||
used.clear(w.index);
|
||||
undoPlace(grid, ctx.undoBuffer, undoOffset, nPlaced);
|
||||
undoPlace(grid, s, ctx.undoBuffer[depth]);
|
||||
}
|
||||
|
||||
stats.backtracks++;
|
||||
|
||||
Reference in New Issue
Block a user