update them

This commit is contained in:
mike
2025-12-24 04:39:21 +01:00
parent f9f0f31d12
commit 0a9a537fa8
3 changed files with 36 additions and 47 deletions

View File

@@ -217,7 +217,8 @@ public class DailyGenerator {
sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n"); sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n");
sb.append(" \"answer\": \"").append(escapeJson(w.answer())).append("\",\n"); sb.append(" \"answer\": \"").append(escapeJson(w.answer())).append("\",\n");
sb.append(" \"arrowRow\": ").append(w.arrowRow()).append(",\n"); sb.append(" \"arrowRow\": ").append(w.arrowRow()).append(",\n");
sb.append(" \"arrowCol\": ").append(w.arrowCol()).append("\n"); sb.append(" \"arrowCol\": ").append(w.arrowCol()).append(",\n");
sb.append(" \"isReversed\": ").append(w.isReversed()).append("\n");
sb.append(" }"); sb.append(" }");
if (i < puzzle.words().size() - 1) sb.append(","); if (i < puzzle.words().size() - 1) sb.append(",");
sb.append("\n"); sb.append("\n");

View File

@@ -132,7 +132,8 @@ public final class ExportFormat {
p.direction, p.direction,
p.word, // answer p.word, // answer
p.arrowRow - minR, p.arrowRow - minR,
p.arrowCol - minC p.arrowCol - minC,
p.isReversed
)); ));
} }
@@ -164,8 +165,9 @@ public final class ExportFormat {
if (cells.size() < minLen) return null; if (cells.size() < minLen) return null;
// Canonicalize: always output right/down // Canonicalize: always output right/down
int startRow, startCol, arrowRow, arrowCol; int startRow, startCol, arrowRow, arrowCol;
String direction; String direction;
boolean isReversed = false;
if (d == '2') { // right -> horizontal if (d == '2') { // right -> horizontal
direction = "horizontal"; direction = "horizontal";
@@ -179,52 +181,35 @@ public final class ExportFormat {
startCol = cells.get(0)[1]; startCol = cells.get(0)[1];
arrowRow = r; arrowRow = r;
arrowCol = c; arrowCol = c;
} else if (d == '4') { // left -> canonical right } else if (d == '4') { // left -> horizontal (REVERSED)
direction = "horizontal"; direction = "horizontal";
var farLeft = cells.get(cells.size() - 1); isReversed = true;
startRow = farLeft[0]; startRow = cells.get(0)[0];
startCol = farLeft[1]; startCol = cells.get(0)[1];
arrowRow = startRow; arrowRow = r;
arrowCol = startCol - 1; arrowCol = c;
} else if (d == '1') { // up -> canonical down } else if (d == '1') { // up -> vertical (REVERSED)
direction = "vertical"; direction = "vertical";
var topMost = cells.get(cells.size() - 1); isReversed = true;
startRow = topMost[0]; startRow = cells.get(0)[0];
startCol = topMost[1]; startCol = cells.get(0)[1];
arrowRow = startRow - 1; arrowRow = r;
arrowCol = startCol; arrowCol = c;
} else { } else {
return null; return null;
} }
// Read word from grid in canonical order (right/down) // Read word from grid using the collected cells
var wordChars = new StringBuilder(); var wordChars = new StringBuilder();
if ("horizontal".equals(direction)) { for (var rc : cells) {
for (var i = 0; i < cells.size(); i++) { wordChars.append(g[rc[0]][rc[1]]);
var cc2 = startCol + i;
var ch = (inBounds(H, W, startRow, cc2) ? g[startRow][cc2] : '#');
if (!isLetter(ch)) break;
wordChars.append(ch);
}
} else {
for (var i = 0; i < cells.size(); i++) {
var rr2 = startRow + i;
var ch = (inBounds(H, W, rr2, startCol) ? g[rr2][startCol] : '#');
if (!isLetter(ch)) break;
wordChars.append(ch);
}
} }
var word = wordChars.toString(); var word = wordChars.toString();
if (word.length() < minLen || word.length() > maxLen) return null; if (word.length() < minLen || word.length() > maxLen) return null;
// Build exact used cells (only for actual word length) // Build exact used cells (only for actual word length)
List<int[]> used = new ArrayList<>(word.length()); List<int[]> used = new ArrayList<>(cells);
if ("horizontal".equals(direction)) {
for (var i = 0; i < word.length(); i++) used.add(new int[]{ startRow, startCol + i });
} else {
for (var i = 0; i < word.length(); i++) used.add(new int[]{ startRow + i, startCol });
}
return new Placed( return new Placed(
word, word,
@@ -236,7 +221,8 @@ public final class ExportFormat {
arrowRow, arrowRow,
arrowCol, arrowCol,
used, used,
new int[]{ arrowRow, arrowCol } new int[]{ arrowRow, arrowCol },
isReversed
); );
} }
@@ -251,21 +237,22 @@ public final class ExportFormat {
* @param direction "horizontal" | "vertical" * @param direction "horizontal" | "vertical"
* @param cells word cells * @param cells word cells
* @param arrow [arrowRow, arrowCol] */ * @param arrow [arrowRow, arrowCol] */
private record Placed(String word, String clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol, List<int[]> cells, int[] arrow) { private record Placed(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) { public record Rewards(int coins, int stars, int hints) {
} }
/** /**
* @param direction "horizontal" | "vertical" */ * @param direction "horizontal" | "vertical" */
public record WordOut(String word, String clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol) { public record WordOut(String word, String clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol, boolean isReversed) {
} }
public record ExportedPuzzle(List<String> gridv2, List<WordOut> words, int difficulty, Rewards rewards) { public record ExportedPuzzle(List<String> gridv2, List<WordOut> words, int difficulty, Rewards rewards) {
} }
} }

View File

@@ -127,7 +127,8 @@ public class Main {
sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n"); sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n");
sb.append(" \"answer\": \"").append(escapeJson(w.answer())).append("\",\n"); sb.append(" \"answer\": \"").append(escapeJson(w.answer())).append("\",\n");
sb.append(" \"arrowRow\": ").append(w.arrowRow()).append(",\n"); sb.append(" \"arrowRow\": ").append(w.arrowRow()).append(",\n");
sb.append(" \"arrowCol\": ").append(w.arrowCol()).append("\n"); sb.append(" \"arrowCol\": ").append(w.arrowCol()).append(",\n");
sb.append(" \"isReversed\": ").append(w.isReversed()).append("\n");
sb.append(" }"); sb.append(" }");
if (i < puzzle.words().size() - 1) sb.append(","); if (i < puzzle.words().size() - 1) sb.append(",");
sb.append("\n"); sb.append("\n");