redo
This commit is contained in:
@@ -4,6 +4,7 @@ import anno.ConstGen;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import precomp.Mask;
|
||||
import static java.lang.Long.bitCount;
|
||||
import static puzzle.SwedishGenerator.X;
|
||||
//@formatter:on
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -106,7 +106,7 @@ public class Main {
|
||||
section("Grid (human)");
|
||||
System.out.print(indentLines(res.gridRenderHuman()));
|
||||
|
||||
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1), Masker.IT);
|
||||
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1));
|
||||
|
||||
section("Clues");
|
||||
info("status : generating...");
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package puzzle;
|
||||
|
||||
public interface Mask {
|
||||
|
||||
record Masker(long lo, long hi,int index,byte d)
|
||||
implements Mask { }
|
||||
default Mask or(Mask o) { return new Masker(o.lo() | lo(), o.hi() | hi(), 0, (byte) 0); }
|
||||
default Mask and(Mask o) { return new Masker(o.lo() & lo(), o.hi() & hi(), 0, (byte) 0); }
|
||||
|
||||
long hi();
|
||||
long lo();
|
||||
int index();
|
||||
byte d();
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package puzzle;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.Delegate;
|
||||
import lombok.val;
|
||||
import precomp.Mask;
|
||||
import puzzle.Masker.Slot;
|
||||
import puzzle.Meta.ShardLem;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
@@ -87,20 +88,6 @@ public class Riddle {
|
||||
|
||||
public record Vestigium(int index, int clue) { }
|
||||
|
||||
record Placed(long lemma, int slotKey, rci[] cells) {
|
||||
|
||||
public static final char HORIZONTAL = 'h';
|
||||
static final char VERTICAL = 'v';
|
||||
static final char[] DIRECTION = { Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.VERTICAL };
|
||||
|
||||
public int arrowCol() { return cells[0].c(); }
|
||||
public int arrowRow() { return cells[0].r(); }
|
||||
public int startRow() { return cells[1].r(); }
|
||||
public int startCol() { return cells[1].c(); }
|
||||
public boolean isReversed() { return !Slotinfo.increasing(slotKey); }
|
||||
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
|
||||
}
|
||||
|
||||
public record ExportedPuzzle(String[] grid, WordOut[] words, int difficulty, Rewards rewards) { }
|
||||
|
||||
public record Rewards(int coins, int stars, int hints) { }
|
||||
@@ -174,4 +161,18 @@ public class Riddle {
|
||||
return stream.build();
|
||||
}
|
||||
}
|
||||
|
||||
public record Placed(long lemma, int slotKey, Mask[] cells) {
|
||||
|
||||
public static final char HORIZONTAL = 'h';
|
||||
static final char VERTICAL = 'v';
|
||||
static final char[] DIRECTION = { Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.VERTICAL };
|
||||
|
||||
public int arrowCol() { return cells[0].c(); }
|
||||
public int arrowRow() { return cells[0].r(); }
|
||||
public int startRow() { return cells[1].r(); }
|
||||
public int startCol() { return cells[1].c(); }
|
||||
public boolean isReversed() { return !Slotinfo.increasing(slotKey); }
|
||||
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user