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;
}

View File

@@ -3,7 +3,6 @@ package puzzle;
import anno.ConstGen;
import anno.GenerateNeighbor;
import anno.GenerateNeighbors;
import anno.GenerateShapedCopies;
import anno.Shaped;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@@ -36,10 +35,6 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
@GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2)
})
/*@GenerateShapedCopies(
className = "SwedishGeneratorX",
shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3" }
)*/
public record SwedishGenerator() {
public static final int MAX_TRIES_PER_SLOT = 500;// MAX_TRIES_PER_SLOT;
@@ -59,7 +54,7 @@ public record SwedishGenerator() {
//@formatter:off
public record Dict(DictEntry[] index,DictEntry[] reversed, int length) { public Dict(DictEntry[] index,int length){this(index,index,length);} }
public record DictEntry(long[] words, long[][] posBitsets, int length, int numlong) { }
@AllArgsConstructor @NoArgsConstructor static final class Assign { long w; }
@AllArgsConstructor @NoArgsConstructor public static final class Assign { long w; }
@AllArgsConstructor public static final class Grid { public final byte[] g; public long lo, hi; }
public record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed ) { }
//@formatter:on

View File

@@ -0,0 +1,17 @@
package puzzle;
import anno.GenerateShapedCopies;
import anno.Shaped;
import precomp.Neighbors9x8;
@GenerateShapedCopies(
packageName = "gen",
className = "Test123X",
shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3" }
)
public class Test123 {
@Shaped public static int SIZE = Neighbors9x8.SIZE;
public static void start() {
System.out.println(SIZE);
}
}

View File

@@ -5,7 +5,7 @@ import anno.DictGen;
import lombok.val;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import precomp.Neighbors9x8.rci;
import gen.rci;
import puzzle.Export.Vestigium;
import puzzle.Export.Signa;
import puzzle.Export.Puzzle;

View File

@@ -8,7 +8,7 @@ import lombok.val;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import precomp.Neighbors9x8;
import precomp.Neighbors9x8.rci;
import gen.rci;
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
import puzzle.Export.Signa;
import puzzle.Export.Puzzle;

View File

@@ -0,0 +1,39 @@
package puzzle;
import gen.Test123X_Neighbors4x3;
import gen.Test123X_Neighbors9x8;
import lombok.val;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import puzzle.Export.Signa;
import puzzle.Export.Vestigium;
import puzzle.dict800.DictData800;
import puzzle.dict950.DictData950;
import java.util.stream.Collectors;
import static precomp.Const9x8.Cell.r0c0d1;
import static precomp.Const9x8.Cell.r1c0d1;
import static precomp.Const9x8.Cell.r2c0d1;
import static precomp.Const9x8.Cell.r3c0d1;
public class TestDuplication {
@Test
void test() {
Test123.start();
Test123X_Neighbors4x3.start();
Test123X_Neighbors9x8.start();
}
@Test
void testFiller2() {
var mask = Signa.of(
r0c0d1,
r1c0d1,
r2c0d1,
r3c0d1);
Assertions.assertEquals(4, mask.clueCount());
val map = mask.stream().collect(Collectors.toMap(Vestigium::index, Vestigium::clue));
Assertions.assertEquals(4, map.size());
var slots = mask.slots(DictData800.DICT800);
// var filled = fillMask(rng, slotInfo, grid, false);
// val res = new PuzzleResult(new Clued(mask), new Gridded(grid), slotInfo, filled).exportFormatFromFilled(0, new Rewards(0, 0, 0));
}
}