introduce bitloops
This commit is contained in:
@@ -38,7 +38,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
public CandidateInfo(int n) { this(null, n); }
|
||||
}
|
||||
|
||||
|
||||
// static final CandidateInfo[] CANDIDATES = IntStream.range(0, 10192 << 2).mapToObj(CandidateInfo::new).toArray(CandidateInfo[]::new);
|
||||
|
||||
//@formatter:off
|
||||
@@ -121,22 +121,20 @@ public record SwedishGenerator(Rng rng) {
|
||||
}
|
||||
}
|
||||
|
||||
static record Context(int[] covH,
|
||||
int[] covV,
|
||||
int[] cellCount,
|
||||
int[] stack,
|
||||
Bit seen,
|
||||
byte[] pattern,
|
||||
IntList[] intListBuffer,
|
||||
int[] undo,
|
||||
int[] inter1,
|
||||
int[] inter2) {
|
||||
static final class Context {
|
||||
|
||||
public Context() {
|
||||
this(new int[SIZE], new int[SIZE], new int[SIZE], new int[SIZE], new Bit(), new byte[MAX_WORD_LENGTH], new IntList[MAX_WORD_LENGTH],
|
||||
new int[2048], new int[160000], new int[160000]);
|
||||
}
|
||||
void setPatter(byte[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
|
||||
final int[] covH = new int[SIZE];
|
||||
final int[] covV = new int[SIZE];
|
||||
final int[] cellCount = new int[SIZE];
|
||||
final int[] stack = new int[SIZE];
|
||||
final Bit seen = new Bit();
|
||||
long pattern;
|
||||
final IntList[] intListBuffer = new IntList[MAX_WORD_LENGTH];
|
||||
final int[] undo = new int[2048];
|
||||
final int[] inter1 = new int[160000];
|
||||
final int[] inter2 = new int[160000];
|
||||
|
||||
void setPattern(long p) { this.pattern = p; }
|
||||
}
|
||||
|
||||
static final class Rng {
|
||||
@@ -364,7 +362,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
public int dir() { return key & 7; }
|
||||
public boolean horiz() { return horiz(key); }
|
||||
public int pos(int i) { return offset(packedPos, i); }
|
||||
public static boolean horiz(int key) { return (key & 1) == 0/*((key & 15) & 1) == 0*/; }
|
||||
public static boolean horiz(int key) { return (key & 1) == 0; }
|
||||
public static int offset(long packedPos, int i) { return (int) ((packedPos >> (i * 7)) & 127); }
|
||||
public static int packSlotDir(int idx, int d) { return (idx << BIT_FOR_DIR) | d; }
|
||||
}
|
||||
@@ -415,7 +413,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
Arrays.fill(covH, 0, SIZE, 0);
|
||||
Arrays.fill(covV, 0, SIZE, 0);
|
||||
long lo_cl = grid.lo, hi_cl = grid.hi;
|
||||
long penalty = (((long) Math.abs(grid.clueCount() - TARGET_CLUES)) << 3);
|
||||
long penalty = (((long) Math.abs(grid.clueCount() - TARGET_CLUES)) * 16000L);
|
||||
boolean hasSlots = false;
|
||||
|
||||
for (int i = 0; i < 65; i += 64) {
|
||||
@@ -434,6 +432,8 @@ public record SwedishGenerator(Rng rng) {
|
||||
if (k > 0) {
|
||||
hasSlots = true;
|
||||
if (k < MIN_LEN7) penalty += 8000;
|
||||
} else {
|
||||
penalty += 25000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,12 +615,15 @@ public record SwedishGenerator(Rng rng) {
|
||||
//return pop.get(0).grid;
|
||||
return best.grid;
|
||||
}
|
||||
static void patternForSlot(Grid grid, Slot s, byte[] pat) {
|
||||
byte ch;
|
||||
static long patternForSlot(Grid grid, Slot s) {
|
||||
long p = 0;
|
||||
for (int i = 0, len = s.len(); i < len; i++) {
|
||||
ch = grid.byteAt(s.pos(i));
|
||||
pat[i] = isLetter(ch) ? ch : DASH;
|
||||
byte ch = grid.byteAt(s.pos(i));
|
||||
if (isLetter(ch)) {
|
||||
p |= ((long) (ch & 31)) << (i * 5);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static int slotScore(int[] count, Slot s) {
|
||||
@@ -656,11 +659,10 @@ public record SwedishGenerator(Rng rng) {
|
||||
var listBuffer = ctx.intListBuffer;
|
||||
var listCount = 0;
|
||||
IntList tmp;
|
||||
byte ch;
|
||||
for (var i = 0; i < len; i++) {
|
||||
ch = pattern[i];
|
||||
if (isLetter(ch)) {
|
||||
listBuffer[listCount++] = entry.pos[i][ch - 'A'];
|
||||
int val = (int) ((pattern >>> (i * 5)) & 31);
|
||||
if (val != 0) {
|
||||
listBuffer[listCount++] = entry.pos[i][val - 1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,7 +756,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
if (assigned[s.key()] != null) continue;
|
||||
var entry = dictIndex[s.len()];
|
||||
if (entry == null) return PICK_NOT_DONE;
|
||||
patternForSlot(grid, s, ctx.pattern);
|
||||
ctx.pattern = patternForSlot(grid, s);
|
||||
var info = candidateInfoForPattern(ctx, entry, s.len());
|
||||
|
||||
if (info.count == 0) return PICK_NOT_DONE;
|
||||
|
||||
Reference in New Issue
Block a user