From 0a9a537fa859a319efc3aa3e58ec2a408b6b31bf Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 24 Dec 2025 04:39:21 +0100 Subject: [PATCH] update them --- src/puzzle/DailyGenerator.java | 3 +- src/puzzle/ExportFormat.java | 77 ++++++++++++++-------------------- src/puzzle/Main.java | 3 +- 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/puzzle/DailyGenerator.java b/src/puzzle/DailyGenerator.java index 245c4b9..cfb3e39 100644 --- a/src/puzzle/DailyGenerator.java +++ b/src/puzzle/DailyGenerator.java @@ -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"); diff --git a/src/puzzle/ExportFormat.java b/src/puzzle/ExportFormat.java index 5dd70ad..cbcd23c 100644 --- a/src/puzzle/ExportFormat.java +++ b/src/puzzle/ExportFormat.java @@ -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 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 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 cells, int[] arrow) { - + private record Placed(String word, String clue, int startRow, int startCol, String direction, String answer, int arrowRow, int arrowCol, List 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 gridv2, List words, int difficulty, Rewards rewards) { - + } } diff --git a/src/puzzle/Main.java b/src/puzzle/Main.java index ffe427c..f10c7c6 100644 --- a/src/puzzle/Main.java +++ b/src/puzzle/Main.java @@ -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");