Gather data
This commit is contained in:
@@ -16,8 +16,10 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
public static final char C_DASH = '#';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
|
||||
public static final char C_DASH = '\0';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
|
||||
record nbrs_8(int x, int y) { }
|
||||
|
||||
class Data {
|
||||
@@ -109,7 +111,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
|
||||
record Grid(byte[] g, int H, int W) {
|
||||
|
||||
|
||||
Grid deepCopyGrid() { return new Grid(g.clone(), H, W); }
|
||||
private int getOffset(int r, int c) { return r * W + c; }
|
||||
boolean isLettercell(int r, int c) { return !isDigitAt(r, c); }
|
||||
@@ -135,8 +136,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
for (var r = 0; r < H; r++) {
|
||||
if (r > 0) sb.append('\n');
|
||||
for (var c = 0; c < W; c++) {
|
||||
var ch = g.getCharAt(r, c);
|
||||
sb.append(isDigit(ch) ? ' ' : ch);
|
||||
sb.append(g.isDigitAt(r, c) ? ' ' : g.getCharAt(r, c));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -162,14 +162,12 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
}
|
||||
}
|
||||
|
||||
static record Lemma(int index, String word, int length, int difficulty, int simpel, int score, ArrayList<String> clue) {
|
||||
static record Lemma(int index, String word, int length, int simpel, ArrayList<String> clue) {
|
||||
|
||||
static int LEMMA_COUNTER = 0;
|
||||
public Lemma(int index, String word, int simpel, int score, String clue) {
|
||||
var complex = 0 + ((8 - word.length()) * 30) + ((10 - score) * 15);
|
||||
var list = new ArrayList<String>(10);
|
||||
list.add(clue);
|
||||
this(index, word, word.length(), complex, simpel, score, list);
|
||||
public Lemma(int index, String word, int simpel, int score, String clu) {
|
||||
this(index, word, word.length(), simpel, new ArrayList<String>(10));
|
||||
clue.add(clu);
|
||||
}
|
||||
public Lemma(String word, int simpel, int score, String clue) { this(LEMMA_COUNTER++, word, simpel, score, clue); }
|
||||
char charAt(int idx) { return word.charAt(idx); }
|
||||
@@ -182,7 +180,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
int[] lenCounts) {
|
||||
|
||||
public Dict(Lemma[] wordz) {
|
||||
// Sort words by difficulty in ascending order
|
||||
Lemma[] lemmas = wordz.clone();
|
||||
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
|
||||
|
||||
@@ -220,7 +217,10 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
var map = new HashMap<String, Lemma>();
|
||||
boolean first = true;
|
||||
for (var line : raw.split("\\R")) {
|
||||
if (line.isBlank()) continue;
|
||||
if (line.isBlank()) {
|
||||
System.err.println("Empty line: " + line);
|
||||
continue;
|
||||
}
|
||||
var parts = line.split(",", 4);
|
||||
var word = parts[0].trim();
|
||||
if (first && word.equalsIgnoreCase("WOORD")) {
|
||||
@@ -272,7 +272,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
var lists = new ArrayList<IntList>();
|
||||
for (var i = 0; i < pattern.length; i++) {
|
||||
var ch = pattern[i];
|
||||
if (ch != 0 && isLetter(ch)) {
|
||||
if (isLetter(ch)) {
|
||||
lists.add(entry.pos[i][ch - 'A']);
|
||||
}
|
||||
}
|
||||
@@ -605,7 +605,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
public FillResult(boolean ok, Grid grid, HashMap<String, Lemma> assigned, FillStats stats) {
|
||||
double totalSimplicity = 0;
|
||||
if (ok) {
|
||||
for (var w : assigned.values()) totalSimplicity += w.difficulty;
|
||||
for (var w : assigned.values()) totalSimplicity += w.simpel;
|
||||
totalSimplicity = assigned.isEmpty() ? 0 : totalSimplicity / assigned.size();
|
||||
}
|
||||
this(ok, grid, assigned, stats, totalSimplicity);
|
||||
@@ -616,7 +616,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
var pat = new char[s.len];
|
||||
for (var i = 0; i < s.len; i++) {
|
||||
var ch = grid.getCharAt(s.rs[i], s.cs[i]);
|
||||
pat[i] = isLetter(ch) ? ch : 0;
|
||||
if (isLetter(ch)) pat[i] = ch;
|
||||
}
|
||||
return pat;
|
||||
}
|
||||
@@ -768,7 +768,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
if (used.get(w.index())) return false;
|
||||
|
||||
for (var i = 0; i < pat.length; i++) {
|
||||
if (pat[i] != 0 && pat[i] != w.charAt(i)) return false;
|
||||
if (pat[i] != C_DASH && pat[i] != w.charAt(i)) return false;
|
||||
}
|
||||
|
||||
var undo = placeWord(grid, s, w);
|
||||
|
||||
Reference in New Issue
Block a user