introduce bitloops
This commit is contained in:
@@ -3,8 +3,10 @@ package puzzle;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.Export.Clued;
|
||||
import puzzle.Export.PuzzleResult;
|
||||
import puzzle.Export.Rewards;
|
||||
import puzzle.Main.Opts;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slot;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -24,19 +26,28 @@ public class MainTest {
|
||||
static final byte CLUE_UP = 2;
|
||||
static final byte CLUE_LEFT = 3;
|
||||
|
||||
static final int OFF_0_0 = Grid.offset(0, 0);
|
||||
static final int OFF_0_1 = Grid.offset(0, 1);
|
||||
static final int OFF_0_2 = Grid.offset(0, 2);
|
||||
static final int OFF_1_1 = Grid.offset(1, 1);
|
||||
static final int OFF_1_2 = Grid.offset(1, 2);
|
||||
static final int OFF_2_3 = Grid.offset(2, 3);
|
||||
|
||||
static final int OFF_0_0 = Grid.offset(0, 0);
|
||||
static final int OFF_0_1 = Grid.offset(0, 1);
|
||||
static final int OFF_0_2 = Grid.offset(0, 2);
|
||||
static final int OFF_1_1 = Grid.offset(1, 1);
|
||||
static final int OFF_1_2 = Grid.offset(1, 2);
|
||||
static final int OFF_2_3 = Grid.offset(2, 3);
|
||||
static final Opts opts = new Main.Opts() {{
|
||||
this.seed = 12348;
|
||||
this.pop = 4; // Tiny population
|
||||
this.gens = 20; // Very few generations
|
||||
this.minSimplicity = 0;
|
||||
this.threads = 1;
|
||||
this.tries = 1;
|
||||
this.verbose = false;
|
||||
}};
|
||||
static final Dict dict = Dict.loadDict(opts.wordsPath);
|
||||
@Test
|
||||
void testExtractSlots() {
|
||||
|
||||
var clues = Clues.createEmpty();
|
||||
clues.setClue(OFF_0_0, CLUE_RIGHT);
|
||||
var grid = clues.toGrid();
|
||||
var grid = clues.toGrid();
|
||||
grid.setLetter(OFF_0_1, LETTER_A);
|
||||
grid.setLetter(OFF_0_2, LETTER_B);
|
||||
|
||||
@@ -84,7 +95,7 @@ public class MainTest {
|
||||
public void testGridBasics() {
|
||||
var clues = Clues.createEmpty();
|
||||
clues.setClue(OFF_1_2, CLUE_UP);
|
||||
var grid = clues.toGrid();
|
||||
var grid = clues.toGrid();
|
||||
|
||||
// Test set/get
|
||||
grid.setLetter(OFF_0_0, LETTER_A);
|
||||
@@ -130,28 +141,52 @@ public class MainTest {
|
||||
}
|
||||
@Test
|
||||
public void testMini() {
|
||||
val idx = OFF_1_1;
|
||||
val idx = OFF_1_1;
|
||||
var clues = Clues.createEmpty();
|
||||
clues.setClue(idx, CLUE_LEFT);
|
||||
var grid = clues.toGrid();
|
||||
var grid = clues.toGrid();
|
||||
Assertions.assertTrue(grid.isClue(idx));
|
||||
}
|
||||
@Test
|
||||
void testMaskerCreation() {
|
||||
var swe = new SwedishGenerator(new Rng(12348), new int[STACK_SIZE], Clues.createEmpty());
|
||||
var mask = swe.generateMask(opts.pop, opts.gens, Math.max(opts.pop, (int) Math.floor(opts.pop * 1.5)));
|
||||
val clued = new Clued(mask);
|
||||
val test = clued.gridToString();
|
||||
val RESULT = " 3 300\n" +
|
||||
" 1 \n" +
|
||||
" 1 \n" +
|
||||
" 3 0 \n" +
|
||||
" 31 \n" +
|
||||
" 1 \n" +
|
||||
" 1 2\n" +
|
||||
"21 22 3";
|
||||
|
||||
Assertions.assertEquals(18, clued.clueCount(), "Found seed changed");
|
||||
Assertions.assertEquals(RESULT, test, "Found seed changed");
|
||||
}
|
||||
@Test
|
||||
void testFiller() {
|
||||
val rng = new Rng(-343913721);
|
||||
val mask = new Clues(
|
||||
74732156493031040L,
|
||||
193L,
|
||||
281475397248512L,
|
||||
128L,
|
||||
422762372923520L,
|
||||
192L);
|
||||
var filled = fillMask(rng, extractSlots(mask), mask.toGrid(), dict.index());
|
||||
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
|
||||
Assertions.assertEquals(18, filled.wordCount(), "Number of assigned words changed");
|
||||
Assertions.assertEquals("SLEDE", Lemma.asWord(filled.clueMap()[282]));
|
||||
Assertions.assertEquals(74732156493031040L, filled.grid().grid().lo());
|
||||
Assertions.assertEquals(193L, filled.grid().grid().hi());
|
||||
|
||||
var aa = new PuzzleResult(new Clued(mask), filled).exportFormatFromFilled(1, new Rewards(1, 1, 1));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testAttempt() {
|
||||
// Arrange
|
||||
var opts = new Main.Opts();
|
||||
opts.seed = 12348;
|
||||
opts.pop = 4; // Tiny population
|
||||
opts.gens = 20; // Very few generations
|
||||
opts.minSimplicity = 0;
|
||||
opts.fillTimeout = 10_000;
|
||||
opts.threads = 1;
|
||||
opts.tries = 1;
|
||||
opts.verbose = false;
|
||||
|
||||
var dict = Dict.loadDict(opts.wordsPath);
|
||||
|
||||
// Act
|
||||
PuzzleResult res = null;
|
||||
int foundSeed = -1;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
@@ -164,21 +199,13 @@ 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());
|
||||
var aa = res.exportFormatFromFilled(1, new Rewards(1, 1, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assertions.assertNotNull(res, "Puzzle generation failed (null result)");
|
||||
Assertions.assertTrue(res.filled().ok(), "Puzzle generation failed (not ok)");
|
||||
|
||||
// Regression baseline for seed search starting at 12347, pop 4, gens 20
|
||||
Assertions.assertEquals(12348, foundSeed, "Found seed changed");
|
||||
Assertions.assertEquals(18, res.filled().wordCount(), "Number of assigned words changed");
|
||||
Assertions.assertEquals("SLEDE", Lemma.asWord(res.filled().clueMap()[282]));
|
||||
Assertions.assertEquals(74732156493031040L, res.filled().grid().grid().lo());
|
||||
Assertions.assertEquals(193L, res.filled().grid().grid().hi());
|
||||
}
|
||||
boolean isLetter(byte b) { return (b & 64) != 0; }
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user