introduce bitloops
This commit is contained in:
@@ -61,16 +61,21 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
static int clamp(int x, int a, int b) { return Math.max(a, Math.min(b, x)); }
|
||||
record Pick(Slot slot, CandidateInfo info, boolean done) { }
|
||||
// 0b11
|
||||
//0b00
|
||||
// 0b01
|
||||
// 0b10
|
||||
|
||||
static final byte B0 = (byte) 0;
|
||||
static final byte B64 = (byte) 64;
|
||||
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
|
||||
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;
|
||||
static final long[] NBR8_PACKED_HI = Neighbors9x8.NBR8_PACKED_HI;
|
||||
static final long[] PATH_LO = Neighbors9x8.PATH_LO;
|
||||
static final long[] PATH_HI = Neighbors9x8.PATH_HI;
|
||||
static final byte B0 = (byte) 0;
|
||||
static final byte B64 = (byte) 64;
|
||||
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
|
||||
static final long[] OFFSET_D_IDX_0_BASE = Neighbors9x8.OFFSET_D_IDX_0_BASE;
|
||||
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;
|
||||
static final long[] NBR8_PACKED_HI = Neighbors9x8.NBR8_PACKED_HI;
|
||||
static final long[] PATH_LO = Neighbors9x8.PATH_LO;
|
||||
static final long[] PATH_HI = Neighbors9x8.PATH_HI;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
@@ -317,11 +322,11 @@ public record SwedishGenerator(Rng rng) {
|
||||
public static int clueIndex(int key) { return key >>> BIT_FOR_DIR; }
|
||||
public static int dir(int key) { return key & 7; }
|
||||
public boolean horiz() { return horiz(key); }
|
||||
public boolean reversed() { return (key & 2) == 0; }
|
||||
public boolean increasing() { return (key & 2) != 0; }
|
||||
public static boolean increasing(int dir) { return (dir & 2) != 0; }
|
||||
public IntStream walk() { return Gridded.walk((byte) key, lo, hi); }
|
||||
public static boolean horiz(int d) { return (d & 1) == 0; }
|
||||
public static boolean horizv2(int d) { return (d & 1) == 1; }
|
||||
public static int packSlotDir(int idx, int d) { return (idx << BIT_FOR_DIR) | d; }
|
||||
}
|
||||
|
||||
@@ -410,7 +415,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
}
|
||||
if ((rLo | rHi) != 0) {
|
||||
hasSlots = true;
|
||||
if (Slot.horiz(d + 1)) covH.or(rLo, rHi);
|
||||
if (Slot.horizv2(d)) covH.or(rLo, rHi);
|
||||
else covV.or(rLo, rHi);
|
||||
if ((Long.bitCount(rLo) + Long.bitCount(rHi)) < MIN_LEN) penalty += 8000;
|
||||
} else {
|
||||
@@ -555,7 +560,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
for (var hi = out.hi; hi != X; hi &= hi - 1L) clearClues(out, 64 + Long.numberOfTrailingZeros(hi));
|
||||
return out;
|
||||
}
|
||||
public static void clearClues(Grid out, int idx) { if (!out.hasRoomForClue(OFFSETS_D_IDX[(out.digitAt(idx) ) | (idx << 2)])) out.clearClue(idx); }
|
||||
public static void clearClues(Grid out, int idx) { if (!out.hasRoomForClue(OFFSETS_D_IDX[(out.digitAt(idx)) | (idx << 2)])) out.clearClue(idx); }
|
||||
|
||||
Grid hillclimb(Grid start, int limit) {
|
||||
var best = start;
|
||||
|
||||
Reference in New Issue
Block a user