redo
This commit is contained in:
@@ -27,13 +27,19 @@ public record Export() {
|
|||||||
|
|
||||||
public record ExportTemplates(byte[] table, byte[] dashTable, byte[] wordBytes) { }
|
public record ExportTemplates(byte[] table, byte[] dashTable, byte[] wordBytes) { }
|
||||||
|
|
||||||
@Shaped static final int R = Const9x8.R;
|
@Shaped static final byte SPACE = Const9x8.SPACE;
|
||||||
@Shaped static final int C = Const9x8.C;
|
@Shaped static final byte LINE_BREAK = Const9x8.LINE_BREAK;
|
||||||
@Shaped static final byte[] INIT_GRID_OUTPUT_ARR = Const9x8.INIT_GRID_OUTPUT_ARR;
|
@Shaped static final byte DASH = Const9x8.DASH;
|
||||||
@Shaped static final byte[] INIT_GRID_OUTPUT_DASH_ARR = Const9x8.INIT_GRID_OUTPUT_DASH_ARR;
|
@Shaped static final int R = Const9x8.R;
|
||||||
@Shaped static final long MASK_HI = Const9x8.MASK_HI;
|
@Shaped static final int C = Const9x8.C;
|
||||||
@Shaped static final long MASK_LO = Const9x8.MASK_LO;
|
@Shaped static final int SIZE = Const9x8.SIZE;
|
||||||
public static final ThreadLocal<ExportTemplates> BYTES = ThreadLocal.withInitial(
|
@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]));
|
() -> new ExportTemplates(INIT_GRID_OUTPUT_ARR, INIT_GRID_OUTPUT_DASH_ARR, new byte[8]));
|
||||||
static int HI(int in) { return in | 64; }
|
static int HI(int in) { return in | 64; }
|
||||||
static byte LETTER(int in) { return (byte) (in | 64); }
|
static byte LETTER(int in) { return (byte) (in | 64); }
|
||||||
@@ -52,16 +58,17 @@ public record Export() {
|
|||||||
}
|
}
|
||||||
public static String gridToString(Clues clues) {
|
public static String gridToString(Clues clues) {
|
||||||
val chars = BYTES.get().table();
|
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);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
record Puzzle(@Delegate Grid grid, Clues cl)
|
record Puzzle(@Delegate Grid grid, Clues cl)
|
||||||
implements Stream<Lettrix> {
|
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 Puzzle(Signa clues) { this(clues.c()); }
|
||||||
public @Delegate Stream<Lettrix> stream() {
|
public @Delegate Stream<Lettrix> stream() {
|
||||||
val stream = Stream.<Lettrix>builder();
|
val stream = Stream.<Lettrix>builder();
|
||||||
@@ -76,15 +83,15 @@ public record Export() {
|
|||||||
public String exportGrid(ClueSign clueChar, byte[] template) {
|
public String exportGrid(ClueSign clueChar, byte[] template) {
|
||||||
var sb = template.clone();
|
var sb = template.clone();
|
||||||
for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key())));
|
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);
|
return new String(sb);
|
||||||
}
|
}
|
||||||
public String cluesGridToString() { return gridToString(clues.c()); }
|
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 String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); }
|
||||||
public ExportedPuzzle exportFormatFromFilled(Rewards rewards, rci[] rcis) {
|
public ExportedPuzzle exportFormatFromFilled(Rewards rewards, rci[] rcis) {
|
||||||
if (slots.length == 0) {
|
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)
|
var placed = Arrays.stream(slots)
|
||||||
@@ -109,8 +116,8 @@ public record Export() {
|
|||||||
int height = Math.max(0, maxR - minR + 1);
|
int height = Math.max(0, maxR - minR + 1);
|
||||||
int width = Math.max(0, maxC - minC + 1);
|
int width = Math.max(0, maxC - minC + 1);
|
||||||
byte[] template = new byte[height * (width + 1)];
|
byte[] template = new byte[height * (width + 1)];
|
||||||
Arrays.fill(template, (byte) '#');
|
Arrays.fill(template, DASH);
|
||||||
for (int i = width; i < template.length; i += width + 1) template[i] = (byte) '\n';
|
for (int i = width; i < template.length; i += width + 1) template[i] = LINE_BREAK;
|
||||||
|
|
||||||
puzzle.forEach(l -> {
|
puzzle.forEach(l -> {
|
||||||
int rr = l.row() - MINR;
|
int rr = l.row() - MINR;
|
||||||
@@ -135,7 +142,5 @@ public record Export() {
|
|||||||
var total = 0.0001d + Arrays.stream(wordsOut).mapToDouble(Riddle.WordOut::complex).sum();
|
var total = 0.0001d + Arrays.stream(wordsOut).mapToDouble(Riddle.WordOut::complex).sum();
|
||||||
return new ExportedPuzzle(grid, wordsOut, (int) (total / wordsOut.length), rewards);
|
return new ExportedPuzzle(grid, wordsOut, (int) (total / wordsOut.length), rewards);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -30,7 +30,6 @@ import static puzzle.SwedishGenerator.fillMask;
|
|||||||
@ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
|
@ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
|
||||||
@GenerateNeighbors({
|
@GenerateNeighbors({
|
||||||
@GenerateNeighbor(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2),
|
@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)
|
@GenerateNeighbor(C = 3, R = 4, packageName = "precomp", className = "Neighbors3x4", MIN_LEN = 2)
|
||||||
})
|
})
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ import static puzzle.SwedishGenerator.Grid;
|
|||||||
import static puzzle.SwedishGenerator.MAX_TRIES_PER_SLOT;
|
import static puzzle.SwedishGenerator.MAX_TRIES_PER_SLOT;
|
||||||
import static puzzle.SwedishGenerator.Rng;
|
import static puzzle.SwedishGenerator.Rng;
|
||||||
import static puzzle.SwedishGenerator.Slotinfo;
|
import static puzzle.SwedishGenerator.Slotinfo;
|
||||||
import static puzzle.SwedishGenerator.X;
|
|
||||||
@GenerateShapedCopies(
|
@GenerateShapedCopies(
|
||||||
packageName = "puzzle",
|
packageName = "puzzle",
|
||||||
className = "Masker",
|
className = "Masker",
|
||||||
shapes = { "precomp.Neighbors9x8", "precomp.Neighbors4x3", "precomp.Neighbors3x4" }
|
shapes = { "precomp.Neighbors9x8", "precomp.Neighbors3x4" }
|
||||||
)
|
)
|
||||||
public final class Masker {
|
public final class Masker {
|
||||||
|
|
||||||
|
public static final long X = 0L;
|
||||||
@Shaped public static final int SIZE = Neighbors9x8.SIZE;
|
@Shaped public static final int SIZE = Neighbors9x8.SIZE;
|
||||||
@Shaped public static final rci[] IT = Neighbors9x8.IT;
|
@Shaped public static final rci[] IT = Neighbors9x8.IT;
|
||||||
@Shaped public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
|
@Shaped public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
|
||||||
@@ -55,8 +55,8 @@ public final class Masker {
|
|||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
public Clues cache(Clues clues){
|
public Clues cache(Clues clues) {
|
||||||
return cache.from(clues);
|
return cache.from(clues);
|
||||||
}
|
}
|
||||||
public static boolean isLo(int n) { return (n & 64) == 0; }
|
public static boolean isLo(int n) { return (n & 64) == 0; }
|
||||||
public static double similarity(Clues a, Clues b) {
|
public static double similarity(Clues a, Clues b) {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
|
|||||||
@ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
|
@ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
|
||||||
@GenerateNeighbors({
|
@GenerateNeighbors({
|
||||||
@GenerateNeighbor(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2),
|
@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)
|
@GenerateNeighbor(C = 3, R = 4, packageName = "precomp", className = "Neighbors3x4", MIN_LEN = 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -79,7 +79,7 @@ import static puzzle.SwedishGenerator.X;
|
|||||||
import static puzzle.SwedishGenerator.candidateCountForPattern;
|
import static puzzle.SwedishGenerator.candidateCountForPattern;
|
||||||
import static puzzle.SwedishGenerator.candidateInfoForPattern;
|
import static puzzle.SwedishGenerator.candidateInfoForPattern;
|
||||||
import static puzzle.SwedishGenerator.patternForSlot;
|
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(
|
@LemmaGen(
|
||||||
packageName = "puzzle",
|
packageName = "puzzle",
|
||||||
className = "LemmaData",
|
className = "LemmaData",
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package puzzle;
|
package puzzle;
|
||||||
|
|
||||||
import anno.ConstGen;
|
import anno.ConstGen;
|
||||||
import gen.Test123X_Neighbors4x3;
|
|
||||||
import gen.Test123X_Neighbors9x8;
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
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")
|
@ConstGen(C = 3, R = 4, packageName = "precomp", className = "Const3x4")
|
||||||
public class TestDuplication {
|
public class TestDuplication {
|
||||||
|
|
||||||
@Test
|
|
||||||
void test() {
|
|
||||||
Test123.start();
|
|
||||||
Test123X_Neighbors4x3.start();
|
|
||||||
Test123X_Neighbors9x8.start();
|
|
||||||
}
|
|
||||||
static void main() {
|
static void main() {
|
||||||
TestDuplication test = new TestDuplication();
|
TestDuplication test = new TestDuplication();
|
||||||
test.testFiller2();
|
test.testFiller2();
|
||||||
|
|||||||
Reference in New Issue
Block a user