Gather data

This commit is contained in:
mike
2026-01-07 03:40:48 +01:00
parent 1725b16dd1
commit 684ced86cf
2 changed files with 34 additions and 6 deletions

View File

@@ -816,9 +816,9 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
stats.lastMRV = pick.info.count;
renderProgress.run();
var s = pick.slot;
var k = s.key();
var entry = dictIndex[s.len()];
var s = pick.slot;
var k = s.key();
var entry = dictIndex[s.len()];
var pat = new char[s.len()];
patternForSlot(grid, s, pat);
@@ -827,10 +827,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
var L = idxs.length;
var tries = Math.min(MAX_TRIES_PER_SLOT, L);
// When picking words from sorted indices, we want to favor the beginning
// (lower difficulty) but still have some randomness.
for (var t = 0; t < tries; t++) {
// Bias strongly towards lower indices (simpler words) using r^3
double r = rng.nextFloat();
int idxInArray = (int) (r * r * r * L);
var idx = idxs[idxInArray];

View File

@@ -29,4 +29,35 @@ class SwedishGeneratorTest {
assertEquals(0, s.r(1));
assertEquals(2, s.c(1));
}
@Test
void testStaticSlotMethods() {
// Test static r and c extraction
// packedRs: 1 at index 0, 2 at index 1
long packedRs = (1L << 0) | (2L << 4);
assertEquals(1, Slot.r(packedRs, 0));
assertEquals(2, Slot.r(packedRs, 1));
// Test static horiz
// dir 2 (right) is horizontal
assertTrue(Slot.horiz(2));
// dir 3 (down) is vertical
assertTrue(!Slot.horiz(3));
}
@Test
void testForEachSlot() {
SwedishGenerator generator = new SwedishGenerator(3, 3);
Grid grid = generator.makeEmptyGrid();
grid.setCharAt(0, 0, '2'); // right
java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(0);
generator.forEachSlot(grid, (key, rs, cs, len) -> {
count.incrementAndGet();
assertEquals(2, len);
assertEquals(0, Slot.r(rs, 0));
assertEquals(1, Slot.c(cs, 0));
});
assertEquals(1, count.get());
}
}