Gather data

This commit is contained in:
mike
2026-01-09 11:07:01 +01:00
parent e55e26af6c
commit add9a5db7a
4 changed files with 22 additions and 28 deletions

View File

@@ -212,8 +212,8 @@ public record ExportFormat() {
public record WordOut(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, boolean isReversed, int complex) {
public String word() { return new String(lemma().word(), java.nio.charset.StandardCharsets.US_ASCII); }
public ArrayList<String> clue() { return lemma.clue(); }
public String word() { return new String(lemma().word(), java.nio.charset.StandardCharsets.US_ASCII); }
public String[] clue() { return lemma.clue(); }
}
public record ExportedPuzzle(List<String> gridv2, WordOut[] words, int difficulty, Rewards rewards) { }

View File

@@ -45,7 +45,7 @@ public class Main {
public int seed = (int) (System.nanoTime() ^ System.currentTimeMillis());
public int pop = 18;
public int gens = 2000;
public String wordsPath = "nl_score_hints.csv";
public String wordsPath = "nl_score_hints_v2.csv";
public double minSimplicity = 0; // 0 means no limit
public int threads = Math.max(1, Runtime.getRuntime().availableProcessors());
public int tries = threads;
@@ -167,7 +167,7 @@ public class Main {
safe(w.direction(), 3),
fmtPoint(w.startRow(), w.startCol()),
fmtPoint(w.arrowRow(), w.arrowCol()),
Arrays.toString(w.lemma().clue().toArray(String[]::new)));
Arrays.toString(w.lemma().clue()));
}
}
@@ -400,11 +400,9 @@ public class Main {
sb.append(" \"words\": [\n");
for (var i = 0; i < puzzle.words().length; i++) {
var w = puzzle.words()[i];
var clues = w.clue().toArray(String[]::new);
Arrays.sort(clues, Comparator.comparingInt(String::length));
sb.append(" {\n");
sb.append(" \"word\": \"").append(escapeJson(w.word())).append("\",\n");
sb.append(" \"clue\": [").append(Arrays.stream(clues).map(ss -> "\"" + escapeJson(ss) + "\"").collect(Collectors.joining(","))).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");

View File

@@ -1,5 +1,6 @@
package puzzle;
import com.google.gson.Gson;
import lombok.Getter;
import lombok.val;
import puzzle.ExportFormat.Bit;
@@ -227,17 +228,17 @@ public record SwedishGenerator(int[] buff) {
}
}
static record Lemma(int index, byte[] word, int simpel, ArrayList<String> clue) {
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, new ArrayList<String>(10));
clue.add(clu);
public Lemma(int index, String word, int simpel, String[] clu) {
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu);
}
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
byte byteAt(int idx) { return word[idx]; }
@Override public int hashCode() { return index; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, new String[]{ clue }); }
public Lemma(String word, int simpel, String[] clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
byte byteAt(int idx) { return word[idx]; }
@Override public int hashCode() { return index; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
}
public static record Dict(Lemma[] wordz,
@@ -245,14 +246,11 @@ public record SwedishGenerator(int[] buff) {
int[] lenCounts) {
public Dict(Lemma[] wordz) {
var lemmas = wordz.clone();
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
var lenCounts = new int[MAX_WORD_LENGTH + 1];
var index = new DictEntry[MAX_WORD_LENGTH + 1];
Arrays.setAll(index, i -> new DictEntry(i));
int maxLength = -1;
for (var lemma : lemmas) {
for (var lemma : wordz) {
var L = lemma.word.length;
if (L > maxLength) maxLength = L;
lenCounts[L]++;
@@ -270,6 +268,8 @@ public record SwedishGenerator(int[] buff) {
this(wordz, index, lenCounts);
}
}
static final Gson GSON = new Gson();
static Dict loadWords(String wordsPath) {
String raw;
try {
@@ -279,7 +279,7 @@ public record SwedishGenerator(int[] buff) {
raw = "WOORD,level_1_to_10,hint\nEU,2,hint\nUUR,2,hint\nAUTO,2,hint\nBOOM,2,hint\nHUIS,2,hint\nKAT,2,hint\nZEE,2,hint\nRODE,2,hint\nDRAAD,2,hint\nKENNIS,2,hint\nNETWERK,2,hint\nPAKTE,2,hint\n";
}
var map = new HashMap<String, Lemma>();
var map = new ArrayList<Lemma>();
var first = true;
for (var line : raw.split("\\R")) {
if (line.isBlank()) {
@@ -304,18 +304,14 @@ public record SwedishGenerator(int[] buff) {
rawClue = rawClue.substring(1, rawClue.length() - 1).replace("\"\"", "\"");
}
if (score >= 1) {
if (map.containsKey(s)) {
map.get(s).clue.add(rawClue);
} else {
map.put(s, new Lemma(s, simpel, rawClue));
}
map.add(new Lemma(s, simpel, GSON.fromJson(rawClue, String[].class)));
}
} else {
System.err.println("Invalid word: " + line);
}
}
return new Dict(map.values().toArray(Lemma[]::new));
return new Dict(map .toArray(Lemma[]::new));
}
static int[] intersectSorted(int[] buff, int[] a, int aLen, int[] b, int bLen) {
//var out = new int[Math.min(aLen, bLen)];

View File

@@ -175,8 +175,8 @@ public class MainTest {
// Regression baseline for seed search starting at 12347, pop 4, gens 20
Assertions.assertEquals(12347, foundSeed, "Found seed changed");
Assertions.assertEquals(20, res.filled().clueMap().size(), "Number of assigned words changed");
Assertions.assertEquals(775.45, res.filled().simplicity(), 1e-9, "Simplicity value changed");
Assertions.assertArrayEquals(new byte[]{ 'I', 'N', 'E', 'R', 'T' }, res.filled().clueMap().get(849).word());
Assertions.assertEquals(758.55, res.filled().simplicity(), 1e-9, "Simplicity value changed");
Assertions.assertArrayEquals(new byte[]{ 'M', 'A', 'N', 'T', 'A' }, res.filled().clueMap().get(849).word());
}
@Test
public void testIsLetterA() {