Gather data
This commit is contained in:
@@ -7,7 +7,7 @@ import puzzle.SwedishGenerator.Grid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static puzzle.SwedishGenerator.R;
|
||||
import static puzzle.SwedishGenerator.Lemma;
|
||||
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); }
|
||||
long l1, l2;
|
||||
public Bit() {
|
||||
l1 = 0L;
|
||||
l2 = 0L;
|
||||
}
|
||||
public boolean get(int bitIndex) {
|
||||
if (bitIndex < 64) return (l1 & (1L << bitIndex)) != 0L;
|
||||
return (l2 & (1L << (bitIndex & 63))) != 0L;
|
||||
@@ -86,18 +82,19 @@ public record Export() {
|
||||
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";
|
||||
static final String VERTICAL = "v";
|
||||
public static final char HORIZONTAL = 'h';
|
||||
static final char VERTICAL = 'v';
|
||||
}
|
||||
|
||||
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 String[] clue() { return lemma.clue(); }
|
||||
public WordOut(Lemma l, int startRow, int startCol, char d, int arrowRow, int arrowCol, boolean isReversed) {
|
||||
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) { }
|
||||
@@ -111,7 +108,7 @@ public record Export() {
|
||||
var cells = new int[s.len()];
|
||||
for (int i = 0, len = s.len(); i < len; i++) cells[i] = s.pos(i);
|
||||
|
||||
String direction;
|
||||
char direction;
|
||||
var isReversed = false;
|
||||
var startRow = Grid.r(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)];
|
||||
for (int r = minR, i = 0; r <= maxR; r++, i++) {
|
||||
var row = new StringBuilder(Math.max(0, maxC - minC + 1));
|
||||
for (var c = minC; c <= maxC; c++) {
|
||||
row.append(letterAt.getOrDefault(Bit.pack(r, c), '#'));
|
||||
}
|
||||
for (var c = minC; c <= maxC; c++) row.append(letterAt.getOrDefault(Bit.pack(r, c), '#'));
|
||||
gridv2[i] = row.toString();
|
||||
}
|
||||
|
||||
@@ -215,8 +210,7 @@ public record Export() {
|
||||
p.direction,
|
||||
p.arrowRow - MIN_R,
|
||||
p.arrowCol - MIN_C,
|
||||
p.isReversed,
|
||||
p.lemma.simpel()
|
||||
p.isReversed
|
||||
)).toArray(WordOut[]::new);
|
||||
return new ExportedPuzzle(gridv2, wordsOut, difficulty, rewards);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static puzzle.Export.*;
|
||||
import static puzzle.SwedishGenerator.*;
|
||||
import static puzzle.SwedishGenerator.Dict.GSON;
|
||||
import static puzzle.SwedishGenerator.Dict.loadDict;
|
||||
|
||||
public class Main {
|
||||
@@ -162,10 +163,10 @@ public class Main {
|
||||
j,
|
||||
safe(w.word(), 12),
|
||||
safe("" + w.complex(), 4),
|
||||
safe(w.direction(), 3),
|
||||
safe(String.valueOf(w.direction()), 3),
|
||||
fmtPoint(w.startRow(), w.startCol()),
|
||||
fmtPoint(w.arrowRow(), w.arrowCol()),
|
||||
Arrays.toString(w.lemma().clue()));
|
||||
Arrays.toString(w.clue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,43 +376,9 @@ public class Main {
|
||||
|
||||
// ---------------- 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) {
|
||||
var sb = new StringBuilder();
|
||||
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();
|
||||
return GSON.toJson(new JsonExportedPuzzle(date, theme, puzzle.difficulty(), puzzle.rewards(), puzzle.gridv2(), puzzle.words()));
|
||||
}
|
||||
|
||||
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;
|
||||
public Lemma(int index, String word, int simpel, String[] clu) { this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu); }
|
||||
|
||||
Reference in New Issue
Block a user