diff --git a/src/main/java/puzzle/SwedishGenerator.java b/src/main/java/puzzle/SwedishGenerator.java index 25e6a83..6b5adfb 100644 --- a/src/main/java/puzzle/SwedishGenerator.java +++ b/src/main/java/puzzle/SwedishGenerator.java @@ -379,8 +379,9 @@ public record SwedishGenerator(int[] buff) { } public int len() { return (int) (packedPos >>> 56); } - public int clueR() { return (key >> 8) & 15; } - public int clueC() { return (key >> 4) & 15; } + public int clueR() { return Grid.r((key >>> 4)); } + public int clueIndex() { return key >>> 4; } + public int clueC() { return Grid.c((key >>> 4)); } public int dir() { return key & 15; } public boolean horiz() { return horiz(key); } public int pos(int i) { return offset(packedPos, i); } @@ -416,7 +417,7 @@ public record SwedishGenerator(int[] buff) { cc += nbrs16.dc; } if (n > 0) { - visitor.visit((r << 8) | (c << 4) | d, packedPos, n); + visitor.visit((idx << 4) | d, packedPos, n); } }); } @@ -764,7 +765,8 @@ public record SwedishGenerator(int[] buff) { if ((now - lastLog.get()) < logEveryMs) return; lastLog.set(now); - var done = assigned.size(); + var done = assigned.size(); + // if (done!=grid.clueCount())throw new RuntimeException(); var pct = (TOTAL == 0) ? 100 : (int) Math.floor((done / (double) TOTAL) * 100); var filled = Math.min(BAR_LEN, (int) Math.floor((pct / 100.0) * BAR_LEN)); var bar = "[" + "#".repeat(filled) + "-".repeat(BAR_LEN - filled) + "]"; @@ -854,9 +856,8 @@ public record SwedishGenerator(int[] buff) { break; } } - if (!match) continue; - if (!placeWord(grid, s, w, ctx.undo, depth)) continue; + if (!match || !placeWord(grid, s, w, ctx.undo, depth)) continue; used.set(w.index()); assigned.put(k, w); @@ -892,9 +893,7 @@ public record SwedishGenerator(int[] buff) { break; } } - if (!match) continue; - - if (!placeWord(grid, s, w, ctx.undo, depth)) continue; + if (!match || !placeWord(grid, s, w, ctx.undo, depth)) continue; used.set(w.index()); assigned.put(k, w); diff --git a/src/test/java/puzzle/MainTest.java b/src/test/java/puzzle/MainTest.java index 175dbc0..41ca7c4 100644 --- a/src/test/java/puzzle/MainTest.java +++ b/src/test/java/puzzle/MainTest.java @@ -176,7 +176,7 @@ public class MainTest { Assertions.assertEquals(12347, foundSeed, "Found seed changed"); Assertions.assertEquals(20, res.filled().clueMap().size(), "Number of assigned words changed"); Assertions.assertEquals(775.45, res.filled().simplicity(), 1e-9, "Simplicity value changed"); - Assertions.assertArrayEquals(new byte[]{ 'I', 'N', 'E', 'R', 'T' }, res.filled().clueMap().get(1377).word()); + Assertions.assertArrayEquals(new byte[]{ 'I', 'N', 'E', 'R', 'T' }, res.filled().clueMap().get(849).word()); } @Test public void testIsLetterA() { diff --git a/src/test/java/puzzle/SwedishGeneratorTest.java b/src/test/java/puzzle/SwedishGeneratorTest.java index 948ddf1..478db4f 100644 --- a/src/test/java/puzzle/SwedishGeneratorTest.java +++ b/src/test/java/puzzle/SwedishGeneratorTest.java @@ -12,7 +12,7 @@ public class SwedishGeneratorTest { @Test void testPatternForSlotAllLetters() { var grid = new Grid(new byte[]{ 65, 66, 67 }); // A B C - var slot = Slot.from(0 << 8 | 1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); + var slot = Slot.from(18, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); var pattern = new byte[3]; SwedishGenerator.patternForSlot(grid, slot, pattern); @@ -22,7 +22,7 @@ public class SwedishGeneratorTest { @Test void testPatternForSlotMixed() { var grid = new Grid(new byte[]{ 65, SwedishGenerator.DASH, 67 }); // A - C - var slot = Slot.from(0 << 8 | 1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); + var slot = Slot.from(1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); var pattern = new byte[3]; SwedishGenerator.patternForSlot(grid, slot, pattern); @@ -32,7 +32,7 @@ public class SwedishGeneratorTest { @Test void testPatternForSlotAllDashes() { var grid = new Grid(new byte[]{ SwedishGenerator.DASH, SwedishGenerator.DASH, SwedishGenerator.DASH }); // - - - - var slot = Slot.from(0 << 8 | 1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); + var slot = Slot.from(1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); var pattern = new byte[3]; SwedishGenerator.patternForSlot(grid, slot, pattern); @@ -42,7 +42,7 @@ public class SwedishGeneratorTest { @Test void testPatternForSlotSingleLetter() { var grid = new Grid(new byte[]{ 65, SwedishGenerator.DASH, SwedishGenerator.DASH }); // A - - - var slot = Slot.from(0 << 8 | 1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); + var slot = Slot.from(1 << 4 | 2, ((long) 0) | ((long) 1 << 7) | ((long) 2 << 14), 3); var pattern = new byte[3]; SwedishGenerator.patternForSlot(grid, slot, pattern); @@ -128,10 +128,10 @@ public class SwedishGeneratorTest { @Test void testSlot() { // key = (r << 8) | (c << 4) | d - var key = (2 << 8) | (3 << 4) | 5; + var key = (Grid.offset(2, 3) << 4) | 5; long packedPos = 0; // pos 0: (2, 5) - packedPos |= (long) Grid.offset(2, 5) << 0; + packedPos |= Grid.offset(2, 5); // pos 1: (3, 5) packedPos |= (long) Grid.offset(3, 5) << 7; // pos 2: (4, 5)