Gather data

This commit is contained in:
mike
2026-01-08 01:18:02 +01:00
parent 3e6d4eec02
commit 14b33022d2
5 changed files with 325 additions and 98 deletions

View File

@@ -3,6 +3,7 @@ package puzzle;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.experimental.Accessors;
import puzzle.Main.PuzzleResult;
import java.util.*;
import static puzzle.SwedishGenerator.*;
@@ -55,21 +56,21 @@ public final class ExportFormat {
}
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
List<int[]> allCells = new ArrayList<>();
for (var p : placed) {
allCells.addAll(p.cells);
allCells.add(p.arrow);
}
int minR = Integer.MAX_VALUE, minC = Integer.MAX_VALUE;
int maxR = Integer.MIN_VALUE, maxC = Integer.MIN_VALUE;
for (var rc : allCells) {
int rr = rc[0], cc = rc[1];
minR = Math.min(minR, rr);
minC = Math.min(minC, cc);
maxR = Math.max(maxR, rr);
maxC = Math.max(maxC, cc);
for (var rc : placed) {
for (var r : rc.cells) {
minR = Math.min(minR, r[0]);
minC = Math.min(minC, r[1]);
maxR = Math.max(maxR, r[0]);
maxC = Math.max(maxC, r[1]);
}
minR = Math.min(minR, rc.arrowRow);
minC = Math.min(minC, rc.arrowCol);
maxR = Math.max(maxR, rc.arrowRow);
maxC = Math.max(maxC, rc.arrowCol);
}
// 3) map of only used letter cells (everything else becomes '#')
@@ -116,9 +117,9 @@ public final class ExportFormat {
int c = s.clueC();
int d = s.dir();
List<int[]> cells = new ArrayList<>();
int[][] cells = new int[s.len()][];
for (int i = 0; i < s.len(); i++) {
cells.add(new int[]{ s.r(i), s.c(i) });
cells[i] = new int[]{ s.r(i), s.c(i) };
}
// Canonicalize: always output right/down
@@ -128,28 +129,28 @@ public final class ExportFormat {
if (d == 2) { // right -> horizontal
direction = HORIZONTAL;
startRow = cells.get(0)[0];
startCol = cells.get(0)[1];
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else if (d == 3 || d == 5) { // down or down-bent -> vertical
direction = VERTICAL;
startRow = cells.get(0)[0];
startCol = cells.get(0)[1];
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else if (d == 4) { // left -> horizontal (REVERSED)
direction = HORIZONTAL;
isReversed = true;
startRow = cells.get(0)[0];
startCol = cells.get(0)[1];
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else if (d == 1) { // up -> vertical (REVERSED)
direction = VERTICAL;
isReversed = true;
startRow = cells.get(0)[0];
startCol = cells.get(0)[1];
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else {
@@ -164,46 +165,20 @@ public final class ExportFormat {
arrowRow,
arrowCol,
cells,
new int[]{ arrowRow, arrowCol },
isReversed
);
}
private static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
@Value @Accessors(fluent = true) @AllArgsConstructor
private static class Placed {
Lemma lemma;
int startRow, startCol;
String direction;
int arrowRow, arrowCol;
List<int[]> cells;
int[] arrow;
boolean isReversed;
}
@Value @Accessors(fluent = true) @AllArgsConstructor
public static class Rewards {
int coins, stars, hints;
}
@Value @Accessors(fluent = true) @AllArgsConstructor
public static class WordOut {
Lemma lemma;
int startRow, startCol;
String direction;
int arrowRow, arrowCol;
boolean isReversed;
int complex;
public String word() { return lemma().word(); }
public ArrayList<String> clue() { return lemma.clue(); }
}
@Value @Accessors(fluent = true) @AllArgsConstructor
public static class ExportedPuzzle {
List<String> gridv2;
WordOut[] words;
int difficulty;
Rewards rewards;
}
private record Placed(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, int[][] cells, boolean isReversed) { }
public record Rewards(int coins, int stars, int hints) { }
public record WordOut(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, boolean isReversed, int complex) {
public String word() { return lemma().word(); }
public ArrayList<String> clue() { return lemma.clue(); }
}
public record ExportedPuzzle(List<String> gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
}