From 2a5b70896e9bc1d24ed4abbae60424cf9a8b3398 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 23 Jan 2026 23:13:12 +0100 Subject: [PATCH] redo --- src/main/java/puzzle/Export.java | 41 +++++++++++-------- src/main/java/puzzle/Main.java | 1 - src/main/java/puzzle/Masker.java | 8 ++-- src/main/java/puzzle/SwedishGenerator.java | 1 - src/main/java/puzzle/Test123.java | 17 -------- .../java/puzzle/SwedishGeneratorTest.java | 2 +- src/test/java/puzzle/TestDuplication.java | 8 ---- 7 files changed, 28 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/puzzle/Test123.java diff --git a/src/main/java/puzzle/Export.java b/src/main/java/puzzle/Export.java index 8bd056e..2e3218f 100644 --- a/src/main/java/puzzle/Export.java +++ b/src/main/java/puzzle/Export.java @@ -27,13 +27,19 @@ public record Export() { public record ExportTemplates(byte[] table, byte[] dashTable, byte[] wordBytes) { } - @Shaped static final int R = Const9x8.R; - @Shaped static final int C = Const9x8.C; - @Shaped static final byte[] INIT_GRID_OUTPUT_ARR = Const9x8.INIT_GRID_OUTPUT_ARR; - @Shaped static final byte[] INIT_GRID_OUTPUT_DASH_ARR = Const9x8.INIT_GRID_OUTPUT_DASH_ARR; - @Shaped static final long MASK_HI = Const9x8.MASK_HI; - @Shaped static final long MASK_LO = Const9x8.MASK_LO; - public static final ThreadLocal BYTES = ThreadLocal.withInitial( + @Shaped static final byte SPACE = Const9x8.SPACE; + @Shaped static final byte LINE_BREAK = Const9x8.LINE_BREAK; + @Shaped static final byte DASH = Const9x8.DASH; + @Shaped static final int R = Const9x8.R; + @Shaped static final int C = Const9x8.C; + @Shaped static final int SIZE = Const9x8.SIZE; + @Shaped static final byte[] INIT_GRID_OUTPUT_ARR = Const9x8.INIT_GRID_OUTPUT_ARR; + @Shaped static final byte[] INIT_GRID_OUTPUT_DASH_ARR = Const9x8.INIT_GRID_OUTPUT_DASH_ARR; + @Shaped static final long MASK_HI = Const9x8.MASK_HI; + @Shaped static final long MASK_LO = Const9x8.MASK_LO; + @Shaped static final Mask[] CELLS = Const9x8.CELLS; + + public static final ThreadLocal BYTES = ThreadLocal.withInitial( () -> new ExportTemplates(INIT_GRID_OUTPUT_ARR, INIT_GRID_OUTPUT_DASH_ARR, new byte[8])); static int HI(int in) { return in | 64; } static byte LETTER(int in) { return (byte) (in | 64); } @@ -52,16 +58,17 @@ public record Export() { } public static String gridToString(Clues clues) { val chars = BYTES.get().table(); - new Signa(clues).forEach(v -> chars[INDEX(v.index(), C + 1)] = CLUE_CHAR(v.clue())); + var signa = new Signa(clues); + signa.forEach(v -> chars[INDEX(v.index(), C + 1)] = CLUE_CHAR(v.clue())); val result = new String(chars); - new Signa(clues).forEach(v -> chars[INDEX(v.index(), C + 1)] = ' '); + signa.forEach(v -> chars[INDEX(v.index(), C + 1)] = SPACE); return result; } record Puzzle(@Delegate Grid grid, Clues cl) implements Stream { - public Puzzle(Clues clues) { this(Masker.toGrid(clues), clues); } + public Puzzle(Clues clues) { this(new Grid(new byte[SIZE], clues.lo, clues.hi), clues); } public Puzzle(Signa clues) { this(clues.c()); } public @Delegate Stream stream() { val stream = Stream.builder(); @@ -76,15 +83,15 @@ public record Export() { public String exportGrid(ClueSign clueChar, byte[] template) { var sb = template.clone(); for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key()))); - puzzle.stream().forEach((l) -> sb[l.index(C + 1)] = l.human()); + puzzle.forEach((l) -> sb[l.index(C + 1)] = l.human()); return new String(sb); } public String cluesGridToString() { return gridToString(clues.c()); } - public String gridRenderHuman() { return String.join("\n", exportGrid(_ -> (byte) ' ', INIT_GRID_OUTPUT_DASH_ARR).split("\n")); } + public String gridRenderHuman() { return exportGrid(_ -> SPACE, INIT_GRID_OUTPUT_DASH_ARR); } public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); } public ExportedPuzzle exportFormatFromFilled(Rewards rewards, rci[] rcis) { if (slots.length == 0) { - return new ExportedPuzzle(exportGrid(_ -> (byte) '#', INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards); + return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards); } var placed = Arrays.stream(slots) @@ -109,8 +116,8 @@ public record Export() { int height = Math.max(0, maxR - minR + 1); int width = Math.max(0, maxC - minC + 1); byte[] template = new byte[height * (width + 1)]; - Arrays.fill(template, (byte) '#'); - for (int i = width; i < template.length; i += width + 1) template[i] = (byte) '\n'; + Arrays.fill(template, DASH); + for (int i = width; i < template.length; i += width + 1) template[i] = LINE_BREAK; puzzle.forEach(l -> { int rr = l.row() - MINR; @@ -135,7 +142,5 @@ public record Export() { var total = 0.0001d + Arrays.stream(wordsOut).mapToDouble(Riddle.WordOut::complex).sum(); return new ExportedPuzzle(grid, wordsOut, (int) (total / wordsOut.length), rewards); } - } - -} +} \ No newline at end of file diff --git a/src/main/java/puzzle/Main.java b/src/main/java/puzzle/Main.java index 93846a2..b993116 100644 --- a/src/main/java/puzzle/Main.java +++ b/src/main/java/puzzle/Main.java @@ -30,7 +30,6 @@ import static puzzle.SwedishGenerator.fillMask; @ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8") @GenerateNeighbors({ @GenerateNeighbor(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2), - @GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2), @GenerateNeighbor(C = 3, R = 4, packageName = "precomp", className = "Neighbors3x4", MIN_LEN = 2) }) public class Main { diff --git a/src/main/java/puzzle/Masker.java b/src/main/java/puzzle/Masker.java index 86446d4..3de0b42 100644 --- a/src/main/java/puzzle/Masker.java +++ b/src/main/java/puzzle/Masker.java @@ -15,14 +15,14 @@ import static puzzle.SwedishGenerator.Grid; import static puzzle.SwedishGenerator.MAX_TRIES_PER_SLOT; import static puzzle.SwedishGenerator.Rng; import static puzzle.SwedishGenerator.Slotinfo; -import static puzzle.SwedishGenerator.X; @GenerateShapedCopies( packageName = "puzzle", className = "Masker", - shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3", "precomp.Neighbors3x4" } + shapes = { "precomp.Neighbors9x8", "precomp.Neighbors3x4" } ) public final class Masker { + public static final long X = 0L; @Shaped public static final int SIZE = Neighbors9x8.SIZE; @Shaped public static final rci[] IT = Neighbors9x8.IT; @Shaped public static final long[] PATH_LO = Neighbors9x8.PATH_LO; @@ -55,8 +55,8 @@ public final class Masker { this.stack = stack; this.cache = cache; } - public Clues cache(Clues clues){ - return cache.from(clues); + public Clues cache(Clues clues) { + return cache.from(clues); } public static boolean isLo(int n) { return (n & 64) == 0; } public static double similarity(Clues a, Clues b) { diff --git a/src/main/java/puzzle/SwedishGenerator.java b/src/main/java/puzzle/SwedishGenerator.java index 456d3d3..3657fb5 100644 --- a/src/main/java/puzzle/SwedishGenerator.java +++ b/src/main/java/puzzle/SwedishGenerator.java @@ -30,7 +30,6 @@ import static java.nio.charset.StandardCharsets.US_ASCII; @ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8") @GenerateNeighbors({ @GenerateNeighbor(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2), - @GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2), @GenerateNeighbor(C = 3, R = 4, packageName = "precomp", className = "Neighbors3x4", MIN_LEN = 2) }) diff --git a/src/main/java/puzzle/Test123.java b/src/main/java/puzzle/Test123.java deleted file mode 100644 index 3831a78..0000000 --- a/src/main/java/puzzle/Test123.java +++ /dev/null @@ -1,17 +0,0 @@ -package puzzle; - -import anno.GenerateShapedCopies; -import anno.Shaped; -import precomp.Neighbors9x8; -@GenerateShapedCopies( - packageName = "gen", - className = "Test123X", - shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3" } -) -public class Test123 { - - @Shaped public static int SIZE = Neighbors9x8.SIZE; - public static void start() { - System.out.println(SIZE); - } -} \ No newline at end of file diff --git a/src/test/java/puzzle/SwedishGeneratorTest.java b/src/test/java/puzzle/SwedishGeneratorTest.java index 5040541..cb9184f 100644 --- a/src/test/java/puzzle/SwedishGeneratorTest.java +++ b/src/test/java/puzzle/SwedishGeneratorTest.java @@ -79,7 +79,7 @@ import static puzzle.SwedishGenerator.X; import static puzzle.SwedishGenerator.candidateCountForPattern; import static puzzle.SwedishGenerator.candidateInfoForPattern; import static puzzle.SwedishGenerator.patternForSlot; -@GenerateNeighbors(@GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2)) +@GenerateNeighbors(@GenerateNeighbor(C = 3, R = 4, packageName = "precomp", className = "Neighbors3x4", MIN_LEN = 2)) @LemmaGen( packageName = "puzzle", className = "LemmaData", diff --git a/src/test/java/puzzle/TestDuplication.java b/src/test/java/puzzle/TestDuplication.java index 99fe1df..f3aee7c 100644 --- a/src/test/java/puzzle/TestDuplication.java +++ b/src/test/java/puzzle/TestDuplication.java @@ -1,8 +1,6 @@ package puzzle; import anno.ConstGen; -import gen.Test123X_Neighbors4x3; -import gen.Test123X_Neighbors9x8; import lombok.val; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -19,12 +17,6 @@ import static precomp.Const3x4.Cell.r3c0d1; @ConstGen(C = 3, R = 4, packageName = "precomp", className = "Const3x4") public class TestDuplication { - @Test - void test() { - Test123.start(); - Test123X_Neighbors4x3.start(); - Test123X_Neighbors9x8.start(); - } static void main() { TestDuplication test = new TestDuplication(); test.testFiller2();