redo
This commit is contained in:
@@ -5,15 +5,22 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import precomp.Neighbors9x8;
|
||||
import puzzle.SwedishGenerator.Dict;
|
||||
import puzzle.SwedishGenerator.DictEntry;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
import puzzle.dict950.DictData950;
|
||||
import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
|
||||
public final class DictJavaGeneratorMulti {
|
||||
|
||||
|
||||
@Test
|
||||
void testReversed() {
|
||||
val wOrig = DictData950.DICT950.index()[4].words()[4];
|
||||
val wRev = DictData950.DICT950.reversed()[4].words()[4];
|
||||
System.out.println(Lemma.asWord(wOrig, new byte[8]) + " " + Lemma.asWord(wRev, new byte[8]));
|
||||
}
|
||||
interface Dicts {
|
||||
|
||||
static Dict makeDict(long[] wordz) {
|
||||
@@ -52,7 +59,6 @@ public final class DictJavaGeneratorMulti {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
record DictEntryDTO(LongArrayList words, IntListDTO[][] pos) {
|
||||
|
||||
public DictEntryDTO(int L) {
|
||||
|
||||
@@ -27,8 +27,6 @@ import static puzzle.LemmaData.AZ;
|
||||
import static puzzle.SwedishGenerator.Lemma;
|
||||
import static puzzle.SwedishGenerator.Slotinfo;
|
||||
import static puzzle.SwedishGenerator.fillMask;
|
||||
import static puzzle.SwedishGeneratorTest.LETTER_A;
|
||||
import static puzzle.SwedishGeneratorTest.LETTER_Z;
|
||||
@DictGen(
|
||||
packageName = "puzzle.dict950",
|
||||
className = "DictData950",
|
||||
@@ -101,7 +99,7 @@ public class MainTest {
|
||||
public void testGridBasics() {
|
||||
var clues = Signa.of(r2c1d2);
|
||||
var grid = new Puzzle(clues);
|
||||
|
||||
r1c1.or(r0c1).lo();
|
||||
// Test set/get
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r2c1d2.slotKey, (1L << OFF_1_1) | (1L << OFF_0_1), 0, AZ);
|
||||
val map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
@@ -183,12 +181,12 @@ public class MainTest {
|
||||
);
|
||||
var slotInfo = mask.slots(DictData950.DICT950);
|
||||
var grid = Slotinfo.grid(slotInfo);
|
||||
var filled = fillMask(rng, slotInfo, grid);
|
||||
var filled = fillMask(rng, slotInfo, grid.lo,grid.hi, grid.g);
|
||||
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
|
||||
Assertions.assertEquals(17, Slotinfo.wordCount(0, slotInfo), "Number of assigned words changed");
|
||||
Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get()));
|
||||
Assertions.assertEquals(-1L, grid.lo);
|
||||
Assertions.assertEquals(-1L, grid.hi);
|
||||
Assertions.assertEquals(74732156493031040L, grid.lo);
|
||||
Assertions.assertEquals(-63L, grid.hi);
|
||||
var g = new Puzzle(grid, mask.c());
|
||||
g.gridToString();
|
||||
var aa = new PuzzleResult(mask, g, slotInfo, filled).exportFormatFromFilled(new Rewards(1, 1, 1));
|
||||
|
||||
@@ -10,7 +10,6 @@ import puzzle.Export.Rewards;
|
||||
import puzzle.Masker.Clues;
|
||||
import puzzle.SwedishGenerator.Assign;
|
||||
import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.FillStats;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
@@ -257,7 +256,7 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
void testCornerDownExtraction() {
|
||||
var slots = Masker.slots(Signa.of(r0c0d4).c(), DictData950.DICT950.index());
|
||||
var slots = Masker.slots(Signa.of(r0c0d4).c(), DictData950.DICT950);
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(r0c0d4.d, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
@@ -303,7 +302,7 @@ public class MarkerTest {
|
||||
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
||||
|
||||
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
|
||||
var fillResult = new FillResult(true, 0, 0, 0, 0);
|
||||
var puzzleResult = new PuzzleResult(clues, grid, new Slotinfo[]{
|
||||
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null, 0)
|
||||
}, fillResult);
|
||||
@@ -343,9 +342,9 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
void testExportFormatEmpty() {
|
||||
var grid = SwedishGeneratorTest.createEmpty();
|
||||
var grid = SwedishGeneratorTest.createEmpty9x8();
|
||||
val clues = Clues.createEmpty();
|
||||
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
|
||||
var fillResult = new FillResult(true, 0, 0, 0, 0);
|
||||
var puzzleResult = new PuzzleResult(new Signa(clues), new Puzzle(grid, clues), new Slotinfo[0], fillResult);
|
||||
|
||||
var exported = puzzleResult.exportFormatFromFilled(new Rewards(0, 0, 0));
|
||||
|
||||
@@ -9,6 +9,7 @@ import puzzle.Export.Clue;
|
||||
import puzzle.Export.Signa;
|
||||
import puzzle.Export.Puzzle;
|
||||
import puzzle.Masker.Clues;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
|
||||
@@ -72,8 +73,9 @@ public class PerformanceTest {
|
||||
var successCount = 0;
|
||||
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
val slotInfo = Masker.slots(arr[c], DICT800.index());
|
||||
val result = fillMask(rng, slotInfo, Slotinfo.grid(slotInfo));
|
||||
val slotInfo = Masker.slots(arr[c], DICT800);
|
||||
var grid = Slotinfo.grid(slotInfo);
|
||||
val result = fillMask(rng, slotInfo,grid.lo,grid.hi, grid.g);
|
||||
if (result.ok()) successCount++;
|
||||
totalNodes += result.nodes();
|
||||
totalBacktracks += result.backtracks();
|
||||
@@ -100,7 +102,7 @@ public class PerformanceTest {
|
||||
r6c2d1,
|
||||
r7c0d2, r7c1d2, r7c2d1, r7c7d2, r7c8d2
|
||||
);
|
||||
val allSlots = Masker.slots(mask.c(), DICT900.index());
|
||||
val allSlots = Masker.slots(mask.c(), DICT900);
|
||||
//mask.toGrid()
|
||||
System.out.println("[DEBUG_LOG] \n--- Incremental Complexity Test ---");
|
||||
System.out.println("[DEBUG_LOG] Full Slot Layout:");
|
||||
@@ -121,7 +123,7 @@ public class PerformanceTest {
|
||||
|
||||
// A single horizontal slot at (0,0)
|
||||
val mask = Signa.of(r0c0d1);
|
||||
val slots = Masker.slots(mask.c(), DICT800.index());
|
||||
val slots = Masker.slots(mask.c(), DICT800);
|
||||
|
||||
System.out.println("[DEBUG_LOG] \n--- Single Slot Resolution ---");
|
||||
if (slots.length > 0) {
|
||||
@@ -142,7 +144,8 @@ public class PerformanceTest {
|
||||
// Reset assignments for each iteration
|
||||
for (var s : slots) s.assign().w = 0;
|
||||
|
||||
val result = fillMask(rng, slots, Slotinfo.grid(slots));
|
||||
var grid = Slotinfo.grid(slots);
|
||||
val result = fillMask(rng, slots, grid.lo,grid.hi,grid.g);
|
||||
if (result.ok()) {
|
||||
successCount++;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import anno.LemmaGen;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import precomp.Neighbors9x8;
|
||||
import precomp.Neighbors9x8.rci;
|
||||
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
|
||||
import puzzle.Export.Signa;
|
||||
@@ -37,6 +38,9 @@ import static puzzle.LemmaData.INER;
|
||||
import static puzzle.LemmaData.INEREN;
|
||||
import static puzzle.LemmaData.INERENA;
|
||||
import static puzzle.LemmaData.INERENAE;
|
||||
import static puzzle.LemmaData.WORD_A;
|
||||
import static puzzle.LemmaData.WORD_C;
|
||||
import static puzzle.LemmaData.WORD_X;
|
||||
import static puzzle.SwedishGenerator.*;
|
||||
@GenerateNeighbors(@GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2))
|
||||
@LemmaGen(
|
||||
@@ -52,10 +56,7 @@ import static puzzle.SwedishGenerator.*;
|
||||
)
|
||||
public class SwedishGeneratorTest {
|
||||
|
||||
public static final long WORD_A = Lemma.from("A");
|
||||
public static final long WORD_C = Lemma.from("C");
|
||||
public static final long WORD_X = Lemma.from("X");
|
||||
static Grid createEmpty() { return new Grid(new byte[SIZE], X, X); }
|
||||
static Grid createEmpty9x8() { return new Grid(new byte[Neighbors9x8.SIZE], X, X); }
|
||||
record Context(long[] bitset) {
|
||||
|
||||
public Context() { this(new long[2500]); }
|
||||
@@ -86,26 +87,10 @@ public class SwedishGeneratorTest {
|
||||
INERENA,
|
||||
INERENAE };
|
||||
|
||||
static final byte LETTER_A = ((byte) 'A') & 31;
|
||||
static final byte LETTER_P = ((byte) 'P') & 31;
|
||||
static final byte LETTER_L = ((byte) 'L') & 31;
|
||||
static final byte LETTER_B = ((byte) 'B') & 31;
|
||||
static final byte LETTER_C = ((byte) 'C') & 31;
|
||||
static final byte LETTER_E = ((byte) 'E') & 31;
|
||||
static final byte LETTER_I = ((byte) 'I') & 31;
|
||||
static final byte LETTER_N = ((byte) 'N') & 31;
|
||||
static final byte LETTER_X = ((byte) 'X') & 31;
|
||||
static final byte LETTER_R = ((byte) 'R') & 31;
|
||||
static final byte LETTER_Z = ((byte) 'Z') & 31;
|
||||
static final byte CLUE_DOWN = 0;
|
||||
static final byte CLUE_RIGHT = 1;
|
||||
static final byte CLUE_UP = 2;
|
||||
static final byte CLUE_LEFT = 3;
|
||||
|
||||
@Test
|
||||
void testPatternForSlotAllLetters() {
|
||||
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);
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).or(r0c3).lo(), X, ABC);
|
||||
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));
|
||||
@@ -114,60 +99,32 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testPatternForSlotMixed() {
|
||||
var grid = createEmpty();
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, 1L << OFF_0_0, 0, WORD_A);
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, 1L << OFF_2_0, 0, WORD_C);
|
||||
var key = Slot.packSlotKey(OFF_1_0, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
var grid = createEmpty9x8();
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, r0c0.mask, X, WORD_A);
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, r2c0.mask, X, WORD_C);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, 7L, X);
|
||||
assertEquals(14081L, pattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPatternForSlotAllDashes() {
|
||||
var grid = createEmpty();
|
||||
var key = Slot.packSlotKey(1 << Slot.BIT_FOR_DIR, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(0L, pattern);
|
||||
var grid = createEmpty9x8();
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, 7L, X);
|
||||
assertEquals(X, pattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPatternForSlotSingleLetter() {
|
||||
var grid = createEmpty();
|
||||
//Slot.packSlotKey(0, CLUE_RIGHT)
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, 1L << OFF_0_0, 0, WORD_A);
|
||||
var key = Slot.packSlotKey(1, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
var grid = createEmpty9x8();
|
||||
GridBuilder.placeWord(grid, grid.g, r0c0d1.slotKey, r0c0.mask, X, WORD_A);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, 7L, X);
|
||||
assertEquals(1L, pattern);
|
||||
}
|
||||
@Test
|
||||
void testRng() {
|
||||
var rng = new Rng(123);
|
||||
var val1 = rng.nextU32();
|
||||
var val2 = rng.nextU32();
|
||||
assertNotEquals(val1, val2);
|
||||
|
||||
var rng2 = new Rng(123);
|
||||
assertEquals(val1, rng2.nextU32());
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var r = rng.randomClueDir();
|
||||
assertTrue(r >= 0 && r <= 5);
|
||||
var f = rng.nextFloat();
|
||||
assertTrue(f >= 0.0 && f <= 1.0);
|
||||
}
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGrid() {
|
||||
var grid = new Puzzle(Clues.createEmpty());
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, 1L << OFF_0_0, 0, WORD_A);
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0d0.mask, X, WORD_A);
|
||||
val arr = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(1, arr.size());
|
||||
assertEquals(LETTER_A, arr.get(OFF_0_0));
|
||||
@@ -210,25 +167,10 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testSlot() {
|
||||
System.out.println("[DEBUG_LOG] Slot.BIT_FOR_DIR = " + 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);
|
||||
System.out.println("[DEBUG_LOG] key = " + key);
|
||||
long lo = 0;
|
||||
// pos 0: (2, 5)
|
||||
lo |= 1L << OFF_2_5;
|
||||
// pos 1: (3, 5)
|
||||
lo |= 1L << OFF_3_5;
|
||||
// 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));
|
||||
var cells = Puzzle.cellWalk((byte) key, lo, 0L).mapToObj(i -> Masker.IT[i]).toArray(rci[]::new);
|
||||
assertEquals(OFF_2_3, Slot.clueIndex(r2c3d0.slotKey));
|
||||
assertEquals(CLUE_DOWN0, Slot.dir(r2c3d0.slotKey));
|
||||
assertFalse(Slot.horiz(r2c3d0.slotKey));
|
||||
var cells = Puzzle.cellWalk((byte) r2c3d0.slotKey, r2c5.or(r3c5).or(r4c5).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());
|
||||
@@ -236,8 +178,8 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(5, cells[1].c());
|
||||
assertEquals(5, cells[2].c());
|
||||
|
||||
assertTrue(Slot.horiz(CLUE_RIGHT)); // right
|
||||
assertFalse(Slot.horiz(CLUE_DOWN)); // down
|
||||
assertTrue(Slot.horiz(CLUE_RIGHT1)); // right
|
||||
assertFalse(Slot.horiz(CLUE_DOWN0)); // down
|
||||
}
|
||||
|
||||
static long packPattern(String s) {
|
||||
@@ -267,13 +209,13 @@ 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(Signa.of(r0c0d1).c(), dict.index());
|
||||
var slots = Masker.extractSlots(Signa.of(r0c0d1).c(), dict.index(), dict.reversed());
|
||||
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()));
|
||||
assertEquals(CLUE_RIGHT1, Slot.dir(s.key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,33 +234,20 @@ public class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testGeneticAlgorithmComponents() {
|
||||
var rng = new Rng(42);
|
||||
var gen = new Masker(rng, new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
|
||||
|
||||
var c1 = new Signa(gen.randomMask(18));
|
||||
var gen = new Masker(new Rng(42), new int[Masker.STACK_SIZE], Masker.Clues.createEmpty());
|
||||
var c1 = new Signa(gen.randomMask(18));
|
||||
assertNotNull(c1);
|
||||
|
||||
var g2 = new Signa(gen.mutate(c1.deepCopyGrid().c()));
|
||||
assertNotNull(g2);
|
||||
assertNotSame(c1.c(), g2.c());
|
||||
|
||||
assertNotNull(gen.crossover(c1.c(), g2.c()));
|
||||
|
||||
var g4 = gen.hillclimb(c1.c(), 18, 10);
|
||||
assertNotNull(g4);
|
||||
assertNotNull(gen.hillclimb(c1.c(), 18, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPlaceWord() {
|
||||
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);
|
||||
val hi = 0L;
|
||||
var w1 = ABC;
|
||||
|
||||
// 1. Successful placement in empty grid
|
||||
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC));
|
||||
|
||||
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(3, map.size());
|
||||
@@ -327,9 +256,9 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(LETTER_C, map.get(OFF_0_2));
|
||||
|
||||
// 2. Successful placement with partial overlap (same characters)
|
||||
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, w1));
|
||||
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC));
|
||||
// 3. Conflict: place "ABD" where "ABC" is
|
||||
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, hi, ABD));
|
||||
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABD));
|
||||
// Verify grid is unchanged (still "ABC")
|
||||
map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(3, map.size());
|
||||
@@ -339,8 +268,8 @@ public class SwedishGeneratorTest {
|
||||
|
||||
// 4. Partial placement then conflict (rollback)
|
||||
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));
|
||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, 1L << OFF_0_2, 0, WORD_X); // Conflict at the end
|
||||
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC));
|
||||
map = grid.stream().collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(LETTER_X, map.get(OFF_0_2));
|
||||
@@ -350,12 +279,9 @@ public class SwedishGeneratorTest {
|
||||
void testBacktrackingHelpers() {
|
||||
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);
|
||||
var w = AZ;
|
||||
val low = grid.grid().lo;
|
||||
val top = grid.grid().hi;
|
||||
var placed = GridBuilder.placeWord(grid.grid(), grid.grid().g, key, lo, 0L, w);
|
||||
var placed = GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).lo(), X, AZ);
|
||||
assertTrue(placed);
|
||||
|
||||
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter));
|
||||
@@ -374,16 +300,16 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testInnerWorkings() {
|
||||
// 1. Test Slot.increasing
|
||||
assertFalse(Slotinfo.increasing(CLUE_LEFT)); // Left
|
||||
assertTrue(Slotinfo.increasing(CLUE_RIGHT)); // Right
|
||||
assertTrue(Slotinfo.increasing(CLUE_DOWN)); // Down
|
||||
assertFalse(Slotinfo.increasing(CLUE_UP)); // Up
|
||||
assertFalse(Slotinfo.increasing(CLUE_LEFT3)); // Left
|
||||
assertTrue(Slotinfo.increasing(CLUE_RIGHT1)); // Right
|
||||
assertTrue(Slotinfo.increasing(CLUE_DOWN0)); // Down
|
||||
assertFalse(Slotinfo.increasing(CLUE_UP2)); // Up
|
||||
|
||||
assertTrue(Slotinfo.increasing(Slot.packSlotKey(0, CLUE_RIGHT)));
|
||||
assertFalse(Slotinfo.increasing(Slot.packSlotKey(0, CLUE_LEFT)));
|
||||
assertTrue(Slotinfo.increasing(r0c0d1.slotKey));
|
||||
assertFalse(Slotinfo.increasing(r0c0d3.slotKey));
|
||||
|
||||
// 2. Test slotScore
|
||||
val counts = new byte[SIZE];
|
||||
val counts = new byte[Neighbors9x8.SIZE];
|
||||
counts[1] = 2;
|
||||
counts[2] = 3;
|
||||
var dict = DictJavaGeneratorMulti.Dicts.makeDict(WORDS);
|
||||
@@ -415,4 +341,29 @@ public class SwedishGeneratorTest {
|
||||
var fitOne = gen.maskFitness(grid, 18);
|
||||
assertTrue(fitOne < fitEmpty);
|
||||
}
|
||||
@Test
|
||||
void testRng() {
|
||||
var rng = new Rng(123);
|
||||
var val1 = rng.nextU32();
|
||||
var val2 = rng.nextU32();
|
||||
assertNotEquals(val1, val2);
|
||||
|
||||
var rng2 = new Rng(123);
|
||||
assertEquals(val1, rng2.nextU32());
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var r = rng.randomClueDir();
|
||||
assertTrue(r >= 0 && r <= 5);
|
||||
var f = rng.nextFloat();
|
||||
assertTrue(f >= 0.0 && f <= 1.0);
|
||||
}
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
assertTrue(rng.biasedIndexPow3(100) >= 0 && rng.biasedIndexPow3(100) < 100);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user