This commit is contained in:
mike
2026-01-23 23:13:12 +01:00
parent 282ec56f19
commit 2a5b70896e
7 changed files with 28 additions and 50 deletions

View File

@@ -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<ExportTemplates> 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<ExportTemplates> 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<Lettrix> {
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<Lettrix> stream() {
val stream = Stream.<Lettrix>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);
}
}
}
}

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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)
})

View File

@@ -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);
}
}

View File

@@ -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",

View File

@@ -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();