Gather data

This commit is contained in:
mike
2026-01-07 23:28:14 +01:00
parent dad1fd69a1
commit efe70fb121
4 changed files with 100 additions and 69 deletions

View File

@@ -1,5 +1,8 @@
package puzzle;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.experimental.Accessors;
import java.util.*;
import static puzzle.SwedishGenerator.*;
@@ -50,7 +53,7 @@ public final class ExportFormat {
}
gridv2.add(sb.toString());
}
return new ExportedPuzzle(gridv2, List.of(), difficulty, rewards);
return new ExportedPuzzle(gridv2, new WordOut[0], difficulty, rewards);
}
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
@@ -72,7 +75,7 @@ public final class ExportFormat {
}
// 3) map of only used letter cells (everything else becomes '#')
Map<Long, Character> letterAt = new HashMap<>();
var letterAt = new HashMap<Long, Character>();
for (var p : placed) {
for (var rc : p.cells) {
int rr = rc[0], cc = rc[1];
@@ -83,7 +86,7 @@ public final class ExportFormat {
}
// 4) render gridv2 over cropped bounds (out-of-bounds become '#')
List<String> gridv2 = new ArrayList<>(Math.max(0, maxR - minR + 1));
var gridv2 = new ArrayList<String>(Math.max(0, maxR - minR + 1));
for (var r = minR; r <= maxR; r++) {
var row = new StringBuilder(Math.max(0, maxC - minC + 1));
for (var c = minC; c <= maxC; c++) {
@@ -93,23 +96,17 @@ public final class ExportFormat {
}
// 5) words output with cropped coordinates
var wordsOut = new ArrayList<WordOut>(placed.size());
for (var p : placed) {
wordsOut.add(new WordOut(
p.lemma,
p.word,
p.clue, // placeholder = word (same as JS)
p.startRow - minR,
p.startCol - minC,
p.direction,
p.word, // answer
p.arrowRow - minR,
p.arrowCol - minC,
p.isReversed,
p.lemma.simpel()
));
}
int MIN_R = minR, MIN_C = minC;
var wordsOut = placed.stream().map(p -> new WordOut(
p.lemma,
p.startRow - MIN_R,
p.startCol - MIN_C,
p.direction,
p.arrowRow - MIN_R,
p.arrowCol - MIN_C,
p.isReversed,
p.lemma.simpel()
)).toArray(WordOut[]::new);
return new ExportedPuzzle(gridv2, wordsOut, difficulty, rewards);
}
@@ -117,8 +114,8 @@ public final class ExportFormat {
* Convert a generator Slot + assigned word into a Placed object for export.
*/
private static Placed extractPlacedFromSlot(Slot s, Lemma lemma) {
int r = s.clueR();
int c = s.clueC();
int r = s.clueR();
int c = s.clueC();
int d = s.dir();
List<int[]> cells = new ArrayList<>();
@@ -131,7 +128,7 @@ public final class ExportFormat {
String direction;
boolean isReversed = false;
if (d ==2) { // right -> horizontal
if (d == 2) { // right -> horizontal
direction = HORIZONTAL;
startRow = cells.get(0)[0];
startCol = cells.get(0)[1];
@@ -163,12 +160,9 @@ public final class ExportFormat {
return new Placed(
lemma,
lemma.word(),
lemma.clue().toArray(String[]::new),
startRow,
startCol,
direction,
lemma.word(), // answer
arrowRow,
arrowCol,
cells,
@@ -177,21 +171,41 @@ public final class ExportFormat {
);
}
// pack (r,c) into one long key (handles negatives too)
private static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
/**
* @param direction "h" | "v"
* @param cells word cells
* @param arrow [arrowRow, arrowCol] */
private record Placed(Lemma lemma, String word, String[] clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol, List<int[]> cells,
int[] arrow,
boolean isReversed) { }
public record Rewards(int coins, int stars, int hints) { }
/// @param direction "h" | "v"
public record WordOut(Lemma lemma, String word, String[] clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol, boolean isReversed,
int complex) { }
public record ExportedPuzzle(List<String> gridv2, List<WordOut> words, int difficulty, Rewards rewards) { }
@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;
}
}