introduce bitloops
This commit is contained in:
@@ -10,7 +10,6 @@ import puzzle.Export.PuzzleResult;
|
||||
import puzzle.Export.Rewards;
|
||||
import puzzle.SwedishGenerator.Assign;
|
||||
import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import puzzle.SwedishGeneratorTest.Idx;
|
||||
import java.io.IOException;
|
||||
@@ -20,17 +19,15 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static puzzle.ExportFormatTest.Clue.RIGHT;
|
||||
import static puzzle.SwedishGenerator.C;
|
||||
import static puzzle.SwedishGenerator.Clues;
|
||||
import static puzzle.Masker.Clues;
|
||||
import static puzzle.SwedishGenerator.FillStats;
|
||||
import static puzzle.SwedishGenerator.R;
|
||||
import static puzzle.SwedishGenerator.STACK_SIZE;
|
||||
import static puzzle.SwedishGenerator.Slot;
|
||||
import static puzzle.Masker.Slot;
|
||||
import static puzzle.SwedishGenerator.placeWord;
|
||||
import static puzzle.SwedishGeneratorTest.OFF_0_1;
|
||||
import static puzzle.SwedishGeneratorTest.OFF_0_2;
|
||||
import static puzzle.SwedishGeneratorTest.OFF_0_3;
|
||||
import static puzzle.SwedishGeneratorTest.OFF_0_4;
|
||||
import static puzzle.SwedishGeneratorTest.OFF_0_5;
|
||||
import static puzzle.SwedishGeneratorTest.TEST;
|
||||
|
||||
public class ExportFormatTest {
|
||||
@@ -56,8 +53,6 @@ public class ExportFormatTest {
|
||||
|
||||
@Test
|
||||
void testExportFormatFromFilled() {
|
||||
var swe = new SwedishGenerator(new Rng(0), new int[STACK_SIZE], Clues.createEmpty());
|
||||
|
||||
val clues = Clues.createEmpty();
|
||||
// Place a RIGHT clue at (0,0)
|
||||
clues.setClueLo(Idx.IDX_0_0.lo, RIGHT.dir);
|
||||
@@ -72,8 +67,8 @@ public class ExportFormatTest {
|
||||
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
||||
|
||||
var fillResult = new FillResult(true, grid, new FillStats(0, 0, 0, 0));
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), new Slotinfo[]{
|
||||
var fillResult = new FillResult(true, new FillStats(0, 0, 0, 0));
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), grid, new Slotinfo[]{
|
||||
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null)
|
||||
}, fillResult);
|
||||
|
||||
@@ -114,8 +109,8 @@ public class ExportFormatTest {
|
||||
void testExportFormatEmpty() {
|
||||
var grid = SwedishGeneratorTest.createEmpty();
|
||||
val clues = Clues.createEmpty();
|
||||
var fillResult = new FillResult(true, new Gridded(grid), new FillStats(0, 0, 0, 0));
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), new Slotinfo[0], fillResult);
|
||||
var fillResult = new FillResult(true, new FillStats(0, 0, 0, 0));
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), new Gridded(grid), new Slotinfo[0], fillResult);
|
||||
|
||||
var exported = puzzleResult.exportFormatFromFilled(1, new Rewards(0, 0, 0));
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import puzzle.Export.LetterVisit.LetterAt;
|
||||
import puzzle.Export.PuzzleResult;
|
||||
import puzzle.Export.Rewards;
|
||||
import puzzle.Main.Opts;
|
||||
import puzzle.Masker.Clues;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slot;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -46,17 +46,17 @@ public class MainTest {
|
||||
@Test
|
||||
void testExtractSlots() {
|
||||
|
||||
var clues = Clues.createEmpty();
|
||||
val key = Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
var clues = Masker.Clues.createEmpty();
|
||||
val key = Masker.Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
||||
var grid = new Gridded(clues.toGrid());
|
||||
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());
|
||||
var slots = Masker.extractSlots(clues, dict.index());
|
||||
assertEquals(1, slots.length);
|
||||
var s = slots[0];
|
||||
assertEquals(8, Slot.length(s.lo(), s.hi()));
|
||||
assertEquals(8, Masker.Slot.length(s.lo(), s.hi()));
|
||||
var cells = s.walk().toArray();
|
||||
assertEquals(0, SwedishGenerator.IT[cells[0]].r());
|
||||
assertEquals(1, SwedishGenerator.IT[cells[0]].c());
|
||||
@@ -68,14 +68,14 @@ public class MainTest {
|
||||
void testStaticSlotMethods() {
|
||||
// Test static horiz
|
||||
// dir 1 (right) is horizontal
|
||||
assertTrue(Slot.horiz(1));
|
||||
assertTrue(Masker.Slot.horiz(1));
|
||||
// dir 0 (down) is vertical
|
||||
assertFalse(Slot.horiz(0));
|
||||
assertFalse(Masker.Slot.horiz(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEachSlot() {
|
||||
var clues = Clues.createEmpty();
|
||||
var clues = Masker.Clues.createEmpty();
|
||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
||||
var count = new AtomicInteger(0);
|
||||
clues.forEachSlot((key, lo, hi) -> {
|
||||
@@ -88,15 +88,15 @@ public class MainTest {
|
||||
}
|
||||
@Test
|
||||
public void testHoriz() {
|
||||
assertTrue(Slot.horiz(1)); // Right
|
||||
assertTrue(Slot.horiz(3)); // Left
|
||||
assertFalse(Slot.horiz(0)); // Down
|
||||
assertFalse(Slot.horiz(2)); // Up
|
||||
assertTrue(Masker.Slot.horiz(1)); // Right
|
||||
assertTrue(Masker.Slot.horiz(3)); // Left
|
||||
assertFalse(Masker.Slot.horiz(0)); // Down
|
||||
assertFalse(Masker.Slot.horiz(2)); // Up
|
||||
}
|
||||
@Test
|
||||
public void testGridBasics() {
|
||||
var clues = new Clued(Clues.createEmpty());
|
||||
val key = Slot.packSlotKey(OFF_2_1, CLUE_UP);
|
||||
var clues = new Clued(Masker.Clues.createEmpty());
|
||||
val key = Masker.Slot.packSlotKey(OFF_2_1, CLUE_UP);
|
||||
clues.setClueLo(IDX_2_1.lo, CLUE_UP);
|
||||
var grid = new Gridded(clues.toGrid());
|
||||
|
||||
@@ -130,7 +130,7 @@ public class MainTest {
|
||||
}
|
||||
@Test
|
||||
public void testCluesDeepCopy() {
|
||||
var clues = new Clued(Clues.createEmpty());
|
||||
var clues = new Clued(Masker.Clues.createEmpty());
|
||||
clues.setClueLo(IDX_0_0.lo, RIGHT.dir);
|
||||
clues.setClueLo(IDX_0_1.lo, UP.dir);
|
||||
clues.setClueLo(IDX_1_0.lo, LEFT.dir);
|
||||
@@ -148,16 +148,16 @@ public class MainTest {
|
||||
@Test
|
||||
public void testMini() {
|
||||
val idx = IDX_1_1;
|
||||
var clues = Clues.createEmpty();
|
||||
var clues = Masker.Clues.createEmpty();
|
||||
clues.setClueLo(idx.lo, CLUE_LEFT);
|
||||
Assertions.assertTrue(clues.isClueLo(idx.index));
|
||||
}
|
||||
@Test
|
||||
void testMaskerCreation() {
|
||||
var swe = new SwedishGenerator(new Rng(12348), new int[STACK_SIZE], Clues.createEmpty());
|
||||
var mask = swe.generateMask(opts.clueSize, opts.pop, opts.gens, opts.offspring);
|
||||
val clued = new Clued(mask);
|
||||
val test = clued.gridToString();
|
||||
var masker = new Masker(new Rng(12348), new int[STACK_SIZE], Masker.Clues.createEmpty());
|
||||
var mask = masker.generateMask(opts.clueSize, opts.pop, opts.gens, opts.offspring);
|
||||
val clued = new Clued(mask);
|
||||
val test = clued.gridToString();
|
||||
val RESULT = "1 \n" +
|
||||
" \n" +
|
||||
" 3\n" +
|
||||
@@ -180,16 +180,18 @@ public class MainTest {
|
||||
128L,
|
||||
422762372923520L,
|
||||
192L);
|
||||
var slots = extractSlots(mask, dict.index());
|
||||
val slotInfo = scoreSlots(new int[slots.length], slots);
|
||||
var filled = fillMask(rng, slotInfo, mask.toGrid(), false);
|
||||
var slots = Masker.extractSlots(mask, dict.index());
|
||||
val slotInfo = Masker.scoreSlots(new int[slots.length], slots);
|
||||
var grid = mask.toGrid();
|
||||
var filled = fillMask(rng, slotInfo, grid, false);
|
||||
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
|
||||
Assertions.assertEquals(17, Slotinfo.wordCount(0, slotInfo), "Number of assigned words changed");
|
||||
Assertions.assertEquals("POENIGE", Lemma.asWord(slotInfo[0].assign().w));
|
||||
Assertions.assertEquals(-1L, filled.grid().grid().lo);
|
||||
Assertions.assertEquals(255L, filled.grid().grid().hi);
|
||||
filled.grid().gridToString(mask);
|
||||
var aa = new PuzzleResult(new Clued(mask), slotInfo, filled).exportFormatFromFilled(1, new Rewards(1, 1, 1));
|
||||
Assertions.assertEquals(-1L, grid.lo);
|
||||
Assertions.assertEquals(255L, grid.hi);
|
||||
var g = new Gridded(grid);
|
||||
g.gridToString(mask);
|
||||
var aa = new PuzzleResult(new Clued(mask), g, slotInfo, filled).exportFormatFromFilled(1, new Rewards(1, 1, 1));
|
||||
|
||||
}
|
||||
@Test
|
||||
@@ -205,9 +207,9 @@ public class MainTest {
|
||||
System.out.println("[DEBUG_LOG] Simplicity: " + res.filled().stats().simplicity);
|
||||
System.out.println("[DEBUG_LOG] ClueMap Size: " + Slotinfo.wordCount(0, res.slots()));
|
||||
System.out.println("[DEBUG_LOG] Grid:");
|
||||
System.out.println(res.filled().grid().renderHuman(res.clues().c()));
|
||||
System.out.println(res.filled().grid().gridToString(res.clues().c()));
|
||||
System.out.println(res.filled().grid().renderHuman(res.clues().c()));
|
||||
System.out.println(res.grid().renderHuman(res.clues().c()));
|
||||
System.out.println(res.grid().gridToString(res.clues().c()));
|
||||
System.out.println(res.grid().renderHuman(res.clues().c()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotAllLetters() {
|
||||
var grid = new Gridded(createEmpty());
|
||||
var key = Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
val clues = Clues.createEmpty();
|
||||
var key = Masker.Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
||||
val clues = Masker.Clues.createEmpty();
|
||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
||||
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));
|
||||
@@ -151,9 +151,9 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotMixed() {
|
||||
var grid = createEmpty();
|
||||
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);
|
||||
placeWord(grid, grid.g, Masker.Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
placeWord(grid, grid.g, Masker.Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_2_0, 0, Lemma.from(0, "C"));
|
||||
var key = Masker.Slot.packSlotKey(OFF_1_0, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(14081L, pattern);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotAllDashes() {
|
||||
var grid = createEmpty();
|
||||
var key = Slot.packSlotKey(1 << Slot.BIT_FOR_DIR, CLUE_RIGHT);
|
||||
var key = Masker.Slot.packSlotKey(1 << Masker.Slot.BIT_FOR_DIR, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(0L, pattern);
|
||||
}
|
||||
@@ -169,8 +169,8 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotSingleLetter() {
|
||||
var grid = createEmpty();
|
||||
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);
|
||||
placeWord(grid, grid.g, Masker.Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
var key = Masker.Slot.packSlotKey(1, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(1L, pattern);
|
||||
}
|
||||
@@ -195,8 +195,8 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testGrid() {
|
||||
var grid = new Gridded(createEmpty());
|
||||
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));
|
||||
placeWord(grid.grid(), grid.grid().g, Masker.Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
|
||||
val arr = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(1, arr.size());
|
||||
assertEquals(LETTER_A, arr.get(OFF_0_0));
|
||||
}
|
||||
@@ -231,11 +231,11 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testSlot() {
|
||||
System.out.println("[DEBUG_LOG] Slot.BIT_FOR_DIR = " + Slot.BIT_FOR_DIR);
|
||||
System.out.println("[DEBUG_LOG] Slot.BIT_FOR_DIR = " + Masker.Slot.BIT_FOR_DIR);
|
||||
// key = (r << 8) | (c << 4) | d
|
||||
var offset = OFF_2_3;
|
||||
System.out.println("[DEBUG_LOG] Grid.offset(2, 3) = " + offset);
|
||||
var key = Slot.packSlotKey(offset, CLUE_DOWN);
|
||||
var key = Masker.Slot.packSlotKey(offset, CLUE_DOWN);
|
||||
System.out.println("[DEBUG_LOG] key = " + key);
|
||||
long lo = 0;
|
||||
// pos 0: (2, 5)
|
||||
@@ -245,10 +245,10 @@ public class SwedishGeneratorTest {
|
||||
// pos 2: (4, 5)
|
||||
lo |= 1L << OFF_4_5;
|
||||
|
||||
System.out.println("[DEBUG_LOG] s.dir() = " + Slot.dir(key));
|
||||
assertEquals(OFF_2_3, Slot.clueIndex(key));
|
||||
assertEquals(CLUE_DOWN, Slot.dir(key));
|
||||
assertFalse(Slot.horiz(key));
|
||||
System.out.println("[DEBUG_LOG] s.dir() = " + Masker.Slot.dir(key));
|
||||
assertEquals(OFF_2_3, Masker.Slot.clueIndex(key));
|
||||
assertEquals(CLUE_DOWN, Masker.Slot.dir(key));
|
||||
assertFalse(Masker.Slot.horiz(key));
|
||||
var cells = Gridded.walk((byte) key, lo, 0L).toArray();
|
||||
assertEquals(2, SwedishGenerator.IT[cells[0]].r());
|
||||
assertEquals(3, SwedishGenerator.IT[cells[1]].r());
|
||||
@@ -257,8 +257,8 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(5, SwedishGenerator.IT[cells[1]].c());
|
||||
assertEquals(5, SwedishGenerator.IT[cells[2]].c());
|
||||
|
||||
assertTrue(Slot.horiz(CLUE_RIGHT)); // right
|
||||
assertFalse(Slot.horiz(CLUE_DOWN)); // down
|
||||
assertTrue(Masker.Slot.horiz(CLUE_RIGHT)); // right
|
||||
assertFalse(Masker.Slot.horiz(CLUE_DOWN)); // down
|
||||
}
|
||||
|
||||
static long packPattern(String s) {
|
||||
@@ -287,22 +287,22 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testForEachSlotAndExtractSlots() {
|
||||
// This should detect a slot starting at 0,1 with length 2 (0,1 and 0,2)
|
||||
var clues = Clues.createEmpty();
|
||||
var clues = Masker.Clues.createEmpty();
|
||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
||||
var dict = new Dict(WORDS2);
|
||||
var slots = extractSlots(clues, dict.index());
|
||||
var slots = Masker.extractSlots(clues, dict.index());
|
||||
assertEquals(1, slots.length);
|
||||
var s = slots[0];
|
||||
|
||||
assertTrue(Slot.length(s.lo(), s.hi()) >= 2);
|
||||
assertEquals(OFF_0_0, Slot.clueIndex(s.key()));
|
||||
assertEquals(CLUE_RIGHT, Slot.dir(s.key()));
|
||||
assertTrue(Masker.Slot.length(s.lo(), s.hi()) >= 2);
|
||||
assertEquals(OFF_0_0, Masker.Slot.clueIndex(s.key()));
|
||||
assertEquals(CLUE_RIGHT, Masker.Slot.dir(s.key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMaskFitnessBasic() {
|
||||
var gen = new SwedishGenerator(new Rng(0), new int[STACK_SIZE], Clues.createEmpty());
|
||||
var grid = Clues.createEmpty();
|
||||
var gen = new Masker(new Rng(0), new int[STACK_SIZE], Masker.Clues.createEmpty());
|
||||
var grid = Masker.Clues.createEmpty();
|
||||
// Empty grid should have high penalty (no slots)
|
||||
var f1 = gen.maskFitness(grid, 18);
|
||||
assertTrue(f1 >= 1_000_000_000L);
|
||||
@@ -316,7 +316,7 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testGeneticAlgorithmComponents() {
|
||||
var rng = new Rng(42);
|
||||
var gen = new SwedishGenerator(rng, new int[STACK_SIZE], Clues.createEmpty());
|
||||
var gen = new Masker(rng, new int[STACK_SIZE], Masker.Clues.createEmpty());
|
||||
|
||||
var c1 = new Clued(gen.randomMask(18));
|
||||
assertNotNull(c1);
|
||||
@@ -335,14 +335,14 @@ public class SwedishGeneratorTest {
|
||||
void testPlaceWord() {
|
||||
var grid = new Gridded(createEmpty());
|
||||
// Slot at OFF_0_0 length 3, horizontal (right)
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var key = Masker.Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_0) | (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
val hi = 0L;
|
||||
var w1 = ABC;
|
||||
|
||||
// 1. Successful placement in empty grid
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
var map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
var map = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(3, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_0));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_1));
|
||||
@@ -353,7 +353,7 @@ public class SwedishGeneratorTest {
|
||||
// 3. Conflict: place "ABD" where "ABC" is
|
||||
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));
|
||||
map = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(3, map.size());
|
||||
assertEquals(LETTER_A, map.get(OFF_0_0));
|
||||
assertEquals(LETTER_B, map.get(OFF_0_1));
|
||||
@@ -361,9 +361,9 @@ public class SwedishGeneratorTest {
|
||||
|
||||
// 4. Partial placement then conflict (rollback)
|
||||
grid = new Gridded(createEmpty());
|
||||
placeWord(grid.grid(), grid.grid().g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_2, 0, Lemma.from(0, "X")); // Conflict at the end
|
||||
placeWord(grid.grid(), grid.grid().g, Masker.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));
|
||||
map = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(LETTER_X, map.get(OFF_0_2));
|
||||
}
|
||||
@@ -372,21 +372,21 @@ public class SwedishGeneratorTest {
|
||||
void testBacktrackingHelpers() {
|
||||
var grid = new Gridded(createEmpty());
|
||||
// Slot at 0,1 length 2
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var key = Masker.Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
var w = AZ;
|
||||
val low = grid.grid().lo;
|
||||
val top = grid.grid().hi;
|
||||
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));
|
||||
var map = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::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.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
map = grid.stream(Masker.Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||
assertEquals(0, map.size());
|
||||
assertEquals(DASH, map.getOrDefault(OFF_0_1, DASH));
|
||||
assertEquals(DASH, map.getOrDefault(OFF_0_2, DASH));
|
||||
@@ -395,13 +395,13 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testInnerWorkings() {
|
||||
// 1. Test Slot.increasing
|
||||
assertFalse(Slot.increasing(CLUE_LEFT)); // Left
|
||||
assertTrue(Slot.increasing(CLUE_RIGHT)); // Right
|
||||
assertTrue(Slot.increasing(CLUE_DOWN)); // Down
|
||||
assertFalse(Slot.increasing(CLUE_UP)); // Up
|
||||
assertFalse(Slotinfo.increasing(CLUE_LEFT)); // Left
|
||||
assertTrue(Slotinfo.increasing(CLUE_RIGHT)); // Right
|
||||
assertTrue(Slotinfo.increasing(CLUE_DOWN)); // Down
|
||||
assertFalse(Slotinfo.increasing(CLUE_UP)); // Up
|
||||
|
||||
assertTrue(Slot.increasing(Slot.packSlotKey(0, CLUE_RIGHT)));
|
||||
assertFalse(Slot.increasing(Slot.packSlotKey(0, CLUE_LEFT)));
|
||||
assertTrue(Slotinfo.increasing(Masker.Slot.packSlotKey(0, CLUE_RIGHT)));
|
||||
assertFalse(Slotinfo.increasing(Masker.Slot.packSlotKey(0, CLUE_LEFT)));
|
||||
|
||||
// 2. Test slotScore
|
||||
val counts = new byte[SIZE];
|
||||
@@ -411,7 +411,7 @@ public class SwedishGeneratorTest {
|
||||
var entry5 = dict.index()[5];
|
||||
// cross = (counts[1]-1) + (counts[2]-1) = 1 + 2 = 3
|
||||
// score = 3 * 10 + len(2) = 32
|
||||
assertEquals(32, slotScore(counts, (1L << 1) | (1L << 2), 0L));
|
||||
assertEquals(32, Masker.slotScore(counts, (1L << 1) | (1L << 2), 0L));
|
||||
// 3. Test candidateCountForPattern
|
||||
|
||||
var ctx = Context.get();
|
||||
@@ -427,8 +427,8 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testMaskFitnessDetailed() {
|
||||
var gen = new SwedishGenerator(new Rng(42), new int[STACK_SIZE], Clues.createEmpty());
|
||||
var grid = Clues.createEmpty();
|
||||
var gen = new Masker(new Rng(42), new int[STACK_SIZE], Masker.Clues.createEmpty());
|
||||
var grid = Masker.Clues.createEmpty();
|
||||
// Empty grid: huge penalty
|
||||
var fitEmpty = gen.maskFitness(grid, 18);
|
||||
assertTrue(fitEmpty >= 1_000_000_000L);
|
||||
|
||||
Reference in New Issue
Block a user