Gather data

This commit is contained in:
mike
2026-01-06 21:04:39 +01:00
parent 07b629c7a0
commit 3014571ba3
3 changed files with 24 additions and 32 deletions

View File

@@ -42,12 +42,11 @@ public final class ExportFormat {
// If nothing placed: return full grid mapped to letters/# only
if (placed.isEmpty()) {
List<String> gridv2 = new ArrayList<>(H);
var gridv2 = new ArrayList<String>(H);
for (var r = 0; r < H; r++) {
var sb = new StringBuilder(W);
for (var c = 0; c < W; c++) {
var ch = g.getCharAt(r, c);
sb.append(isLetter(ch) ? ch : '#');
sb.append(g.isLetterAt(r, c) ? g.getCharAt(r, c) : '#');
}
gridv2.add(sb.toString());
}
@@ -165,7 +164,7 @@ public final class ExportFormat {
return new Placed(
lemma,
lemma.word(),
lemma.clue()/*dict.words()[lemma.index()].clue()*/.toArray(String[]::new), // clue placeholder
lemma.clue().toArray(String[]::new),
startRow,
startCol,
direction,

View File

@@ -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);

View File

@@ -8,6 +8,7 @@ import puzzle.SwedishGenerator.Lemma;
import puzzle.SwedishGenerator.PuzzleResult;
import puzzle.SwedishGenerator.Rng;
import static puzzle.Main.indentLines;
import static puzzle.SwedishGenerator.C_DASH;
public class MainTest {
@@ -15,7 +16,6 @@ public class MainTest {
MainTest t = new MainTest();
t.testGridBasics();
t.testGridDeepCopy();
t.testGridOffset();
t.testMini();
t.testAttempt();
}
@@ -26,7 +26,7 @@ public class MainTest {
// Initialize with #
for (int r = 0; r < 3; r++) {
for (int c = 0; c < 4; c++) {
grid.setCharAt(r, c, '#');
grid.setCharAt(r, c, C_DASH);
}
}
@@ -38,7 +38,7 @@ public class MainTest {
Assertions.assertEquals('A', grid.getCharAt(0, 0));
Assertions.assertEquals('5', grid.getCharAt(1, 2));
Assertions.assertEquals('Z', grid.getCharAt(2, 3));
Assertions.assertEquals('#', grid.getCharAt(1, 1));
Assertions.assertEquals(C_DASH, grid.getCharAt(1, 1));
// Test isLetterAt
Assertions.assertTrue(grid.isLetterAt(0, 0));
@@ -74,13 +74,6 @@ public class MainTest {
Assertions.assertEquals('A', grid.getCharAt(0, 0)); // Original should be unchanged
}
@Test
public void testGridOffset() {
var grid = new Grid(new byte[10 * 10], 10, 10);
Assertions.assertEquals(0, grid.getOffset(0, 0));
Assertions.assertEquals(11, grid.getOffset(1, 1));
Assertions.assertEquals(99, grid.getOffset(9, 9));
}
@Test
public void testMini() {
@@ -88,7 +81,7 @@ public class MainTest {
grid.setCharAt(1, 1, '1');
Assertions.assertTrue(grid.isDigitAt(1, 1));
}
@Test
public void testAttempt() {
// Arrange
var opts = new Main.Opts();