introduce bitloops
This commit is contained in:
@@ -52,7 +52,7 @@ public class ExportFormatTest {
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4);
|
||||
clueMap[key] = TEST;
|
||||
assertTrue(placeWord(grid.grid(), key, lo, 0L, TEST));
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
||||
|
||||
var fillResult = new FillResult(true, grid, clueMap, new FillStats(0, 0, 0, 0));
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), fillResult);
|
||||
|
||||
@@ -24,8 +24,7 @@ import static puzzle.SwedishGeneratorTest.OFF_0_2;
|
||||
|
||||
public class MainTest {
|
||||
|
||||
|
||||
static final Opts opts = new Main.Opts() {{
|
||||
static final Opts opts = new Main.Opts() {{
|
||||
this.seed = 12348;
|
||||
this.clueSize = 4;
|
||||
this.pop = 4; // Tiny population
|
||||
@@ -36,7 +35,7 @@ public class MainTest {
|
||||
this.tries = 1;
|
||||
this.verbose = false;
|
||||
}};
|
||||
static final Dict dict = Dict.loadDict(opts.wordsPath);
|
||||
static final Dict dict = Dict.loadDict(opts.wordsPath);
|
||||
@Test
|
||||
void testExtractSlots() {
|
||||
|
||||
@@ -44,8 +43,8 @@ public class MainTest {
|
||||
val key = Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
clues.setClue(OFF_0_0, CLUE_RIGHT);
|
||||
var grid = new Gridded(clues.toGrid());
|
||||
|
||||
placeWord(grid.grid(), key, (1L << OFF_0_1) | (1L << OFF_0_2), 0, AB);
|
||||
val g = grid.grid().g;
|
||||
placeWord(grid.grid(), g, key, (1L << OFF_0_1) | (1L << OFF_0_2), 0, AB);
|
||||
|
||||
var slots = extractSlots(clues, dict.index());
|
||||
assertEquals(1, slots.length);
|
||||
@@ -95,7 +94,7 @@ public class MainTest {
|
||||
var grid = new Gridded(clues.toGrid());
|
||||
|
||||
// Test set/get
|
||||
placeWord(grid.grid(), key, (1L << OFF_1_1) | (1L << OFF_0_1), 0, AZ);
|
||||
placeWord(grid.grid(), grid.grid().g, key, (1L << OFF_1_1) | (1L << OFF_0_1), 0, AZ);
|
||||
val arr = grid.stream(clues).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
Assertions.assertEquals(LETTER_A, arr.get(OFF_1_1));
|
||||
Assertions.assertEquals(LETTER_Z, arr.get(OFF_0_1));
|
||||
@@ -193,6 +192,8 @@ public class MainTest {
|
||||
System.out.println("[DEBUG_LOG] ClueMap Size: " + res.filled().wordCount());
|
||||
System.out.println("[DEBUG_LOG] Grid:");
|
||||
System.out.println(res.filled().grid().renderHuman(res.clues().mask()));
|
||||
System.out.println(res.filled().grid().gridToString(res.clues().mask()));
|
||||
System.out.println(res.filled().grid().renderHuman(res.clues().mask()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class SwedishGeneratorTest {
|
||||
var key = Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
val clues = Clues.createEmpty();
|
||||
clues.setClue(OFF_0_0, CLUE_RIGHT);
|
||||
placeWord(grid.grid(), key, (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3), 0L, ABC);
|
||||
placeWord(grid.grid(), grid.grid().g, key, (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3), 0L, ABC);
|
||||
val map = grid.stream(clues).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(LETTER_A, map.get(OFF_0_1));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_2));
|
||||
@@ -100,10 +100,10 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotMixed() {
|
||||
var grid = createEmpty();
|
||||
placeWord(grid, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
placeWord(grid, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_2_0, 0, Lemma.from(0, "C"));
|
||||
placeWord(grid, grid.g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
placeWord(grid, grid.g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_2_0, 0, Lemma.from(0, "C"));
|
||||
var key = Slot.packSlotKey(OFF_1_0, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(1L | (55L << 16), pattern);
|
||||
}
|
||||
|
||||
@@ -111,16 +111,16 @@ public class SwedishGeneratorTest {
|
||||
void testPatternForSlotAllDashes() {
|
||||
var grid = createEmpty();
|
||||
var key = Slot.packSlotKey(1 << Slot.BIT_FOR_DIR, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(0L, pattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPatternForSlotSingleLetter() {
|
||||
var grid = createEmpty();
|
||||
placeWord(grid, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
placeWord(grid, grid.g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
var key = Slot.packSlotKey(1, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(1L, pattern);
|
||||
}
|
||||
@Test
|
||||
@@ -134,8 +134,8 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(val1, rng2.nextU32());
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var r = rng.randint(5, 10);
|
||||
assertTrue(r >= 5 && r <= 10);
|
||||
var r = rng.randint(5);
|
||||
assertTrue(r >= 0 && r <= 5);
|
||||
var f = rng.nextFloat();
|
||||
assertTrue(f >= 0.0 && f <= 1.0);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testGrid() {
|
||||
var grid = new Gridded(createEmpty());
|
||||
placeWord(grid.grid(), Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
placeWord(grid.grid(), grid.grid().g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
val arr = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(1, arr.size());
|
||||
assertEquals(LETTER_A, arr.get(OFF_0_0));
|
||||
@@ -290,7 +290,7 @@ public class SwedishGeneratorTest {
|
||||
var w1 = ABC;
|
||||
|
||||
// 1. Successful placement in empty grid
|
||||
assertTrue(placeWord(grid.grid(), key, lo, hi, w1));
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
var map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(3, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_0));
|
||||
@@ -298,9 +298,9 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(LETTER_C, map.get(OFF_0_2));
|
||||
|
||||
// 2. Successful placement with partial overlap (same characters)
|
||||
assertTrue(placeWord(grid.grid(), key, lo, hi, w1));
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
// 3. Conflict: place "ABD" where "ABC" is
|
||||
assertFalse(placeWord(grid.grid(), key, lo, hi, ABD));
|
||||
assertFalse(placeWord(grid.grid(), grid.grid().g, key, lo, hi, ABD));
|
||||
// Verify grid is unchanged (still "ABC")
|
||||
map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(3, map.size());
|
||||
@@ -310,8 +310,8 @@ public class SwedishGeneratorTest {
|
||||
|
||||
// 4. Partial placement then conflict (rollback)
|
||||
grid = new Gridded(createEmpty());
|
||||
placeWord(grid.grid(), Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_2, 0, Lemma.from(0, "X")); // Conflict at the end
|
||||
assertFalse(placeWord(grid.grid(), key, lo, hi, w1));
|
||||
placeWord(grid.grid(), grid.grid().g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_2, 0, Lemma.from(0, "X")); // Conflict at the end
|
||||
assertFalse(placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(LETTER_X, map.get(OFF_0_2));
|
||||
@@ -326,7 +326,7 @@ public class SwedishGeneratorTest {
|
||||
var w = AZ;
|
||||
val low = grid.grid().lo;
|
||||
val top = grid.grid().hi;
|
||||
var placed = placeWord(grid.grid(), key, lo, 0L, w);
|
||||
var placed = placeWord(grid.grid(), grid.grid().g, key, lo, 0L, w);
|
||||
assertTrue(placed);
|
||||
var map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(2, map.size());
|
||||
|
||||
Reference in New Issue
Block a user