redo
This commit is contained in:
@@ -6,6 +6,7 @@ import anno.Shaped;
|
||||
import lombok.experimental.Delegate;
|
||||
import lombok.val;
|
||||
import precomp.Const9x8;
|
||||
import precomp.Mask;
|
||||
import puzzle.Riddle.ClueSign;
|
||||
import puzzle.Riddle.ExportedPuzzle;
|
||||
import puzzle.Riddle.Placed;
|
||||
@@ -17,6 +18,9 @@ import puzzle.SwedishGenerator.Grid;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import static puzzle.Masker.Slot;
|
||||
import static puzzle.SwedishGenerator.X;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Arrays;
|
||||
|
||||
@GenerateShapedCopies(
|
||||
packageName = "puzzle",
|
||||
@@ -48,14 +52,6 @@ public record Export() {
|
||||
static int INDEX_COL(int idx) { return idx / R; }
|
||||
static int INDEX(int idx, int cols) { return INDEX_ROW(idx) * cols + INDEX_COL(idx); }
|
||||
|
||||
record Lettrix(int index, byte letter) {
|
||||
|
||||
public int row() { return INDEX_ROW(index); }
|
||||
public int col() { return INDEX_COL(index); }
|
||||
public byte human() { return LETTER(letter); }
|
||||
static Lettrix from(int index, byte[] bytes) { return new Lettrix(index, bytes[index]); }
|
||||
public int index(int cols) { return (row() * cols) + col(); }
|
||||
}
|
||||
public static String gridToString(Clues clues) {
|
||||
val chars = BYTES.get().table();
|
||||
var signa = new Signa(clues);
|
||||
@@ -65,17 +61,30 @@ public record Export() {
|
||||
return result;
|
||||
}
|
||||
|
||||
record Puzzle(@Delegate Grid grid, Clues cl)
|
||||
implements Stream<Lettrix> {
|
||||
record Puzzle(@Delegate Grid grid, Mask[] cells, Clues cl)
|
||||
implements Stream<Mask> {
|
||||
|
||||
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();
|
||||
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) stream.accept(Lettrix.from(Long.numberOfTrailingZeros(l), grid.g));
|
||||
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(Lettrix.from(HI(Long.numberOfTrailingZeros(h)), grid.g));
|
||||
public Puzzle {
|
||||
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) set(Long.numberOfTrailingZeros(l), cells, grid.g);
|
||||
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) set(HI(Long.numberOfTrailingZeros(h)), cells, grid.g);
|
||||
new Signa(cl).forEach(v -> cells[v.index()] = CELLS[v.index() * 33 + 27 + Slot.dir(v.clue())]);
|
||||
}
|
||||
static void set(int idx, Mask[] cells, byte[] read) { cells[idx] = CELLS[idx * 33 + read[idx]]; }
|
||||
public Puzzle(Grid grid, Clues cl) { this(grid, new Mask[grid.g.length], cl); }
|
||||
public Puzzle(Clues clues) { this(new Grid(new byte[SIZE], clues.lo, clues.hi), new Mask[SIZE], clues); }
|
||||
public Puzzle(Signa clues) { this(clues.c()); }
|
||||
public @Delegate Stream<Mask> stream() {
|
||||
val stream = Stream.<Mask>builder();
|
||||
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) stream.accept(cells[Long.numberOfTrailingZeros(l)]);
|
||||
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(cells[HI(Long.numberOfTrailingZeros(h))]);
|
||||
return stream.build();
|
||||
}
|
||||
public Puzzle sync() {
|
||||
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) set(Long.numberOfTrailingZeros(l), cells, grid.g);
|
||||
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) set(HI(Long.numberOfTrailingZeros(h)), cells, grid.g);
|
||||
new Signa(cl).forEach(v -> cells[v.index()] = CELLS[v.index() * 33 + 27 + Slot.dir(v.clue())]);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) {
|
||||
@@ -83,19 +92,19 @@ 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.forEach((l) -> sb[l.index(C + 1)] = l.human());
|
||||
puzzle.forEach((l) -> sb[INDEX(l.index(), C + 1)] = LETTER(l.d()));
|
||||
return new String(sb);
|
||||
}
|
||||
public String cluesGridToString() { return gridToString(clues.c()); }
|
||||
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) {
|
||||
public ExportedPuzzle exportFormatFromFilled(Rewards rewards) {
|
||||
if (slots.length == 0) {
|
||||
return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards);
|
||||
}
|
||||
|
||||
var placed = Arrays.stream(slots)
|
||||
.map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi()).mapToObj(i -> rcis[i]).toArray(rci[]::new)))
|
||||
.map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi()).mapToObj(idx-> puzzle.cells[idx]).toArray(Mask[]::new)))
|
||||
.toArray(Placed[]::new);
|
||||
|
||||
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
|
||||
@@ -120,10 +129,10 @@ public record Export() {
|
||||
for (int i = width; i < template.length; i += width + 1) template[i] = LINE_BREAK;
|
||||
|
||||
puzzle.forEach(l -> {
|
||||
int rr = l.row() - MINR;
|
||||
int cc = l.col() - MINC;
|
||||
int rr = l.r() - MINR;
|
||||
int cc = l.c() - MINC;
|
||||
if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
|
||||
template[rr * (width + 1) + cc] = l.human();
|
||||
template[rr * (width + 1) + cc] = LETTER(l.d());
|
||||
}
|
||||
});
|
||||
var grid = new String(template).split("\n");
|
||||
|
||||
Reference in New Issue
Block a user