This commit is contained in:
mike
2026-01-23 02:56:14 +01:00
parent dc45ad45c9
commit 4b61205bbb
6 changed files with 96 additions and 39 deletions

View File

@@ -1,42 +1,48 @@
package puzzle;
import module java.base;
import anno.GenerateShapedCopies;
import anno.Shaped;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;
import lombok.val;
import precomp.Neighbors9x8;
import precomp.Neighbors9x8.rci;
import gen.rci;
import static java.lang.Long.*;
import static puzzle.SwedishGenerator.*;
@GenerateShapedCopies(
packageName = "gen",
className = "Masker",
shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3" }
)
public final class Masker {
@Shaped public static final rci[] IT = Neighbors9x8.IT;
@Shaped public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
@Shaped public static final long[] PATH_HI = Neighbors9x8.PATH_HI;
@Shaped public static final long MASK_LO = -1L;
@Shaped public static final long MASK_HI = Neighbors9x8.MASK_HI;//(1L << (SIZE - 64)) - 1;
@Shaped public static final int MIN_LEN = Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
@Shaped public static final int C = Neighbors9x8.C;
@Shaped public static final int R = Neighbors9x8.R;
@Shaped public static final int SIZE = Neighbors9x8.SIZE;
@Shaped public static final double SIZED = Neighbors9x8.SIZED;// ~18
@Shaped private static final long[] NBR_LO = Neighbors9x8.NBR_LO;
@Shaped private static final long[] NBR_HI = Neighbors9x8.NBR_HI;
@Shaped private final int[] activeCIdx = new int[Neighbors9x8.SIZE];
@Shaped private final long[] activeSLo = new long[Neighbors9x8.SIZE];
@Shaped private final long[] activeSHi = new long[Neighbors9x8.SIZE];
@Shaped private final long[] adjLo = new long[Neighbors9x8.SIZE];
@Shaped private final long[] adjHi = new long[Neighbors9x8.SIZE];
@Shaped private final int[] rCount = new int[Neighbors9x8.R];
@Shaped private final int[] cCount = new int[Neighbors9x8.C];
private final Rng rng;
private final int[] stack;
private final Clues cache;
public static final int STACK_SIZE = 128;
@Shaped public static final int SIZE = Neighbors9x8.SIZE;
@Shaped public static final rci[] IT = Neighbors9x8.IT;
@Shaped public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
@Shaped public static final long[] PATH_HI = Neighbors9x8.PATH_HI;
@Shaped public static final long MASK_LO = Neighbors9x8.MASK_LO;
@Shaped public static final long MASK_HI = Neighbors9x8.MASK_HI;//(1L << (SIZE - 64)) - 1;
@Shaped public static final int MIN_LEN = Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
@Shaped public static final int C = Neighbors9x8.C;
@Shaped public static final int R = Neighbors9x8.R;
@Shaped public static final double SIZED = Neighbors9x8.SIZED;// ~18
@Shaped private static final long[] NBR_LO = Neighbors9x8.NBR_LO;
@Shaped private static final long[] NBR_HI = Neighbors9x8.NBR_HI;
private static final boolean VERBOSE = false;
private final int[] activeCIdx = new int[SIZE];
private final long[] activeSLo = new long[SIZE];
private final long[] activeSHi = new long[SIZE];
private final long[] adjLo = new long[SIZE];
private final long[] adjHi = new long[SIZE];
private final int[] rCount = new int[R];
private final int[] cCount = new int[C];
private final Rng rng;
private final int[] stack;
private final Clues cache;
public static final int STACK_SIZE = 128;
public Masker(Rng rng, int[] stack, Clues cache) {
this.rng = rng;
this.stack = stack;
@@ -179,8 +185,8 @@ public final class Masker {
}
public static Slotinfo[] slots(Clues mask, Dict d) { return slots(mask, d.index(), d.reversed()); }
public static Slotinfo[] slots(Clues mask, DictEntry[] index, DictEntry[] rev) {
var slots = Masker.extractSlots(mask, index, rev);
return Masker.scoreSlots(slots);
var slots = extractSlots(mask, index, rev);
return scoreSlots(slots);
}
public static Slotinfo[] scoreSlots(Slot[] slots) {
val count = new byte[SIZE];
@@ -191,7 +197,7 @@ public final class Masker {
}
for (var i = 0; i < slots.length; i++) {
var slot = slots[i];
slotInfo[i] = new Slotinfo(slot.key, slot.lo, slot.hi, slotScore(count, slot.lo, slot.hi), new Assign(), slot.entry,
slotInfo[i] = new Slotinfo(slot.key, slot.lo, slot.hi, slotScore(count, slot.lo, slot.hi), new puzzle.SwedishGenerator.Assign(), slot.entry,
Math.min(slot.entry.words().length, MAX_TRIES_PER_SLOT));
}
return slotInfo;
@@ -589,7 +595,7 @@ public final class Masker {
return this.fite;
}
}
if (Main.VERBOSE) System.out.println("generateMask init pop: " + popSize + " clueSize: " + clueSize);
if (VERBOSE) System.out.println("generateMask init pop: " + popSize + " clueSize: " + clueSize);
var pop = new GridAndFit[popSize];
for (var i = 0; i < popSize; i++) {
if (Thread.currentThread().isInterrupted()) return null;
@@ -643,7 +649,7 @@ public final class Masker {
}
pop = nextCount == popSize ? next : Arrays.copyOf(next, nextCount);
if (Main.VERBOSE && (gen & 15) == 15) System.out.println(" gen " + gen + "/" + gens + " bestFitness=" + pop[0].fit());
if (VERBOSE && (gen & 15) == 15) System.out.println(" gen " + gen + "/" + gens + " bestFitness=" + pop[0].fit());
}
if (pop.length == 0) return null;
var best = pop[0];
@@ -669,7 +675,7 @@ public final class Masker {
}
public Clues setClue(precomp.Const9x8.Cell cell) {
if (cell.index < 64) setClueLo(cell.mask, cell.d);
if ((cell.index & 64) == 0) setClueLo(cell.mask, cell.d);
else setClueHi(cell.mask, cell.d);
return this;
}