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(" \"answer\": \"").append(escapeJson(w.answer())).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(" }");
if (i < puzzle.words().size() - 1) sb.append(",");
sb.append("\n");

View File

@@ -132,7 +132,8 @@ public final class ExportFormat {
p.direction,
p.word, // answer
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;
// Canonicalize: always output right/down
int startRow, startCol, arrowRow, arrowCol;
String direction;
int startRow, startCol, arrowRow, arrowCol;
String direction;
boolean isReversed = false;
if (d == '2') { // right -> horizontal
direction = "horizontal";
@@ -179,52 +181,35 @@ public final class ExportFormat {
startCol = cells.get(0)[1];
arrowRow = r;
arrowCol = c;
} else if (d == '4') { // left -> canonical right
direction = "horizontal";
var farLeft = cells.get(cells.size() - 1);
startRow = farLeft[0];
startCol = farLeft[1];
arrowRow = startRow;
arrowCol = startCol - 1;
} else if (d == '1') { // up -> canonical down
direction = "vertical";
var topMost = cells.get(cells.size() - 1);
startRow = topMost[0];
startCol = topMost[1];
arrowRow = startRow - 1;
arrowCol = startCol;
} else if (d == '4') { // left -> horizontal (REVERSED)
direction = "horizontal";
isReversed = true;
startRow = cells.get(0)[0];
startCol = cells.get(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];
arrowRow = r;
arrowCol = c;
} else {
return null;
}
// Read word from grid in canonical order (right/down)
// Read word from grid using the collected cells
var wordChars = new StringBuilder();
if ("horizontal".equals(direction)) {
for (var i = 0; i < cells.size(); i++) {
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);
}
for (var rc : cells) {
wordChars.append(g[rc[0]][rc[1]]);
}
var word = wordChars.toString();
if (word.length() < minLen || word.length() > maxLen) return null;
// Build exact used cells (only for actual word length)
List<int[]> used = new ArrayList<>(word.length());
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 });
}
List<int[]> used = new ArrayList<>(cells);
return new Placed(
word,
@@ -236,7 +221,8 @@ public final class ExportFormat {
arrowRow,
arrowCol,
used,
new int[]{ arrowRow, arrowCol }
new int[]{ arrowRow, arrowCol },
isReversed
);
}
@@ -251,21 +237,22 @@ public final class ExportFormat {
* @param direction "horizontal" | "vertical"
* @param cells word cells
* @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) {
}
/**
* @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) {
}
}

View File

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