Gather data
This commit is contained in:
@@ -213,7 +213,7 @@ public record ExportFormat() {
|
|||||||
public record WordOut(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, boolean isReversed, int complex) {
|
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 String word() { return new String(lemma().word(), java.nio.charset.StandardCharsets.US_ASCII); }
|
||||||
public ArrayList<String> clue() { return lemma.clue(); }
|
public String[] clue() { return lemma.clue(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ExportedPuzzle(List<String> gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
|
public record ExportedPuzzle(List<String> gridv2, WordOut[] words, int difficulty, Rewards rewards) { }
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class Main {
|
|||||||
public int seed = (int) (System.nanoTime() ^ System.currentTimeMillis());
|
public int seed = (int) (System.nanoTime() ^ System.currentTimeMillis());
|
||||||
public int pop = 18;
|
public int pop = 18;
|
||||||
public int gens = 2000;
|
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 double minSimplicity = 0; // 0 means no limit
|
||||||
public int threads = Math.max(1, Runtime.getRuntime().availableProcessors());
|
public int threads = Math.max(1, Runtime.getRuntime().availableProcessors());
|
||||||
public int tries = threads;
|
public int tries = threads;
|
||||||
@@ -167,7 +167,7 @@ public class Main {
|
|||||||
safe(w.direction(), 3),
|
safe(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().toArray(String[]::new)));
|
Arrays.toString(w.lemma().clue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,11 +400,9 @@ public class Main {
|
|||||||
sb.append(" \"words\": [\n");
|
sb.append(" \"words\": [\n");
|
||||||
for (var i = 0; i < puzzle.words().length; i++) {
|
for (var i = 0; i < puzzle.words().length; i++) {
|
||||||
var w = puzzle.words()[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(" {\n");
|
||||||
sb.append(" \"word\": \"").append(escapeJson(w.word())).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(" \"startRow\": ").append(w.startRow()).append(",\n");
|
||||||
sb.append(" \"startCol\": ").append(w.startCol()).append(",\n");
|
sb.append(" \"startCol\": ").append(w.startCol()).append(",\n");
|
||||||
sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n");
|
sb.append(" \"direction\": \"").append(escapeJson(w.direction())).append("\",\n");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package puzzle;
|
package puzzle;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import puzzle.ExportFormat.Bit;
|
import puzzle.ExportFormat.Bit;
|
||||||
@@ -227,14 +228,14 @@ 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;
|
static int LEMMA_COUNTER = 0;
|
||||||
public Lemma(int index, String word, int simpel, String clu) {
|
public Lemma(int index, String word, int simpel, String[] clu) {
|
||||||
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, new ArrayList<String>(10));
|
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu);
|
||||||
clue.add(clu);
|
|
||||||
}
|
}
|
||||||
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
|
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]; }
|
byte byteAt(int idx) { return word[idx]; }
|
||||||
@Override public int hashCode() { return index; }
|
@Override public int hashCode() { return index; }
|
||||||
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
|
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
|
||||||
@@ -245,14 +246,11 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
int[] lenCounts) {
|
int[] lenCounts) {
|
||||||
|
|
||||||
public Dict(Lemma[] wordz) {
|
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 lenCounts = new int[MAX_WORD_LENGTH + 1];
|
||||||
var index = new DictEntry[MAX_WORD_LENGTH + 1];
|
var index = new DictEntry[MAX_WORD_LENGTH + 1];
|
||||||
Arrays.setAll(index, i -> new DictEntry(i));
|
Arrays.setAll(index, i -> new DictEntry(i));
|
||||||
int maxLength = -1;
|
int maxLength = -1;
|
||||||
for (var lemma : lemmas) {
|
for (var lemma : wordz) {
|
||||||
var L = lemma.word.length;
|
var L = lemma.word.length;
|
||||||
if (L > maxLength) maxLength = L;
|
if (L > maxLength) maxLength = L;
|
||||||
lenCounts[L]++;
|
lenCounts[L]++;
|
||||||
@@ -270,6 +268,8 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
this(wordz, index, lenCounts);
|
this(wordz, index, lenCounts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final Gson GSON = new Gson();
|
||||||
static Dict loadWords(String wordsPath) {
|
static Dict loadWords(String wordsPath) {
|
||||||
String raw;
|
String raw;
|
||||||
try {
|
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";
|
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;
|
var first = true;
|
||||||
for (var line : raw.split("\\R")) {
|
for (var line : raw.split("\\R")) {
|
||||||
if (line.isBlank()) {
|
if (line.isBlank()) {
|
||||||
@@ -304,18 +304,14 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
rawClue = rawClue.substring(1, rawClue.length() - 1).replace("\"\"", "\"");
|
rawClue = rawClue.substring(1, rawClue.length() - 1).replace("\"\"", "\"");
|
||||||
}
|
}
|
||||||
if (score >= 1) {
|
if (score >= 1) {
|
||||||
if (map.containsKey(s)) {
|
map.add(new Lemma(s, simpel, GSON.fromJson(rawClue, String[].class)));
|
||||||
map.get(s).clue.add(rawClue);
|
|
||||||
} else {
|
|
||||||
map.put(s, new Lemma(s, simpel, rawClue));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Invalid word: " + line);
|
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) {
|
static int[] intersectSorted(int[] buff, int[] a, int aLen, int[] b, int bLen) {
|
||||||
//var out = new int[Math.min(aLen, bLen)];
|
//var out = new int[Math.min(aLen, bLen)];
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ public class MainTest {
|
|||||||
// Regression baseline for seed search starting at 12347, pop 4, gens 20
|
// Regression baseline for seed search starting at 12347, pop 4, gens 20
|
||||||
Assertions.assertEquals(12347, foundSeed, "Found seed changed");
|
Assertions.assertEquals(12347, foundSeed, "Found seed changed");
|
||||||
Assertions.assertEquals(20, res.filled().clueMap().size(), "Number of assigned words 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.assertEquals(758.55, res.filled().simplicity(), 1e-9, "Simplicity value changed");
|
||||||
Assertions.assertArrayEquals(new byte[]{ 'I', 'N', 'E', 'R', 'T' }, res.filled().clueMap().get(849).word());
|
Assertions.assertArrayEquals(new byte[]{ 'M', 'A', 'N', 'T', 'A' }, res.filled().clueMap().get(849).word());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testIsLetterA() {
|
public void testIsLetterA() {
|
||||||
|
|||||||
Reference in New Issue
Block a user