redo
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user