introduce bitloops

This commit is contained in:
mike
2026-01-12 06:42:22 +01:00
parent b7b66b5cd6
commit f655f70ab8
5 changed files with 38 additions and 36 deletions

View File

@@ -28,11 +28,11 @@ public class ExportFormatTest {
grid.setClue(0, (byte) '2');
// This creates a slot starting at (0,1)
var clueMap = new HashMap<Integer, Lemma>();
var clueMap = new HashMap<Integer, Long>();
// key = (cellIndex << 4) | direction
var key = (0 << 4) | 2;
var lemma = new Lemma("TEST");
clueMap.put(key, lemma);
clueMap.put(key, lemma.word());
// Manually fill the grid letters for "TEST" at (0,1), (0,2), (0,3), (0,4)
grid.setByteAt(Grid.offset(0, 1), (byte) 'T');

View File

@@ -167,7 +167,7 @@ public class MainTest {
// Regression baseline for seed search starting at 12347, pop 4, gens 20
Assertions.assertEquals(12348, foundSeed, "Found seed changed");
Assertions.assertEquals(18, res.filled().clueMap().size(), "Number of assigned words changed");
Assertions.assertEquals("RIJTUIG", res.filled().clueMap().get(74).asWord());
Assertions.assertEquals("RIJTUIG", Lemma.asWord( res.filled().clueMap().get(74)));
Assertions.assertEquals(301794542151533187L, res.filled().grid().grid().lo);
Assertions.assertEquals(193L, res.filled().grid().grid().hi);
}

View File

@@ -108,7 +108,7 @@ public class SwedishGeneratorTest {
var l1 = new Lemma("APPLE");
Assertions.assertEquals(Lemma.pack("APPLE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(l1.word()));
assertEquals(5, l1.length());
assertEquals(5, Lemma.length(l1.word()));
assertEquals((byte) 'A', l1.byteAt(0));
assertEquals(1, l1.intAt(0));
@@ -120,7 +120,7 @@ public class SwedishGeneratorTest {
var entry3 = dict.index()[3];
assertEquals(1, entry3.words().length);
assertEquals(Lemma.pack("AXE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(entry3.words()[0].word()));
assertEquals(Lemma.pack("AXE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(entry3.words()[0]));
// Check pos indexing
// AXE: A at 0, X at 1, E at 2
@@ -276,7 +276,7 @@ public class SwedishGeneratorTest {
// r(i) and c(i) are used by placeWord.
var packedPos = ((long) Grid.offset(0, 0)) | (((long) Grid.offset(0, 1)) << 7) | (((long) Grid.offset(0, 2)) << 14);
var s = Slot.from(0, packedPos, 3);
var w1 = new Lemma("ABC");
var w1 = new Lemma("ABC").word();
var undoBuffer = new int[10];
// 1. Successful placement in empty grid
@@ -291,7 +291,7 @@ public class SwedishGeneratorTest {
assertEquals(0L, undoBuffer[1]); // 0 new characters placed
// 3. Conflict: place "ABD" where "ABC" is
var w2 = new Lemma("ABD");
var w2 = new Lemma("ABD").word();
assertFalse(placeWord(grid, s, w2, undoBuffer, 2));
// Verify grid is unchanged (still "ABC")
assertEquals('A', grid.byteAt(Grid.offset(0, 0)));
@@ -314,7 +314,7 @@ public class SwedishGeneratorTest {
// Slot at 0,1 length 2
var packedPos = ((long) Grid.offset(0, 1)) | (((long) Grid.offset(0, 2)) << 7);
var s = Slot.from((0 << 8) | (1 << 4) | 2, packedPos, 2);
var w = new Lemma("AZ");
var w = new Lemma("AZ").word();
var undoBuffer = new int[10];
var placed = placeWord(grid, s, w, undoBuffer, 0);