introduce bitloops
This commit is contained in:
@@ -66,7 +66,6 @@ public record SwedishGenerator(Rng rng) {
|
||||
static final byte B64 = (byte) 64;
|
||||
static final byte B48 = (byte) 48;
|
||||
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
|
||||
static final nbrs_16[] OFFSETS_FOUR = Neighbors9x8.OFFSETS_FOUR;
|
||||
static final rci[] IT = Neighbors9x8.IT;
|
||||
static final int[][] MUTATE_RI = new int[SIZE][625];
|
||||
static final long[] NBR8_PACKED_LO = Neighbors9x8.NBR8_PACKED_LO;
|
||||
@@ -208,8 +207,6 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
static boolean isLetter(byte b) { return (b & B64) != B0; }
|
||||
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||
static boolean notDigit(byte b) { return (b & B48) != B48; }
|
||||
public boolean isLetterAt(int index) { return notDigit(g[index]); }
|
||||
|
||||
public double similarity(Grid b) {
|
||||
var same = 0;
|
||||
@@ -363,7 +360,6 @@ public record SwedishGenerator(Rng rng) {
|
||||
int clueIdx = i | Long.numberOfTrailingZeros(bits);
|
||||
var d = grid.digitAt(clueIdx);
|
||||
long packed = OFFSETS_D_IDX[(d - 1) | (clueIdx << 2)];
|
||||
//if (OFFSETS_D_IDX[(d-1) * SIZE + clueIdx] != packed) throw new IllegalStateException("Invalid path index for digit " + d + " at clue " + clueIdx);
|
||||
|
||||
int n = (int) (packed >>> 56) * 7, k, idx;
|
||||
var horiz = Slot.horiz(d) ? covH : covV;
|
||||
@@ -466,10 +462,10 @@ public record SwedishGenerator(Rng rng) {
|
||||
for (int placed = 0, guard = 0, idx; placed < TARGET_CLUES && guard < 4000; guard++) {
|
||||
idx = rng.randint(0, SIZE_MIN_1);
|
||||
if (g.isClue(idx)) continue;
|
||||
var d = OFFSETS_FOUR[rng.randint2bit()];
|
||||
|
||||
if (g.hasRoomForClue(d.path()[idx])) {
|
||||
g.setClue(idx, d.dbyte());
|
||||
int d_idx = rng.randint2bit();
|
||||
val packed = OFFSETS_D_IDX[d_idx | idx << 2];
|
||||
if (g.hasRoomForClue(packed)) {
|
||||
g.setClue(idx, (byte) (1 + (d_idx | 48)));
|
||||
placed++;
|
||||
}
|
||||
}
|
||||
@@ -479,12 +475,12 @@ public record SwedishGenerator(Rng rng) {
|
||||
var g = grid.deepCopyGrid();
|
||||
int ri;
|
||||
var bytes = MUTATE_RI[rng.randint(0, SIZE_MIN_1)];
|
||||
nbrs_16 d;
|
||||
for (var k = 0; k < 4; k++) {
|
||||
ri = bytes[rng.randint(0, 624)];
|
||||
if (!g.clueless(ri)) {
|
||||
d = OFFSETS_FOUR[rng.randint2bit()];
|
||||
if (g.hasRoomForClue(d.path()[ri])) g.setClue(ri, d.dbyte());
|
||||
int d_idx = rng.randint2bit();
|
||||
val packed = OFFSETS_D_IDX[d_idx | ri << 2];
|
||||
if (g.hasRoomForClue(packed)) g.setClue(ri, (byte) (1 + (d_idx | 48)));
|
||||
}
|
||||
}
|
||||
return g;
|
||||
|
||||
@@ -3,13 +3,4 @@ package puzzle;
|
||||
import precomp.Neighbors9x8;
|
||||
public class TestGen {
|
||||
|
||||
static void main() {
|
||||
var cell = Neighbors9x8.IT[0];
|
||||
long n1 = cell.n1();
|
||||
long n2 = cell.n2();
|
||||
int count = cell.nbrCount();
|
||||
|
||||
// of direct je offsets:
|
||||
var up = Neighbors9x8.OFFSETS[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class MainTest {
|
||||
// Regression baseline for seed search starting at 12347, pop 4, gens 20
|
||||
Assertions.assertEquals(12348, foundSeed, "Found seed changed");
|
||||
Assertions.assertEquals(18, res.filled().clueMap().size(), "Number of assigned words changed");
|
||||
Assertions.assertEquals("RIJTUIG", Lemma.asWord( res.filled().clueMap().get(74)));
|
||||
Assertions.assertEquals("TEN", Lemma.asWord(res.filled().clueMap().get(2)));
|
||||
Assertions.assertEquals(301794542151533187L, res.filled().grid().grid().lo);
|
||||
Assertions.assertEquals(193L, res.filled().grid().grid().hi);
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ public class SwedishGeneratorTest {
|
||||
|
||||
assertEquals('A', grid.byteAt(0));
|
||||
assertEquals(1, grid.digitAt(Grid.offset(0, 1)));
|
||||
assertTrue(grid.isLetterAt(0));
|
||||
assertTrue(grid.notClue(0));
|
||||
assertFalse(grid.isClue(0));
|
||||
assertTrue(grid.isClue(Grid.offset(0, 1)));
|
||||
assertFalse(grid.isLetterAt(Grid.offset(0, 1)));
|
||||
assertTrue(grid.isLetterAt(0));
|
||||
assertFalse(grid.isLetterAt(Grid.offset(0, 1)));
|
||||
assertFalse(grid.notClue(Grid.offset(0, 1)));
|
||||
assertTrue(grid.notClue(0));
|
||||
assertFalse(grid.notClue(Grid.offset(0, 1)));
|
||||
|
||||
var copy = grid.deepCopyGrid();
|
||||
assertEquals('A', copy.byteAt(0));
|
||||
|
||||
Reference in New Issue
Block a user