Gather data
This commit is contained in:
@@ -2,13 +2,15 @@ package puzzle;
|
||||
|
||||
import puzzle.Main.PuzzleResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import static puzzle.SwedishGenerator.H;
|
||||
import static puzzle.SwedishGenerator.R;
|
||||
import static puzzle.SwedishGenerator.Lemma;
|
||||
import static puzzle.SwedishGenerator.SIZE;
|
||||
import static puzzle.SwedishGenerator.Slot;
|
||||
import static puzzle.SwedishGenerator.W;
|
||||
import static puzzle.SwedishGenerator.C;
|
||||
|
||||
/**
|
||||
* ExportFormat.java
|
||||
@@ -19,19 +21,34 @@ import static puzzle.SwedishGenerator.W;
|
||||
* - crops to bounding box (words + arrow cells) with 1-cell margin
|
||||
* - outputs gridv2 + words[] (+ difficulty, rewards)
|
||||
*/
|
||||
public final class ExportFormat {
|
||||
public record ExportFormat() {
|
||||
|
||||
record Bit(long[] bits) {
|
||||
|
||||
public Bit() { this(new long[(SIZE >> 6) + 1]); }
|
||||
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
|
||||
public boolean get(int bitIndex) { return (this.bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
|
||||
public void set(int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
|
||||
public void clear(int bitIndex) { this.bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
|
||||
public void clear() { Arrays.fill(bits, 0L); }
|
||||
}
|
||||
|
||||
record Bit1029(long[] bits) {
|
||||
|
||||
public Bit1029() { this(new long[1029]); }
|
||||
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
|
||||
public boolean get(int bitIndex) { return (this.bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
|
||||
public void set(int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
|
||||
public void clear(int bitIndex) { this.bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
|
||||
public void clear() { Arrays.fill(bits, 0L); }
|
||||
}
|
||||
|
||||
private ExportFormat() { }
|
||||
static final String HORIZONTAL = "h", VERTICAL = "v";
|
||||
private static boolean inBounds(int H, int W, int r, int c) { return r >= 0 && r < H && c >= 0 && c < W; }
|
||||
|
||||
// ---------- Public API ----------
|
||||
private static boolean inBounds(int r, int c) { return r >= 0 && r < SwedishGenerator.R && c >= 0 && c < SwedishGenerator.C; }
|
||||
|
||||
public static ExportedPuzzle exportFormatFromFilled(PuzzleResult puz, int difficulty, Rewards rewards) {
|
||||
Objects.requireNonNull(puz, "puz");
|
||||
var g = puz.filled().grid();
|
||||
|
||||
// 1) extract "placed" list from all clue digits in the filled grid
|
||||
var g = puz.filled().grid();
|
||||
var placed = new ArrayList<Placed>();
|
||||
var clueMap = puz.filled().clueMap();
|
||||
puz.swe().forEachSlot(g, (int key, long rs, long cs, int len) -> {
|
||||
@@ -44,10 +61,10 @@ public final class ExportFormat {
|
||||
|
||||
// If nothing placed: return full grid mapped to letters/# only
|
||||
if (placed.isEmpty()) {
|
||||
var gridv2 = new ArrayList<String>(H);
|
||||
for (var r = 0; r < H; r++) {
|
||||
var sb = new StringBuilder(W);
|
||||
for (var c = 0; c < W; c++) {
|
||||
var gridv2 = new ArrayList<String>(R);
|
||||
for (var r = 0; r < R; r++) {
|
||||
var sb = new StringBuilder(C);
|
||||
for (var c = 0; c < C; c++) {
|
||||
sb.append(g.isLetterAt(r, c) ? g.getCharAt(r, c) : '#');
|
||||
}
|
||||
gridv2.add(sb.toString());
|
||||
@@ -78,7 +95,7 @@ public final class ExportFormat {
|
||||
for (var p : placed) {
|
||||
for (var rc : p.cells) {
|
||||
int rr = rc[0], cc = rc[1];
|
||||
if (inBounds(H, W, rr, cc) && g.isLetterAt(rr, cc)) {
|
||||
if (inBounds(rr, cc) && g.isLetterAt(rr, cc)) {
|
||||
letterAt.put(pack(rr, cc), g.getCharAt(rr, cc));
|
||||
}
|
||||
}
|
||||
@@ -181,4 +198,5 @@ public final class ExportFormat {
|
||||
}
|
||||
|
||||
public record ExportedPuzzle(List<String> gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user