introduce bitloops

This commit is contained in:
mike
2026-01-20 04:51:32 +01:00
parent 0dcfbebcb0
commit ba90818b66
4 changed files with 29 additions and 23 deletions

View File

@@ -34,7 +34,7 @@ public class Main {
@NoArgsConstructor
public static class Opts {
static int SSIZE = 20;
static int SSIZE = 23;
public int seed = (int) (System.nanoTime() ^ System.currentTimeMillis());
public int clueSize = SSIZE;
public int pop = SSIZE * 2;

View File

@@ -20,7 +20,8 @@ public final class Masker {
private final long[] activeSHi = new long[SwedishGenerator.SIZE];
private final long[] adjLo = new long[SwedishGenerator.SIZE];
private final long[] adjHi = new long[SwedishGenerator.SIZE];
private final int[] rCount = new int[8];
private final int[] cCount = new int[9];
public Masker(Rng rng, int[] stack, Clues cache) {
this.rng = rng;
this.stack = stack;
@@ -194,7 +195,10 @@ public final class Masker {
long lo_cl = grid.lo, hi_cl = grid.hi;
long penalty = (((long) Math.abs(grid.clueCount() - clueSize)) * 16000L);
boolean hasSlots = false;
if (!isValid(grid, 2)) return 1_000_000_000L;
/* if (!isValid(grid, 2)) {
throw new RuntimeException("Invalid grid configuration for mask fitness calculation");
//return 1_000_000_000L;
}*/
int numClues = 0;
for (long bits = lo_cl; bits != X; bits &= bits - 1) {
@@ -288,8 +292,8 @@ public final class Masker {
if (!hasSlots) return 1_000_000_000L;
int[] rCount = new int[8];
int[] cCount = new int[9];
Arrays.fill(rCount, 0);
Arrays.fill(cCount, 0);
for (int i = 0; i < numClues; i++) {
int idx = activeCIdx[i];
rCount[idx & 7]++;
@@ -383,13 +387,12 @@ public final class Masker {
else penalty += 1000;
}
long nclLo = ~lo_cl & MASK_LO;
long nclHi = ~hi_cl & MASK_HI;
long hNbrLo = (nclLo >> 8) | (nclLo << 8) | (nclHi << 56);
long hNbrHi = (nclHi >> 8) | (nclLo >> 56);
long vNbrLo = ((nclLo & ~0x0101010101010101L) >> 1) | ((nclLo & ~0x8080808080808080L) << 1);
long vNbrHi = ((nclHi & ~0x01L) >> 1) | ((nclHi & ~0x80L) << 1);
//long nclLo = ~lo_cl & MASK_LO;
//long nclHi = ~hi_cl & MASK_HI;
//long hNbrLo = (nclLo >> 8) | (nclLo << 8) | (nclHi << 56);
//long hNbrHi = (nclHi >> 8) | (nclLo >> 56);
//long vNbrLo = ((nclLo & ~0x0101010101010101L) >> 1) | ((nclLo & ~0x8080808080808080L) << 1);
//long vNbrHi = ((nclHi & ~0x01L) >> 1) | ((nclHi & ~0x80L) << 1);
//penalty += bitCount(nclLo & ~cHLo & hNbrLo) * 800;
//penalty += bitCount(nclLo & ~cVLo & vNbrLo) * 800;
//penalty += bitCount(nclHi & ~cHHi & hNbrHi) * 800;

View File

@@ -40,7 +40,7 @@ public record SwedishGenerator() {
public static final int MAX_WORD_LENGTH = Config.PUZZLE_ROWS;
public static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
public static final int MIN_LEN = 2;//Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
public static final int MAX_TRIES_PER_SLOT = 700;//Config.MAX_TRIES_PER_SLOT;
public static final int MAX_TRIES_PER_SLOT = 400;//Config.MAX_TRIES_PER_SLOT;
public static final int STACK_SIZE = 128;
public static final long RANGE_0_SIZE = Neighbors9x8.RANGE_0_SIZE;// (long) SIZE_MIN_1 - 0L + 1L
public static final long RANGE_0_624 = Neighbors9x8.RANGE_0_624;//624L - 0L + 1L;