Gather data
This commit is contained in:
@@ -7,7 +7,7 @@ import puzzle.SwedishGenerator.Grid;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static puzzle.SwedishGenerator.R;
|
import static puzzle.SwedishGenerator.R;
|
||||||
import static puzzle.SwedishGenerator.Lemma;
|
import static puzzle.SwedishGenerator.Lemma;
|
||||||
import static puzzle.SwedishGenerator.Slot;
|
import static puzzle.SwedishGenerator.Slot;
|
||||||
@@ -58,10 +58,6 @@ public record Export() {
|
|||||||
|
|
||||||
static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
|
static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
|
||||||
long l1, l2;
|
long l1, l2;
|
||||||
public Bit() {
|
|
||||||
l1 = 0L;
|
|
||||||
l2 = 0L;
|
|
||||||
}
|
|
||||||
public boolean get(int bitIndex) {
|
public boolean get(int bitIndex) {
|
||||||
if (bitIndex < 64) return (l1 & (1L << bitIndex)) != 0L;
|
if (bitIndex < 64) return (l1 & (1L << bitIndex)) != 0L;
|
||||||
return (l2 & (1L << (bitIndex & 63))) != 0L;
|
return (l2 & (1L << (bitIndex & 63))) != 0L;
|
||||||
@@ -86,18 +82,19 @@ public record Export() {
|
|||||||
public void clear() { Arrays.fill(bits, 0L); }
|
public void clear() { Arrays.fill(bits, 0L); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Placed(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, int[] cells, boolean isReversed) {
|
record Placed(Lemma lemma, int startRow, int startCol, char direction, int arrowRow, int arrowCol, int[] cells, boolean isReversed) {
|
||||||
|
|
||||||
static final String HORIZONTAL = "h";
|
public static final char HORIZONTAL = 'h';
|
||||||
static final String VERTICAL = "v";
|
static final char VERTICAL = 'v';
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Rewards(int coins, int stars, int hints) { }
|
public record Rewards(int coins, int stars, int hints) { }
|
||||||
|
|
||||||
public record WordOut(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, boolean isReversed, int complex) {
|
public record WordOut(String word, int[] cell, int startRow, int startCol, char direction, int arrowRow, int arrowCol, boolean isReversed, int complex, String[] clue) {
|
||||||
|
|
||||||
public String word() { return new String(lemma().word(), java.nio.charset.StandardCharsets.US_ASCII); }
|
public WordOut(Lemma l, int startRow, int startCol, char d, int arrowRow, int arrowCol, boolean isReversed) {
|
||||||
public String[] clue() { return lemma.clue(); }
|
this(new String(l.word(), US_ASCII), new int[]{ arrowRow, arrowCol, startRow, startCol }, startRow, startCol, d, arrowRow, arrowCol, isReversed, l.simpel(), l.clue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ExportedPuzzle(String[] gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
|
public record ExportedPuzzle(String[] gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
|
||||||
@@ -111,7 +108,7 @@ public record Export() {
|
|||||||
var cells = new int[s.len()];
|
var cells = new int[s.len()];
|
||||||
for (int i = 0, len = s.len(); i < len; i++) cells[i] = s.pos(i);
|
for (int i = 0, len = s.len(); i < len; i++) cells[i] = s.pos(i);
|
||||||
|
|
||||||
String direction;
|
char direction;
|
||||||
var isReversed = false;
|
var isReversed = false;
|
||||||
var startRow = Grid.r(cells[0]);
|
var startRow = Grid.r(cells[0]);
|
||||||
var startCol = Grid.c(cells[0]);
|
var startCol = Grid.c(cells[0]);
|
||||||
@@ -200,9 +197,7 @@ public record Export() {
|
|||||||
var gridv2 = new String[Math.max(0, maxR - minR + 1)];
|
var gridv2 = new String[Math.max(0, maxR - minR + 1)];
|
||||||
for (int r = minR, i = 0; r <= maxR; r++, i++) {
|
for (int r = minR, i = 0; r <= maxR; r++, i++) {
|
||||||
var row = new StringBuilder(Math.max(0, maxC - minC + 1));
|
var row = new StringBuilder(Math.max(0, maxC - minC + 1));
|
||||||
for (var c = minC; c <= maxC; c++) {
|
for (var c = minC; c <= maxC; c++) row.append(letterAt.getOrDefault(Bit.pack(r, c), '#'));
|
||||||
row.append(letterAt.getOrDefault(Bit.pack(r, c), '#'));
|
|
||||||
}
|
|
||||||
gridv2[i] = row.toString();
|
gridv2[i] = row.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,8 +210,7 @@ public record Export() {
|
|||||||
p.direction,
|
p.direction,
|
||||||
p.arrowRow - MIN_R,
|
p.arrowRow - MIN_R,
|
||||||
p.arrowCol - MIN_C,
|
p.arrowCol - MIN_C,
|
||||||
p.isReversed,
|
p.isReversed
|
||||||
p.lemma.simpel()
|
|
||||||
)).toArray(WordOut[]::new);
|
)).toArray(WordOut[]::new);
|
||||||
return new ExportedPuzzle(gridv2, wordsOut, difficulty, rewards);
|
return new ExportedPuzzle(gridv2, wordsOut, difficulty, rewards);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static puzzle.Export.*;
|
import static puzzle.Export.*;
|
||||||
import static puzzle.SwedishGenerator.*;
|
import static puzzle.SwedishGenerator.*;
|
||||||
|
import static puzzle.SwedishGenerator.Dict.GSON;
|
||||||
import static puzzle.SwedishGenerator.Dict.loadDict;
|
import static puzzle.SwedishGenerator.Dict.loadDict;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -162,10 +163,10 @@ public class Main {
|
|||||||
j,
|
j,
|
||||||
safe(w.word(), 12),
|
safe(w.word(), 12),
|
||||||
safe("" + w.complex(), 4),
|
safe("" + w.complex(), 4),
|
||||||
safe(w.direction(), 3),
|
safe(String.valueOf(w.direction()), 3),
|
||||||
fmtPoint(w.startRow(), w.startCol()),
|
fmtPoint(w.startRow(), w.startCol()),
|
||||||
fmtPoint(w.arrowRow(), w.arrowCol()),
|
fmtPoint(w.arrowRow(), w.arrowCol()),
|
||||||
Arrays.toString(w.lemma().clue()));
|
Arrays.toString(w.clue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,43 +376,9 @@ public class Main {
|
|||||||
|
|
||||||
// ---------------- Export (unchanged logic) ----------------
|
// ---------------- Export (unchanged logic) ----------------
|
||||||
|
|
||||||
|
record JsonExportedPuzzle(String date, String theme, int difficulty, Rewards rewards, String[] grid, WordOut[] words) { }
|
||||||
private static String toJson(ExportedPuzzle puzzle, String date, String theme) {
|
private static String toJson(ExportedPuzzle puzzle, String date, String theme) {
|
||||||
var sb = new StringBuilder();
|
return GSON.toJson(new JsonExportedPuzzle(date, theme, puzzle.difficulty(), puzzle.rewards(), puzzle.gridv2(), puzzle.words()));
|
||||||
sb.append("{\n");
|
|
||||||
sb.append(" \"date\": \"").append(escapeJson(date)).append("\",\n");
|
|
||||||
sb.append(" \"theme\": \"").append(escapeJson(theme)).append("\",\n");
|
|
||||||
sb.append(" \"difficulty\": ").append(puzzle.difficulty()).append(",\n");
|
|
||||||
sb.append(" \"rewards\": {\n");
|
|
||||||
sb.append(" \"coins\": ").append(puzzle.rewards().coins()).append(",\n");
|
|
||||||
sb.append(" \"stars\": ").append(puzzle.rewards().stars()).append(",\n");
|
|
||||||
sb.append(" \"hints\": ").append(puzzle.rewards().hints()).append("\n");
|
|
||||||
sb.append(" },\n");
|
|
||||||
sb.append(" \"gridv2\": [\n");
|
|
||||||
for (var i = 0; i < puzzle.gridv2().length; i++) {
|
|
||||||
sb.append(" \"").append(escapeJson(puzzle.gridv2()[i])).append("\"");
|
|
||||||
if (i < puzzle.gridv2().length - 1) sb.append(",");
|
|
||||||
sb.append("\n");
|
|
||||||
}
|
|
||||||
sb.append(" ],\n");
|
|
||||||
sb.append(" \"words\": [\n");
|
|
||||||
for (var i = 0; i < puzzle.words().length; i++) {
|
|
||||||
var w = puzzle.words()[i];
|
|
||||||
sb.append(" {\n");
|
|
||||||
sb.append(" \"word\": \"").append(escapeJson(w.word())).append("\",\n");
|
|
||||||
sb.append(" \"clue\": [").append(Arrays.stream(w.clue()).map(ss -> "\"" + escapeJson(ss) + "\"").collect(Collectors.joining(","))).append("],\n");
|
|
||||||
sb.append(" \"startRow\": ").append(w.startRow()).append(",\n");
|
|
||||||
sb.append(" \"startCol\": ").append(w.startCol()).append(",\n");
|
|
||||||
sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n");
|
|
||||||
sb.append(" \"arrowRow\": ").append(w.arrowRow()).append(",\n");
|
|
||||||
sb.append(" \"arrowCol\": ").append(w.arrowCol()).append(",\n");
|
|
||||||
sb.append(" \"isReversed\": ").append(w.isReversed()).append("\n");
|
|
||||||
sb.append(" }");
|
|
||||||
if (i < puzzle.words().length - 1) sb.append(",");
|
|
||||||
sb.append("\n");
|
|
||||||
}
|
|
||||||
sb.append(" ]\n");
|
|
||||||
sb.append("}\n");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String escapeJson(String s) {
|
private static String escapeJson(String s) {
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static record Lemma(int index, byte[] word, int simpel, String[] clue) {
|
public static record Lemma(int index, byte[] word, int simpel, String[] clue) {
|
||||||
|
|
||||||
static int LEMMA_COUNTER = 0;
|
static int LEMMA_COUNTER = 0;
|
||||||
public Lemma(int index, String word, int simpel, String[] clu) { this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu); }
|
public Lemma(int index, String word, int simpel, String[] clu) { this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu); }
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package puzzle;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import puzzle.Export.Gridded;
|
import puzzle.Export.Gridded;
|
||||||
|
import puzzle.Export.Placed;
|
||||||
import puzzle.Export.Rewards;
|
import puzzle.Export.Rewards;
|
||||||
import puzzle.Export.PuzzleResult;
|
import puzzle.Export.PuzzleResult;
|
||||||
import puzzle.SwedishGenerator.FillResult;
|
import puzzle.SwedishGenerator.FillResult;
|
||||||
@@ -53,7 +54,7 @@ public class ExportFormatTest {
|
|||||||
assertEquals(1, exported.words().length);
|
assertEquals(1, exported.words().length);
|
||||||
var w = exported.words()[0];
|
var w = exported.words()[0];
|
||||||
assertEquals("TEST", w.word());
|
assertEquals("TEST", w.word());
|
||||||
assertEquals("h", w.direction());
|
assertEquals(Placed.HORIZONTAL, w.direction());
|
||||||
|
|
||||||
// The bounding box should include (0,0) for the arrow and (0,1)-(0,4) for the word.
|
// The bounding box should include (0,0) for the arrow and (0,1)-(0,4) for the word.
|
||||||
// minR=0, maxR=0, minC=0, maxC=4
|
// minR=0, maxR=0, minC=0, maxC=4
|
||||||
|
|||||||
Reference in New Issue
Block a user