introduce bitloops
This commit is contained in:
@@ -648,6 +648,12 @@ public final class Masker {
|
|||||||
long lo, hi, vlo, vhi, rlo, rhi, xlo, xhi;
|
long lo, hi, vlo, vhi, rlo, rhi, xlo, xhi;
|
||||||
public static Clues createEmpty() { return new Clues(0, 0, 0, 0, 0, 0, 0, 0); }
|
public static Clues createEmpty() { return new Clues(0, 0, 0, 0, 0, 0, 0, 0); }
|
||||||
|
|
||||||
|
public static Clues of(precomp.Const9x8.Cell... cells) {
|
||||||
|
var c = createEmpty();
|
||||||
|
for (var cell : cells) c.setClue(cell);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasRoomForClue(int key) {
|
public boolean hasRoomForClue(int key) {
|
||||||
if (Slotinfo.increasing(key)) if (!validSlot(lo, hi, key)) return false;
|
if (Slotinfo.increasing(key)) if (!validSlot(lo, hi, key)) return false;
|
||||||
return validSlotRev(lo, hi, key);
|
return validSlotRev(lo, hi, key);
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ public class CornerClueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCornerDownSlot() {
|
void testCornerDownSlot() {
|
||||||
|
var clues = Clues.of(r0c0d4);
|
||||||
var clues = Clues.createEmpty().setClue(r0c0d4);
|
|
||||||
// Clue op (0,0), type 4 (Corner Down)
|
// Clue op (0,0), type 4 (Corner Down)
|
||||||
|
|
||||||
assertEquals(r0c0d4.d, clues.getDir(r0c0d4.index));
|
assertEquals(r0c0d4.d, clues.getDir(r0c0d4.index));
|
||||||
@@ -39,14 +38,14 @@ public class CornerClueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCornerDownExtraction() {
|
void testCornerDownExtraction() {
|
||||||
var slots = Masker.slots(Clues.createEmpty().setClue(r0c0d4), DictData.DICT.index());
|
var slots = Masker.slots(Clues.of(r0c0d4), DictData.DICT.index());
|
||||||
assertEquals(1, slots.length);
|
assertEquals(1, slots.length);
|
||||||
assertEquals(r0c0d4.d, Masker.Slot.dir(slots[0].key()));
|
assertEquals(r0c0d4.d, Masker.Slot.dir(slots[0].key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCornerDownLeftSlot() {
|
void testCornerDownLeftSlot() {
|
||||||
var clues = Clues.createEmpty().setClue(r0c1d5);
|
var clues = Clues.of(r0c1d5);
|
||||||
|
|
||||||
assertEquals(r0c1d5.d, clues.getDir(r0c1d5.index));
|
assertEquals(r0c1d5.d, clues.getDir(r0c1d5.index));
|
||||||
|
|
||||||
@@ -69,7 +68,7 @@ public class CornerClueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCornerDownLeftExtraction() {
|
void testCornerDownLeftExtraction() {
|
||||||
var slots = Masker.slots(Clues.createEmpty().setClue(r0c1d5), DictData.DICT.index());
|
var slots = Masker.slots(Clues.of(r0c1d5), DictData.DICT.index());
|
||||||
|
|
||||||
assertEquals(1, slots.length);
|
assertEquals(1, slots.length);
|
||||||
assertEquals(r0c1d5.d, Masker.Slot.dir(slots[0].key()));
|
assertEquals(r0c1d5.d, Masker.Slot.dir(slots[0].key()));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package puzzle;
|
package puzzle;
|
||||||
|
|
||||||
import module java.base;
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import puzzle.Export.Clued;
|
import puzzle.Export.Clued;
|
||||||
@@ -12,38 +11,31 @@ import puzzle.SwedishGenerator.Assign;
|
|||||||
import puzzle.SwedishGenerator.FillResult;
|
import puzzle.SwedishGenerator.FillResult;
|
||||||
import puzzle.SwedishGenerator.Lemma;
|
import puzzle.SwedishGenerator.Lemma;
|
||||||
import puzzle.SwedishGenerator.Slotinfo;
|
import puzzle.SwedishGenerator.Slotinfo;
|
||||||
import puzzle.SwedishGeneratorTest.Idx;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static precomp.Const9x8.Cell.r0c0d1;
|
||||||
|
import static precomp.Const9x8.Cell.r0c5d3;
|
||||||
import static precomp.Const9x8.OFF_0_1;
|
import static precomp.Const9x8.OFF_0_1;
|
||||||
import static precomp.Const9x8.OFF_0_2;
|
import static precomp.Const9x8.OFF_0_2;
|
||||||
import static precomp.Const9x8.OFF_0_3;
|
import static precomp.Const9x8.OFF_0_3;
|
||||||
import static precomp.Const9x8.OFF_0_4;
|
import static precomp.Const9x8.OFF_0_4;
|
||||||
import static puzzle.Export.Clue.LEFT3;
|
import static puzzle.GridBuilder.placeWord;
|
||||||
import static puzzle.Export.Clue.RIGHT1;
|
|
||||||
import static puzzle.SwedishGenerator.C;
|
|
||||||
import static puzzle.Masker.Clues;
|
import static puzzle.Masker.Clues;
|
||||||
|
import static puzzle.SwedishGenerator.C;
|
||||||
import static puzzle.SwedishGenerator.FillStats;
|
import static puzzle.SwedishGenerator.FillStats;
|
||||||
import static puzzle.SwedishGenerator.R;
|
import static puzzle.SwedishGenerator.R;
|
||||||
import static puzzle.Masker.Slot;
|
|
||||||
import static puzzle.GridBuilder.placeWord;
|
|
||||||
import static puzzle.SwedishGeneratorTest.TEST;
|
import static puzzle.SwedishGeneratorTest.TEST;
|
||||||
|
|
||||||
public class ExportFormatTest {
|
public class ExportFormatTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExportFormatFromFilled() {
|
void testExportFormatFromFilled() {
|
||||||
val clues = Clues.createEmpty();
|
val clues = Clues.of(r0c0d1, r0c5d3);
|
||||||
// Place a RIGHT clue at (0,0)
|
|
||||||
clues.setClueLo(Idx.IDX_0_0.lo, RIGHT1.dir);
|
|
||||||
// This creates a slot starting at (0,1)
|
|
||||||
// Terminate the slot at (0,5) with another digit to avoid it extending to MAX_WORD_LENGTH
|
|
||||||
clues.setClueLo(Idx.IDX_0_5.lo, LEFT3.dir);
|
|
||||||
var grid = new Gridded(clues);
|
var grid = new Gridded(clues);
|
||||||
|
|
||||||
// key = (cellIndex << 2) | (direction)
|
// key = (cellIndex << 2) | (direction)
|
||||||
var key = Slot.packSlotKey(0, RIGHT1.dir);
|
var key = r0c0d1.slotKey;
|
||||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4);
|
var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4);
|
||||||
|
|
||||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
||||||
|
|||||||
@@ -17,17 +17,10 @@ import puzzle.SwedishGenerator.Rng;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static precomp.Const9x8.OFF_0_0;
|
import static precomp.Const9x8.*;
|
||||||
import static precomp.Const9x8.OFF_0_1;
|
import static precomp.Const9x8.Cell.*;
|
||||||
import static precomp.Const9x8.OFF_0_2;
|
import static puzzle.Export.Clue.*;
|
||||||
import static precomp.Const9x8.OFF_1_1;
|
import static puzzle.Masker.Clues;
|
||||||
import static precomp.Const9x8.OFF_1_2;
|
|
||||||
import static precomp.Const9x8.OFF_2_1;
|
|
||||||
import static precomp.Const9x8.OFF_2_3;
|
|
||||||
import static puzzle.Export.Clue.DOWN0;
|
|
||||||
import static puzzle.Export.Clue.LEFT3;
|
|
||||||
import static puzzle.Export.Clue.RIGHT1;
|
|
||||||
import static puzzle.Export.Clue.UP2;
|
|
||||||
import static puzzle.SwedishGenerator.Lemma;
|
import static puzzle.SwedishGenerator.Lemma;
|
||||||
import static puzzle.SwedishGenerator.Slotinfo;
|
import static puzzle.SwedishGenerator.Slotinfo;
|
||||||
import static puzzle.SwedishGenerator.fillMask;
|
import static puzzle.SwedishGenerator.fillMask;
|
||||||
@@ -36,11 +29,6 @@ import static puzzle.SwedishGeneratorTest.AZ;
|
|||||||
import static puzzle.SwedishGeneratorTest.CLUE_LEFT;
|
import static puzzle.SwedishGeneratorTest.CLUE_LEFT;
|
||||||
import static puzzle.SwedishGeneratorTest.CLUE_RIGHT;
|
import static puzzle.SwedishGeneratorTest.CLUE_RIGHT;
|
||||||
import static puzzle.SwedishGeneratorTest.CLUE_UP;
|
import static puzzle.SwedishGeneratorTest.CLUE_UP;
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_0_0;
|
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_0_1;
|
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_1_0;
|
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_1_1;
|
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_2_1;
|
|
||||||
import static puzzle.SwedishGeneratorTest.LETTER_A;
|
import static puzzle.SwedishGeneratorTest.LETTER_A;
|
||||||
import static puzzle.SwedishGeneratorTest.LETTER_Z;
|
import static puzzle.SwedishGeneratorTest.LETTER_Z;
|
||||||
|
|
||||||
@@ -59,10 +47,8 @@ public class MainTest {
|
|||||||
}};
|
}};
|
||||||
@Test
|
@Test
|
||||||
void testExtractSlots() {
|
void testExtractSlots() {
|
||||||
|
var clues = Clues.of(r0c0d1);
|
||||||
var clues = Masker.Clues.createEmpty();
|
val key = r0c0d1.slotKey;
|
||||||
val key = Masker.Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
|
||||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
|
||||||
var grid = new Gridded(clues);
|
var grid = new Gridded(clues);
|
||||||
val g = grid.grid().g;
|
val g = grid.grid().g;
|
||||||
GridBuilder.placeWord(grid.grid(), g, key, (1L << OFF_0_1) | (1L << OFF_0_2), 0, AB);
|
GridBuilder.placeWord(grid.grid(), g, key, (1L << OFF_0_1) | (1L << OFF_0_2), 0, AB);
|
||||||
@@ -89,8 +75,7 @@ public class MainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testForEachSlot() {
|
void testForEachSlot() {
|
||||||
var clues = Masker.Clues.createEmpty();
|
var clues = Clues.of(r0c0d1);
|
||||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
|
||||||
var count = new AtomicInteger(0);
|
var count = new AtomicInteger(0);
|
||||||
clues.forEachSlot((key, lo, hi) -> {
|
clues.forEachSlot((key, lo, hi) -> {
|
||||||
count.incrementAndGet();
|
count.incrementAndGet();
|
||||||
@@ -111,9 +96,8 @@ public class MainTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testGridBasics() {
|
public void testGridBasics() {
|
||||||
var clues = new Clued(Masker.Clues.createEmpty());
|
var clues = new Clued(Clues.of(r2c1d2));
|
||||||
val key = Masker.Slot.packSlotKey(OFF_2_1, CLUE_UP);
|
val key = r2c1d2.slotKey;
|
||||||
clues.setClueLo(IDX_2_1.lo, CLUE_UP);
|
|
||||||
var grid = new Gridded(clues.c());
|
var grid = new Gridded(clues.c());
|
||||||
|
|
||||||
// Test set/get
|
// Test set/get
|
||||||
@@ -123,7 +107,7 @@ public class MainTest {
|
|||||||
Assertions.assertEquals(LETTER_Z, map.get(OFF_0_1));
|
Assertions.assertEquals(LETTER_Z, map.get(OFF_0_1));
|
||||||
var clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
var clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
||||||
Assertions.assertEquals(1, clueMap.size());
|
Assertions.assertEquals(1, clueMap.size());
|
||||||
Assertions.assertEquals(CLUE_UP, clueMap.get(OFF_2_1));
|
Assertions.assertEquals(UP2.dir, clueMap.get(OFF_2_1));
|
||||||
|
|
||||||
// Test isLetterAt
|
// Test isLetterAt
|
||||||
Assertions.assertFalse(clueMap.containsKey(OFF_0_0));
|
Assertions.assertFalse(clueMap.containsKey(OFF_0_0));
|
||||||
@@ -135,7 +119,7 @@ public class MainTest {
|
|||||||
Assertions.assertFalse(clues.isClueLo(OFF_0_0));
|
Assertions.assertFalse(clues.isClueLo(OFF_0_0));
|
||||||
Assertions.assertTrue(clues.isClueLo(OFF_2_1));
|
Assertions.assertTrue(clues.isClueLo(OFF_2_1));
|
||||||
clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
||||||
Assertions.assertEquals(CLUE_UP, clueMap.get(OFF_2_1));
|
Assertions.assertEquals(UP2.dir, clueMap.get(OFF_2_1));
|
||||||
Assertions.assertFalse(clues.isClueLo(OFF_2_3));
|
Assertions.assertFalse(clues.isClueLo(OFF_2_3));
|
||||||
Assertions.assertFalse(clues.isClueLo(OFF_1_1));
|
Assertions.assertFalse(clues.isClueLo(OFF_1_1));
|
||||||
|
|
||||||
@@ -146,27 +130,21 @@ public class MainTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testCluesDeepCopy() {
|
public void testCluesDeepCopy() {
|
||||||
var clues = new Clued(Masker.Clues.createEmpty());
|
var clues = new Clued(Clues.of(r0c0d1, r0c1d2, r1c0d3, r1c1d0));
|
||||||
clues.setClueLo(IDX_0_0.lo, RIGHT1.dir);
|
|
||||||
clues.setClueLo(IDX_0_1.lo, UP2.dir);
|
|
||||||
clues.setClueLo(IDX_1_0.lo, LEFT3.dir);
|
|
||||||
clues.setClueLo(IDX_1_1.lo, DOWN0.dir);
|
|
||||||
|
|
||||||
var copy = clues.deepCopyGrid();
|
var copy = clues.deepCopyGrid();
|
||||||
var clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
var clueMap = clues.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
||||||
Assertions.assertEquals(CLUE_RIGHT, clueMap.get(OFF_0_0));
|
Assertions.assertEquals(RIGHT1.dir, clueMap.get(OFF_0_0));
|
||||||
|
|
||||||
copy.setClueLo(IDX_0_0.lo, DOWN0.dir);
|
copy.setClue(r0c0d0);
|
||||||
var copied = copy.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
var copied = copy.stream().collect(Collectors.toMap(ClueAt::index, ClueAt::clue));
|
||||||
Assertions.assertEquals(DOWN0.dir, copied.get(OFF_0_0));
|
Assertions.assertEquals(DOWN0.dir, copied.get(OFF_0_0));
|
||||||
Assertions.assertEquals(RIGHT1.dir, clueMap.get(OFF_0_0));
|
Assertions.assertEquals(RIGHT1.dir, clueMap.get(OFF_0_0));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testMini() {
|
public void testMini() {
|
||||||
val idx = IDX_1_1;
|
var clues = Clues.of(r1c1d3);
|
||||||
var clues = Masker.Clues.createEmpty();
|
Assertions.assertTrue(clues.isClueLo(OFF_1_1));
|
||||||
clues.setClueLo(idx.lo, CLUE_LEFT);
|
|
||||||
Assertions.assertTrue(clues.isClueLo(idx.index));
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void testFiller2() {
|
void testFiller2() {
|
||||||
|
|||||||
@@ -66,14 +66,14 @@ public class MaskerCluesTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void testSimilarity() {
|
void testSimilarity() {
|
||||||
Clues a = Clued.create(r0c0d1, r2c1d0);
|
Clues a = Clues.of(r0c0d1, r2c1d0);
|
||||||
Clues b = Clues.createEmpty().setClue(r0c0d1).setClue(r2c1d0);
|
Clues b = Clues.of(r0c0d1, r2c1d0);
|
||||||
|
|
||||||
// Identity
|
// Identity
|
||||||
assertEquals(1.0, a.similarity(b), 0.001);
|
assertEquals(1.0, a.similarity(b), 0.001);
|
||||||
|
|
||||||
// Different direction
|
// Different direction
|
||||||
Clues c = Clues.createEmpty().setClue(r0c0d0).setClue(r2c1d0);
|
Clues c = Clues.of(r0c0d0, r2c1d0);
|
||||||
assertTrue(a.similarity(c) < 1.0);
|
assertTrue(a.similarity(c) < 1.0);
|
||||||
|
|
||||||
// Completely different
|
// Completely different
|
||||||
@@ -86,16 +86,13 @@ public class MaskerCluesTest {
|
|||||||
@Test
|
@Test
|
||||||
void testIsValid() {
|
void testIsValid() {
|
||||||
Masker masker = new Masker(new Rng(42), new int[STACK_SIZE], Clues.createEmpty());
|
Masker masker = new Masker(new Rng(42), new int[STACK_SIZE], Clues.createEmpty());
|
||||||
Clues g = Clues.createEmpty();
|
assertTrue(masker.isValid(Clues.createEmpty()));
|
||||||
assertTrue(masker.isValid(g));
|
|
||||||
|
|
||||||
// Valid clue: Right from (0,0) in 9x8 grid. Length is 8.
|
// Valid clue: Right from (0,0) in 9x8 grid. Length is 8.
|
||||||
g.setClue(r0c0d1);
|
assertTrue(masker.isValid(Clues.of(r0c0d1)));
|
||||||
assertTrue(masker.isValid(g));
|
|
||||||
|
|
||||||
// Invalid clue: Right from (0,7) in 9x8 grid. Length is 1 (too short if MIN_LEN >= 2).
|
// Invalid clue: Right from (0,7) in 9x8 grid. Length is 1 (too short if MIN_LEN >= 2).
|
||||||
Clues g2 = Clues.createEmpty().setClue(r0c7d1);
|
assertFalse(masker.isValid(Clues.of(r0c7d1)));
|
||||||
assertFalse(masker.isValid(g2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,26 +122,20 @@ public class MaskerCluesTest {
|
|||||||
void testIntersectionConstraint() {
|
void testIntersectionConstraint() {
|
||||||
Masker masker = new Masker(new Rng(42), new int[STACK_SIZE], Clues.createEmpty());
|
Masker masker = new Masker(new Rng(42), new int[STACK_SIZE], Clues.createEmpty());
|
||||||
// Clue 1: (0,0) Right. Slot cells: (0,1), (0,2), (0,3), (0,4), (0,5), (0,6), (0,7), (0,8)
|
// Clue 1: (0,0) Right. Slot cells: (0,1), (0,2), (0,3), (0,4), (0,5), (0,6), (0,7), (0,8)
|
||||||
Clues g = Clues.createEmpty().setClue(r0c0d1);
|
|
||||||
|
|
||||||
// Clue 2: (1,2) Up. Slot cells: (0,2)
|
// Clue 2: (1,2) Up. Slot cells: (0,2)
|
||||||
// Intersection is exactly 1 cell (0,2). Valid.
|
// Intersection is exactly 1 cell (0,2). Valid.
|
||||||
g.setClue(r2c2d2);
|
assertTrue(masker.isValid(Clues.of(r0c0d1, r2c2d2)));
|
||||||
assertTrue(masker.isValid(g));
|
|
||||||
|
|
||||||
// Clue 3: (1,1) Right. Slot cells: (1,2), (1,3), ...
|
// Clue 3: (1,1) Right. Slot cells: (1,2), (1,3), ...
|
||||||
// No intersection with Clue 1 or 2. Valid.
|
// No intersection with Clue 1 or 2. Valid.
|
||||||
g.setClue(r1c1d1);
|
assertTrue(masker.isValid(Clues.of(r0c0d1, r2c2d2, r1c1d1)));
|
||||||
assertTrue(masker.isValid(g));
|
|
||||||
|
|
||||||
// Now create a violation: two slots sharing 2 cells.
|
// Now create a violation: two slots sharing 2 cells.
|
||||||
// We can do this with Corner Down and another clue.
|
// We can do this with Corner Down and another clue.
|
||||||
// Clue A: (0,0) Corner Down. Starts at (0,1) goes down: (0,1), (1,1), (2,1), (3,1), ...
|
// Clue A: (0,0) Corner Down. Starts at (0,1) goes down: (0,1), (1,1), (2,1), (3,1), ...
|
||||||
// Clue B: (0,2) Corner Down Left. Starts at (0,1) goes down: (0,1), (1,1), (2,1), ...
|
// Clue B: (0,2) Corner Down Left. Starts at (0,1) goes down: (0,1), (1,1), (2,1), ...
|
||||||
// They share MANY cells starting from (0,1).
|
// They share MANY cells starting from (0,1).
|
||||||
|
assertFalse(masker.isValid(Clues.of(r0c0d4, r0c2d5)));
|
||||||
Clues g3 = Clues.createEmpty().setClue(r0c0d4).setClue(r0c2d5);
|
|
||||||
assertFalse(masker.isValid(g3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ import puzzle.Masker.Slot;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static precomp.Const9x8.*;
|
import static precomp.Const9x8.*;
|
||||||
import static precomp.Const9x8.Cell.r0c0d1;
|
import static precomp.Const9x8.Cell.*;
|
||||||
import static puzzle.SwedishGenerator.*;
|
import static puzzle.SwedishGenerator.*;
|
||||||
import static puzzle.SwedishGeneratorTest.Idx.IDX_0_0;
|
|
||||||
|
|
||||||
public class SwedishGeneratorTest {
|
public class SwedishGeneratorTest {
|
||||||
|
|
||||||
@@ -80,52 +79,11 @@ public class SwedishGeneratorTest {
|
|||||||
|
|
||||||
static final byte D_BYTE_2 = CLUE_RIGHT;
|
static final byte D_BYTE_2 = CLUE_RIGHT;
|
||||||
|
|
||||||
enum Idx {
|
|
||||||
IDX_0_0(OFF_0_0, 0, 0),
|
|
||||||
IDX_0_1(OFF_0_1, 0, 1),
|
|
||||||
IDX_0_2(OFF_0_2, 0, 2),
|
|
||||||
IDX_0_3(OFF_0_3, 0, 3),
|
|
||||||
IDX_0_4(OFF_0_4, 0, 4),
|
|
||||||
IDX_0_5(OFF_0_5, 0, 5),
|
|
||||||
IDX_1_0(OFF_1_0, 1, 0),
|
|
||||||
IDX_1_1(OFF_1_1, 1, 1),
|
|
||||||
IDX_1_2(OFF_1_2, 1, 2),
|
|
||||||
IDX_1_3(OFF_1_3, 1, 3),
|
|
||||||
IDX_1_4(OFF_1_4, 1, 4),
|
|
||||||
IDX_1_5(OFF_1_5, 1, 5),
|
|
||||||
IDX_2_0(OFF_2_0, 2, 0),
|
|
||||||
IDX_2_1(OFF_2_1, 2, 1),
|
|
||||||
IDX_2_2(OFF_2_2, 2, 2),
|
|
||||||
IDX_2_3(OFF_2_3, 2, 3),
|
|
||||||
IDX_2_4(OFF_2_4, 2, 4),
|
|
||||||
IDX_2_5(OFF_2_5, 2, 5),
|
|
||||||
IDX_3_0(OFF_3_0, 3, 0),
|
|
||||||
IDX_3_1(OFF_3_1, 3, 1),
|
|
||||||
IDX_3_2(OFF_3_2, 3, 2),
|
|
||||||
IDX_3_3(OFF_3_3, 3, 3),
|
|
||||||
IDX_3_4(OFF_3_4, 3, 4),
|
|
||||||
IDX_3_5(OFF_3_5, 3, 5);
|
|
||||||
Idx(int idx, int r, int c) {
|
|
||||||
this.index = idx;
|
|
||||||
this.r = r;
|
|
||||||
this.c = c;
|
|
||||||
if (isLo(idx)) {
|
|
||||||
this.lo = 1L << idx;
|
|
||||||
this.hi = 0L;
|
|
||||||
} else {
|
|
||||||
this.lo = 0L;
|
|
||||||
this.hi = 1L << (idx & 63);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final int index, r, c;
|
|
||||||
final long lo, hi;
|
|
||||||
}
|
|
||||||
@Test
|
@Test
|
||||||
void testPatternForSlotAllLetters() {
|
void testPatternForSlotAllLetters() {
|
||||||
var key = Slot.packSlotKey(OFF_0_0, CLUE_RIGHT);
|
var key = r0c0d1.slotKey;
|
||||||
val clues = Masker.Clues.createEmpty();
|
val clues = Clues.of(r0c0d1);
|
||||||
var grid = new Gridded(clues);
|
var grid = new Gridded(clues);
|
||||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
|
||||||
GridBuilder.placeWord(grid.grid(), grid.grid().g, key, (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3), 0L, ABC);
|
GridBuilder.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));
|
val map = grid.stream(clues).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
|
||||||
assertEquals(LETTER_A, map.get(OFF_0_1));
|
assertEquals(LETTER_A, map.get(OFF_0_1));
|
||||||
@@ -288,8 +246,7 @@ public class SwedishGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
void testForEachSlotAndExtractSlots() {
|
void testForEachSlotAndExtractSlots() {
|
||||||
// This should detect a slot starting at 0,1 with length 2 (0,1 and 0,2)
|
// This should detect a slot starting at 0,1 with length 2 (0,1 and 0,2)
|
||||||
var clues = Masker.Clues.createEmpty();
|
var clues = Clues.of(r0c0d1);
|
||||||
clues.setClueLo(IDX_0_0.lo, CLUE_RIGHT);
|
|
||||||
var dict = DictJavaGeneratorMulti.Dicts.makeDict(WORDS2);
|
var dict = DictJavaGeneratorMulti.Dicts.makeDict(WORDS2);
|
||||||
var slots = Masker.extractSlots(clues, dict.index());
|
var slots = Masker.extractSlots(clues, dict.index());
|
||||||
assertEquals(1, slots.length);
|
assertEquals(1, slots.length);
|
||||||
@@ -309,7 +266,7 @@ public class SwedishGeneratorTest {
|
|||||||
assertTrue(f1 >= 1_000_000_000L);
|
assertTrue(f1 >= 1_000_000_000L);
|
||||||
|
|
||||||
// Add a slot
|
// Add a slot
|
||||||
grid.setClueLo(IDX_0_0.lo, D_BYTE_2);
|
grid.setClue(r0c0d1);
|
||||||
var f2 = gen.maskFitness(grid, 18);
|
var f2 = gen.maskFitness(grid, 18);
|
||||||
assertTrue(f2 < f1);
|
assertTrue(f2 < f1);
|
||||||
}
|
}
|
||||||
@@ -437,7 +394,7 @@ public class SwedishGeneratorTest {
|
|||||||
// Empty grid: huge penalty
|
// Empty grid: huge penalty
|
||||||
var fitEmpty = gen.maskFitness(grid, 18);
|
var fitEmpty = gen.maskFitness(grid, 18);
|
||||||
assertTrue(fitEmpty >= 1_000_000_000L);
|
assertTrue(fitEmpty >= 1_000_000_000L);
|
||||||
grid.setClueLo(IDX_0_0.lo, D_BYTE_2); // Right from 0,0. Len 2 if 3x3.
|
grid.setClue(r0c0d1); // Right from 0,0. Len 2 if 3x3.
|
||||||
var fitOne = gen.maskFitness(grid, 18);
|
var fitOne = gen.maskFitness(grid, 18);
|
||||||
assertTrue(fitOne < fitEmpty);
|
assertTrue(fitOne < fitEmpty);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user