Gather data
This commit is contained in:
@@ -502,7 +502,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
return penalty;
|
||||
}
|
||||
|
||||
SwedishGenerator.Grid randomMask(SwedishGenerator.Rng rng) {
|
||||
Grid randomMask(Rng rng) {
|
||||
var g = makeEmptyGrid();
|
||||
int placed = 0, guard = 0;
|
||||
|
||||
@@ -683,7 +683,6 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
// ---------------- Fill (CSP) ----------------
|
||||
|
||||
@Data
|
||||
public static final class FillStats {
|
||||
|
||||
public long nodes;
|
||||
@@ -692,11 +691,11 @@ public record SwedishGenerator(int[] buff) {
|
||||
public int lastMRV;
|
||||
}
|
||||
|
||||
record Pick(SwedishGenerator.Slot slot, SwedishGenerator.CandidateInfo info, boolean done) { }
|
||||
record Pick(Slot slot, CandidateInfo info, boolean done) { }
|
||||
|
||||
public static record FillResult(boolean ok,
|
||||
Gridded grid,
|
||||
HashMap<Integer, SwedishGenerator.Lemma> clueMap,
|
||||
HashMap<Integer, Lemma> clueMap,
|
||||
FillStats stats,
|
||||
double simplicity) {
|
||||
|
||||
@@ -744,7 +743,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public FillResult fillMask(Rng rng, Grid mask, SwedishGenerator.DictEntry[] dictIndex,
|
||||
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
|
||||
int logEveryMs, int timeLimitMs, boolean verbose) {
|
||||
boolean multiThreaded = Thread.currentThread().getName().contains("pool");
|
||||
var grid = mask.deepCopyGrid();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static puzzle.SwedishGenerator.*;
|
||||
import static puzzle.SwedishGenerator.DASH;
|
||||
|
||||
public class MainTest {
|
||||
@@ -23,7 +24,7 @@ public class MainTest {
|
||||
@Test
|
||||
void testExtractSlots() {
|
||||
var generator = new SwedishGenerator();
|
||||
var grid = SwedishGenerator.makeEmptyGrid();
|
||||
var grid = makeEmptyGrid();
|
||||
|
||||
// Set up digits on the grid to create slots.
|
||||
// '2' (right) at (0,0) -> slot at (0,1), (0,2)
|
||||
@@ -35,19 +36,19 @@ public class MainTest {
|
||||
assertEquals(1, slots.size());
|
||||
var s = slots.get(0);
|
||||
assertEquals(8, s.len());
|
||||
assertEquals(0, SwedishGenerator.Grid.r(s.pos(0)));
|
||||
assertEquals(1, SwedishGenerator.Grid.c(s.pos(0)));
|
||||
assertEquals(0, SwedishGenerator.Grid.r(s.pos(1)));
|
||||
assertEquals(2, SwedishGenerator.Grid.c(s.pos(1)));
|
||||
assertEquals(0, Grid.r(s.pos(0)));
|
||||
assertEquals(1, Grid.c(s.pos(0)));
|
||||
assertEquals(0, Grid.r(s.pos(1)));
|
||||
assertEquals(2, Grid.c(s.pos(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStaticSlotMethods() {
|
||||
// Test static offset extraction
|
||||
// packedPos: offset(1, 1) at index 0, offset(2, 2) at index 1
|
||||
var packedPos = ((long) SwedishGenerator.Grid.offset(1, 1)) | (((long) SwedishGenerator.Grid.offset(2, 2)) << 7);
|
||||
assertEquals(SwedishGenerator.Grid.offset(1, 1), Slot.offset(packedPos, 0));
|
||||
assertEquals(SwedishGenerator.Grid.offset(2, 2), Slot.offset(packedPos, 1));
|
||||
var packedPos = ((long) Grid.offset(1, 1)) | (((long) Grid.offset(2, 2)) << 7);
|
||||
assertEquals(Grid.offset(1, 1), Slot.offset(packedPos, 0));
|
||||
assertEquals(Grid.offset(2, 2), Slot.offset(packedPos, 1));
|
||||
|
||||
// Test static horiz
|
||||
// dir 2 (right) is horizontal
|
||||
@@ -59,15 +60,15 @@ public class MainTest {
|
||||
@Test
|
||||
void testForEachSlot() {
|
||||
var generator = new SwedishGenerator();
|
||||
var grid = SwedishGenerator.makeEmptyGrid();
|
||||
var grid = makeEmptyGrid();
|
||||
grid.setCharAt(0, 0, '2'); // right
|
||||
|
||||
var count = new AtomicInteger(0);
|
||||
generator.forEachSlot(grid, (key, packedPos, len) -> {
|
||||
count.incrementAndGet();
|
||||
assertEquals(8, len);
|
||||
assertEquals(0, SwedishGenerator.Grid.r(Slot.offset(packedPos, 0)));
|
||||
assertEquals(1, SwedishGenerator.Grid.c(Slot.offset(packedPos, 0)));
|
||||
assertEquals(0, Grid.r(Slot.offset(packedPos, 0)));
|
||||
assertEquals(1, Grid.c(Slot.offset(packedPos, 0)));
|
||||
});
|
||||
assertEquals(1, count.get());
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class MainTest {
|
||||
}
|
||||
@Test
|
||||
public void testGridBasics() {
|
||||
var grid = SwedishGenerator.makeEmptyGrid();
|
||||
var grid = makeEmptyGrid();
|
||||
// Initialize with #
|
||||
for (int r = 0; r < 3; r++) {
|
||||
for (int c = 0; c < 4; c++) {
|
||||
@@ -120,7 +121,7 @@ public class MainTest {
|
||||
|
||||
@Test
|
||||
public void testGridDeepCopy() {
|
||||
var grid = SwedishGenerator.makeEmptyGrid();
|
||||
var grid = makeEmptyGrid();
|
||||
grid.setCharAt(0, 0, 'A');
|
||||
grid.setCharAt(0, 1, 'B');
|
||||
grid.setCharAt(1, 0, 'C');
|
||||
@@ -136,7 +137,7 @@ public class MainTest {
|
||||
|
||||
@Test
|
||||
public void testMini() {
|
||||
var grid = SwedishGenerator.makeEmptyGrid();
|
||||
var grid = makeEmptyGrid();
|
||||
grid.setCharAt(1, 1, '1');
|
||||
Assertions.assertTrue(grid.isDigitAt(1, 1));
|
||||
}
|
||||
@@ -153,7 +154,7 @@ public class MainTest {
|
||||
opts.tries = 1;
|
||||
opts.verbose = false;
|
||||
|
||||
var dict = SwedishGenerator.loadWords(opts.wordsPath);
|
||||
var dict = loadWords(opts.wordsPath);
|
||||
|
||||
// Act
|
||||
PuzzleResult res = null;
|
||||
@@ -185,12 +186,12 @@ public class MainTest {
|
||||
}
|
||||
@Test
|
||||
public void testIsLetterA() {
|
||||
assertTrue(SwedishGenerator.isLetter((byte) 'A'));
|
||||
assertTrue(isLetter((byte) 'A'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsLetterZ() {
|
||||
assertTrue(SwedishGenerator.isLetter((byte) 'Z'));
|
||||
assertTrue(isLetter((byte) 'Z'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user