redo
This commit is contained in:
@@ -43,30 +43,29 @@ public record Export() {
|
||||
@Shaped static final long MASK_LO = Const9x8.MASK_LO;
|
||||
|
||||
static int HI(int in) { return in | 64; }
|
||||
static char LETTER(int in) { return (char) (in | 64); }
|
||||
static byte LETTER(int in) { return (byte) (in | 64); }
|
||||
static char CLUE_CHAR(int s) { return (char) (s | 48); }
|
||||
static int INDEX_ROW(int idx) { return idx % R; }
|
||||
static int INDEX_COL(int idx) { return idx / R; }
|
||||
static int INDEX(int r, int cols, int c) { return r * cols + c; }
|
||||
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 char human() { return LETTER(letter); }
|
||||
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 record Signa(@Delegate Clues c) {
|
||||
|
||||
public static Signa of(Mask... cells) {
|
||||
var signa = new Signa(createEmpty());
|
||||
Arrays.stream(cells).forEach(signa::setClue);
|
||||
return signa;
|
||||
}
|
||||
public Signa setClue(Mask cell) {
|
||||
if (isLo((cell.index()))) setClueLo(cell.lo(), cell.d());
|
||||
else setClueHi(cell.hi(), cell.d());
|
||||
public static Signa of(Mask... cells) { return new Signa(createEmpty()).setClue(cells); }
|
||||
public Signa setClue(Mask... cells) {
|
||||
for (var cell : cells) {
|
||||
if (isLo((cell.index()))) setClueLo(cell.lo(), cell.d());
|
||||
else setClueHi(cell.hi(), cell.d());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -107,43 +106,22 @@ public record Export() {
|
||||
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(Lettrix.from(HI(Long.numberOfTrailingZeros(h)), grid.g));
|
||||
return stream.build();
|
||||
}
|
||||
public String[] exportGrid(Slotinfo[] slots, ClueSign clueChar, byte[] template) {
|
||||
var sb = template.clone();
|
||||
for (var slot : slots) {
|
||||
val idx = Slot.clueIndex(slot.key());
|
||||
val r = INDEX_ROW(idx);
|
||||
val c = INDEX_COL(idx);
|
||||
val dir = Slot.dir(slot.key());
|
||||
sb[r * (C + 1) + c] = (byte) clueChar.replace((byte) (dir | 48));
|
||||
}
|
||||
stream().forEach((l) -> sb[l.index(C + 1)] = (byte) l.human());
|
||||
return new String(sb) .split("\n");
|
||||
}
|
||||
}
|
||||
|
||||
public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) {
|
||||
|
||||
public String cluesGridToString() {
|
||||
return clues.gridToString();
|
||||
}
|
||||
public String gridRenderHuman() {
|
||||
return String.join("\n", puzzle.exportGrid(slots, _ -> ' ', INIT_GRID_OUTPUT_DASH_ARR));
|
||||
}
|
||||
public String gridGridToString() {
|
||||
var sb = INIT_GRID_OUTPUT_ARR.clone();
|
||||
for (var slot : slots) {
|
||||
val idx = Slot.clueIndex(slot.key());
|
||||
val r = INDEX_ROW(idx);
|
||||
val c = INDEX_COL(idx);
|
||||
val dir = Slot.dir(slot.key());
|
||||
sb[r * (C + 1) + c] = (byte) (dir | 48);
|
||||
}
|
||||
puzzle.stream().forEach((l) -> sb[l.index(C + 1)] = (byte) l.human());
|
||||
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((byte) (Slot.dir(slot.key()) | 48));
|
||||
puzzle.stream().forEach((l) -> sb[l.index(C + 1)] = l.human());
|
||||
return new String(sb);
|
||||
}
|
||||
public String cluesGridToString() { return clues.gridToString(); }
|
||||
public String gridRenderHuman() { return String.join("\n", exportGrid(_ -> (byte) ' ', INIT_GRID_OUTPUT_DASH_ARR).split("\n")); }
|
||||
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(puzzle.exportGrid(slots, _ -> '#', INIT_GRID_OUTPUT_DASH_ARR), new WordOut[0], 1, rewards);
|
||||
return new ExportedPuzzle(exportGrid(_ -> (byte) '#', INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards);
|
||||
}
|
||||
|
||||
var placed = Arrays.stream(slots)
|
||||
@@ -175,7 +153,7 @@ public record Export() {
|
||||
int rr = l.row() - MINR;
|
||||
int cc = l.col() - MINC;
|
||||
if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
|
||||
template[rr * (width + 1) + cc] = (byte) l.human();
|
||||
template[rr * (width + 1) + cc] = l.human();
|
||||
}
|
||||
});
|
||||
var grid = new String(template).split("\n");
|
||||
|
||||
@@ -134,9 +134,8 @@ public class Riddle {
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
static
|
||||
interface ClueSign {
|
||||
public interface ClueSign {
|
||||
|
||||
char replace(byte data);
|
||||
byte replace(byte data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user