introduce bitloops

This commit is contained in:
mike
2026-01-21 06:38:25 +01:00
parent dd53009e69
commit 1e13d39153
46 changed files with 51 additions and 150429 deletions

View File

@@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.val;
import precomp.Neighbors9x8;
import puzzle.SwedishGenerator.Dict;
import puzzle.SwedishGenerator.DictEntry;
import puzzle.SwedishGenerator.Lemma;
@@ -16,7 +17,7 @@ public final class DictJavaGeneratorMulti {
interface Dicts {
static Dict makeDict(long[] wordz) {
var index = new DictEntryDTO[SwedishGenerator.MAX_WORD_LENGTH_PLUS_ONE];
var index = new DictEntryDTO[Neighbors9x8.MAX_WORD_LENGTH_PLUS_ONE];
Arrays.setAll(index, DictEntryDTO::new);
for (var lemma : wordz) {
var L = Lemma.unpackSize(lemma) + 1;//Lemma.unpackSize(lemma) + 2;

View File

@@ -49,7 +49,7 @@ public class MainTest {
val g = grid.grid().g;
GridBuilder.placeWord(grid.grid(), g, r0c0d1.slotKey, (1L << OFF_0_1) | (1L << OFF_0_2), 0, AB);
var slots = clues.slots();
var slots = clues.slots(DictData950.DICT950);
assertEquals(1, slots.length);
var s = slots[0];
assertEquals(8, Masker.Slot.length(s.lo(), s.hi()));
@@ -155,7 +155,7 @@ public class MainTest {
Assertions.assertEquals(20, mask.clueCount());
val map = mask.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
Assertions.assertEquals(20, map.size());
var slots = mask.slots();
var slots = mask.slots(DictData950.DICT950);
// 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));
}
@@ -173,12 +173,12 @@ public class MainTest {
r6c1d1, r6c8d2,
r7c0d2, r7c1d1, r7c4d2, r7c5d2, r7c8d3
);
var slotInfo = mask.slots(/*DictData950.DICT950*/);
var slotInfo = mask.slots(DictData950.DICT950);
var grid = Slotinfo.grid(slotInfo);
var filled = fillMask(rng, slotInfo, grid);
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
Assertions.assertEquals(17, Slotinfo.wordCount(0, slotInfo), "Number of assigned words changed");
Assertions.assertEquals("VREEMDS", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get()));
Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get()));
Assertions.assertEquals(-1L, grid.lo);
Assertions.assertEquals(-1L, grid.hi);
var g = new Gridded(grid, mask.c());
@@ -193,7 +193,7 @@ public class MainTest {
int foundSeed = -1;
for (int i = 0; i < 50; i++) {
int seed = opts.seed + i;
res = Main.attempt(new Rng(seed), DictData.DICT, opts);
res = Main.attempt(new Rng(seed), DictData950.DICT950, opts);
if (res != null && res.filled().ok()) {
foundSeed = seed;
System.out.println("[DEBUG_LOG] Seed found: " + seed);

View File

@@ -14,6 +14,7 @@ import puzzle.SwedishGenerator.FillStats;
import puzzle.SwedishGenerator.Lemma;
import puzzle.SwedishGenerator.Rng;
import puzzle.SwedishGenerator.Slotinfo;
import puzzle.dict950.DictData950;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -22,9 +23,9 @@ import static precomp.Const9x8.*;
import static precomp.Const9x8.Cell.*;
import static puzzle.GridBuilder.placeWord;
import static puzzle.LemmaData.TEST;
import static puzzle.SwedishGenerator.C;
import static puzzle.SwedishGenerator.R;
import static puzzle.SwedishGenerator.STACK_SIZE;
import static puzzle.Masker.C;
import static puzzle.Masker.R;
import static puzzle.Masker.STACK_SIZE;
public class MarkerTest {
@@ -256,7 +257,7 @@ public class MarkerTest {
@Test
void testCornerDownExtraction() {
var slots = Masker.slots(Clued.of(r0c0d4).c(), DictData.DICT.index());
var slots = Masker.slots(Clued.of(r0c0d4).c(), DictData950.DICT950.index());
assertEquals(1, slots.length);
assertEquals(r0c0d4.d, Masker.Slot.dir(slots[0].key()));
}
@@ -286,7 +287,7 @@ public class MarkerTest {
@Test
void testCornerDownLeftExtraction() {
var slots = Clued.of(r0c1d5).slots();
var slots = Clued.of(r0c1d5).slots(DictData950.DICT950);
assertEquals(1, slots.length);
assertEquals(r0c1d5.d, Masker.Slot.dir(slots[0].key()));
@@ -362,7 +363,7 @@ public class MarkerTest {
@Test
void testShardToClue() {
for (var length = 2; length <= 8; length++) {
val entry = DictData.DICT.index()[length];
val entry = DictData950.DICT950.index()[length];
if (entry == null) continue;
val words = entry.words();
for (var i = 0; i < Math.min(words.length, 5); i++) {

View File

@@ -7,7 +7,6 @@ import puzzle.Export.Clue;
import puzzle.Export.Clued;
import puzzle.Export.Gridded;
import puzzle.Masker.Clues;
import puzzle.SwedishGenerator.DictEntry;
import puzzle.SwedishGenerator.Rng;
import puzzle.SwedishGenerator.Slotinfo;
@@ -19,7 +18,6 @@ import static puzzle.dict900.DictData.DICT900;
public class PerformanceTest {
final DictEntry[] EN = DICT800.index();
void main() {
testIncrementalComplexity();
}
@@ -34,7 +32,7 @@ public class PerformanceTest {
var c = 0;
for (var size : clueSizes) {
var t0 = System.currentTimeMillis();
val masker = new Masker(rng, new int[SwedishGenerator.STACK_SIZE], Masker.Clues.createEmpty());
val masker = new Masker(rng, new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
// Increased population and generations for stress
arr[c++] = masker.generateMask(size, 200, 100, 50);
var t1 = System.currentTimeMillis();
@@ -57,7 +55,7 @@ public class PerformanceTest {
var successCount = 0;
for (var i = 0; i < iterations; i++) {
val slotInfo = Masker.slots(arr[c], EN);
val slotInfo = Masker.slots(arr[c], DICT800.index());
val result = fillMask(rng, slotInfo, Slotinfo.grid(slotInfo));
if (result.ok()) successCount++;
totalNodes += result.nodes();
@@ -106,7 +104,7 @@ public class PerformanceTest {
// A single horizontal slot at (0,0)
val mask = Clued.of(r0c0d1);
val slots = Masker.slots(mask.c(), EN);
val slots = Masker.slots(mask.c(), DICT800.index());
System.out.println("[DEBUG_LOG] \n--- Single Slot Resolution ---");
if (slots.length > 0) {
@@ -143,8 +141,8 @@ public class PerformanceTest {
}
private void visualizeSlots(Slotinfo[] slots) {
var R = SwedishGenerator.R;
var C = SwedishGenerator.C;
var R = Masker.R;
var C = Masker.C;
var display = new char[R][C];
for (var r = 0; r < R; r++) Arrays.fill(display[r], ' ');

View File

@@ -279,7 +279,7 @@ public class SwedishGeneratorTest {
@Test
void testMaskFitnessBasic() {
var gen = new Masker(new Rng(0), new int[STACK_SIZE], Masker.Clues.createEmpty());
var gen = new Masker(new Rng(0), new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
var grid = Masker.Clues.createEmpty();
// Empty grid should have high penalty (no slots)
var f1 = gen.maskFitness(grid, 18);
@@ -294,7 +294,7 @@ public class SwedishGeneratorTest {
@Test
void testGeneticAlgorithmComponents() {
var rng = new Rng(42);
var gen = new Masker(rng, new int[STACK_SIZE], Masker.Clues.createEmpty());
var gen = new Masker(rng, new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
var c1 = new Clued(gen.randomMask(18));
assertNotNull(c1);
@@ -407,7 +407,7 @@ public class SwedishGeneratorTest {
@Test
void testMaskFitnessDetailed() {
var gen = new Masker(new Rng(42), new int[STACK_SIZE], Masker.Clues.createEmpty());
var gen = new Masker(new Rng(42), new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
var grid = Masker.Clues.createEmpty();
// Empty grid: huge penalty
var fitEmpty = gen.maskFitness(grid, 18);