introduce bitloops
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package puzzle;
|
||||
|
||||
import module java.base;
|
||||
import gen.GenerateDict;
|
||||
import gen.GenerateNeighbors;
|
||||
import anno.GenerateNeighbor;
|
||||
import anno.GenerateNeighbors;
|
||||
import anno.LemmaGen;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import precomp.Neighbors9x8.rci;
|
||||
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
|
||||
import puzzle.Export.Clued;
|
||||
import puzzle.Export.Gridded;
|
||||
import puzzle.Export.LetterAt;
|
||||
import puzzle.Export.Signa;
|
||||
import puzzle.Export.Puzzle;
|
||||
import puzzle.Export.Lettrix;
|
||||
import puzzle.Masker.Clues;
|
||||
import puzzle.Masker.Slot;
|
||||
|
||||
@@ -37,17 +38,15 @@ import static puzzle.LemmaData.INEREN;
|
||||
import static puzzle.LemmaData.INERENA;
|
||||
import static puzzle.LemmaData.INERENAE;
|
||||
import static puzzle.SwedishGenerator.*;
|
||||
@GenerateNeighbors(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2)
|
||||
@GenerateDict(
|
||||
@GenerateNeighbors(@GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2))
|
||||
@LemmaGen(
|
||||
packageName = "puzzle",
|
||||
className = "LemmaData",
|
||||
scv = "nl_score_hints_v4.csv",
|
||||
words = {
|
||||
"EEN", "NAAR", "IEDEREEN", "A", "C", "X", "TEST", "IN", "INE", "INER", "INEREN", "INERENA", "INERENAE",
|
||||
"APPLE", "AXE", "ABC", "ABD", "AZ", "AB",
|
||||
"AT", "CAT", "DOGS", "APPLY", "BANAN", "BANANA", "BANANAS", "BANANASS"
|
||||
},
|
||||
simpleMax=900,
|
||||
minLen = 2,
|
||||
maxLen = 8
|
||||
)
|
||||
@@ -105,9 +104,9 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testPatternForSlotAllLetters() {
|
||||
var grid = new Gridded(Clued.of(r0c0d1));
|
||||
var grid = new Puzzle(Signa.of(r0c0d1));
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3), 0L, ABC);
|
||||
val map = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
val map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(LETTER_A, map.get(OFF_0_1));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_2));
|
||||
assertEquals(LETTER_C, map.get(OFF_0_3));
|
||||
@@ -167,9 +166,9 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testGrid() {
|
||||
var grid = new Gridded(Clues.createEmpty());
|
||||
var grid = new Puzzle(Clues.createEmpty());
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, 1L << OFF_0_0, 0, WORD_A);
|
||||
val arr = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
val arr = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(1, arr.size());
|
||||
assertEquals(LETTER_A, arr.get(OFF_0_0));
|
||||
}
|
||||
@@ -229,7 +228,7 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(OFF_2_3, Slot.clueIndex(key));
|
||||
assertEquals(CLUE_DOWN, Slot.dir(key));
|
||||
assertFalse(Slot.horiz(key));
|
||||
var cells = Gridded.cellWalk((byte) key, lo, 0L).mapToObj(i -> Masker.IT[i]).toArray(rci[]::new);
|
||||
var cells = Puzzle.cellWalk((byte) key, lo, 0L).mapToObj(i -> Masker.IT[i]).toArray(rci[]::new);
|
||||
assertEquals(2, cells[0].r());
|
||||
assertEquals(3, cells[1].r());
|
||||
assertEquals(4, cells[2].r());
|
||||
@@ -268,7 +267,7 @@ public class SwedishGeneratorTest {
|
||||
void testForEachSlotAndExtractSlots() {
|
||||
// This should detect a slot starting at 0,1 with length 2 (0,1 and 0,2)
|
||||
var dict = DictJavaGeneratorMulti.Dicts.makeDict(WORDS2);
|
||||
var slots = Masker.extractSlots(Clued.of(r0c0d1).c(), dict.index());
|
||||
var slots = Masker.extractSlots(Signa.of(r0c0d1).c(), dict.index());
|
||||
assertEquals(1, slots.length);
|
||||
var s = slots[0];
|
||||
|
||||
@@ -296,10 +295,10 @@ public class SwedishGeneratorTest {
|
||||
var rng = new Rng(42);
|
||||
var gen = new Masker(rng, new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
|
||||
|
||||
var c1 = new Clued(gen.randomMask(18));
|
||||
var c1 = new Signa(gen.randomMask(18));
|
||||
assertNotNull(c1);
|
||||
|
||||
var g2 = new Clued(gen.mutate(c1.deepCopyGrid().c()));
|
||||
var g2 = new Signa(gen.mutate(c1.deepCopyGrid().c()));
|
||||
assertNotNull(g2);
|
||||
assertNotSame(c1.c(), g2.c());
|
||||
|
||||
@@ -311,7 +310,7 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testPlaceWord() {
|
||||
var grid = new Gridded(Clues.createEmpty());
|
||||
var grid = new Puzzle(Clues.createEmpty());
|
||||
// Slot at OFF_0_0 length 3, horizontal (right)
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_0) | (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
@@ -321,7 +320,7 @@ public class SwedishGeneratorTest {
|
||||
// 1. Successful placement in empty grid
|
||||
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
|
||||
var map = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(3, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_0));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_1));
|
||||
@@ -332,24 +331,24 @@ public class SwedishGeneratorTest {
|
||||
// 3. Conflict: place "ABD" where "ABC" is
|
||||
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, ABD));
|
||||
// Verify grid is unchanged (still "ABC")
|
||||
map = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(3, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_0));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_1));
|
||||
assertEquals(LETTER_C, map.get(OFF_0_2));
|
||||
|
||||
// 4. Partial placement then conflict (rollback)
|
||||
grid = new Gridded(Clues.createEmpty());
|
||||
grid = new Puzzle(Clues.createEmpty());
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_2, 0, WORD_X); // Conflict at the end
|
||||
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
map = grid.stream().collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
map = grid.stream().collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(LETTER_X, map.get(OFF_0_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBacktrackingHelpers() {
|
||||
var grid = new Gridded(Clues.createEmpty());
|
||||
var grid = new Puzzle(Clues.createEmpty());
|
||||
// Slot at 0,1 length 2
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
@@ -359,14 +358,14 @@ public class SwedishGeneratorTest {
|
||||
var placed = GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, 0L, w);
|
||||
assertTrue(placed);
|
||||
|
||||
var map = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(2, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_1));
|
||||
assertEquals(LETTER_Z, map.get(OFF_0_2));
|
||||
|
||||
grid.grid().hi = top;
|
||||
grid.grid().lo = low;
|
||||
map = grid.collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(0, map.size());
|
||||
assertFalse(map.containsKey(OFF_0_1));
|
||||
assertFalse(map.containsKey(OFF_0_2));
|
||||
|
||||
Reference in New Issue
Block a user