Gather data

This commit is contained in:
mike
2026-01-09 00:39:43 +01:00
parent fb99a7aab4
commit a269584ad6
3 changed files with 93 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
package puzzle;
import puzzle.Main.PuzzleResult;
import puzzle.SwedishGenerator.Grid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -78,11 +79,11 @@ public record ExportFormat() {
int maxR = Integer.MIN_VALUE, maxC = Integer.MIN_VALUE;
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]);
for (var c : rc.cells) {
minR = Math.min(minR, Grid.r(c));
minC = Math.min(minC, Grid.c(c));
maxR = Math.max(maxR, Grid.r(c));
maxC = Math.max(maxC, Grid.c(c));
}
minR = Math.min(minR, rc.arrowRow);
minC = Math.min(minC, rc.arrowCol);
@@ -93,8 +94,8 @@ public record ExportFormat() {
// 3) map of only used letter cells (everything else becomes '#')
var letterAt = new HashMap<Long, Character>();
for (var p : placed) {
for (var rc : p.cells) {
int rr = rc[0], cc = rc[1];
for (var c : p.cells) {
int rr = Grid.r(c), cc = Grid.c(c);
if (inBounds(rr, cc) && g.isLetterAt(rr, cc)) {
letterAt.put(pack(rr, cc), g.getCharAt(rr, cc));
}
@@ -134,40 +135,34 @@ public record ExportFormat() {
int c = s.clueC();
int d = s.dir();
int[][] cells = new int[s.len()][];
int[] cells = new int[s.len()];
for (int i = 0; i < s.len(); i++) {
cells[i] = new int[]{ s.r(i), s.c(i) };
cells[i] = s.pos(i);
}
// Canonicalize: always output right/down
int startRow, startCol, arrowRow, arrowCol;
String direction;
boolean isReversed = false;
startRow = Grid.r(cells[0]);
startCol = Grid.c(cells[0]);
if (d == 2) { // right -> horizontal
direction = HORIZONTAL;
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
arrowRow = r;
arrowCol = c;
} else if (d == 3 || d == 5) { // down or down-bent -> vertical
direction = VERTICAL;
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[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else if (d == 1) { // up -> vertical (REVERSED)
direction = VERTICAL;
isReversed = true;
startRow = cells[0][0];
startCol = cells[0][1];
arrowRow = r;
arrowCol = c;
} else {
@@ -187,7 +182,7 @@ public record ExportFormat() {
}
private static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
private record Placed(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, int[][] cells, boolean isReversed) { }
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) { }