Gather data
This commit is contained in:
@@ -42,12 +42,11 @@ public final class ExportFormat {
|
|||||||
|
|
||||||
// If nothing placed: return full grid mapped to letters/# only
|
// If nothing placed: return full grid mapped to letters/# only
|
||||||
if (placed.isEmpty()) {
|
if (placed.isEmpty()) {
|
||||||
List<String> gridv2 = new ArrayList<>(H);
|
var gridv2 = new ArrayList<String>(H);
|
||||||
for (var r = 0; r < H; r++) {
|
for (var r = 0; r < H; r++) {
|
||||||
var sb = new StringBuilder(W);
|
var sb = new StringBuilder(W);
|
||||||
for (var c = 0; c < W; c++) {
|
for (var c = 0; c < W; c++) {
|
||||||
var ch = g.getCharAt(r, c);
|
sb.append(g.isLetterAt(r, c) ? g.getCharAt(r, c) : '#');
|
||||||
sb.append(isLetter(ch) ? ch : '#');
|
|
||||||
}
|
}
|
||||||
gridv2.add(sb.toString());
|
gridv2.add(sb.toString());
|
||||||
}
|
}
|
||||||
@@ -165,7 +164,7 @@ public final class ExportFormat {
|
|||||||
return new Placed(
|
return new Placed(
|
||||||
lemma,
|
lemma,
|
||||||
lemma.word(),
|
lemma.word(),
|
||||||
lemma.clue()/*dict.words()[lemma.index()].clue()*/.toArray(String[]::new), // clue placeholder
|
lemma.clue().toArray(String[]::new),
|
||||||
startRow,
|
startRow,
|
||||||
startCol,
|
startCol,
|
||||||
direction,
|
direction,
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import java.util.function.Predicate;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||||
public static final char C_DASH = '#';
|
|
||||||
|
public static final char C_DASH = '\0';
|
||||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||||
|
|
||||||
record nbrs_8(int x, int y) { }
|
record nbrs_8(int x, int y) { }
|
||||||
|
|
||||||
class Data {
|
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) {
|
record Grid(byte[] g, int H, int W) {
|
||||||
|
|
||||||
|
|
||||||
Grid deepCopyGrid() { return new Grid(g.clone(), H, W); }
|
Grid deepCopyGrid() { return new Grid(g.clone(), H, W); }
|
||||||
private int getOffset(int r, int c) { return r * W + c; }
|
private int getOffset(int r, int c) { return r * W + c; }
|
||||||
boolean isLettercell(int r, int c) { return !isDigitAt(r, 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++) {
|
for (var r = 0; r < H; r++) {
|
||||||
if (r > 0) sb.append('\n');
|
if (r > 0) sb.append('\n');
|
||||||
for (var c = 0; c < W; c++) {
|
for (var c = 0; c < W; c++) {
|
||||||
var ch = g.getCharAt(r, c);
|
sb.append(g.isDigitAt(r, c) ? ' ' : g.getCharAt(r, c));
|
||||||
sb.append(isDigit(ch) ? ' ' : ch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
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;
|
static int LEMMA_COUNTER = 0;
|
||||||
public Lemma(int index, String word, int simpel, int score, String clue) {
|
public Lemma(int index, String word, int simpel, int score, String clu) {
|
||||||
var complex = 0 + ((8 - word.length()) * 30) + ((10 - score) * 15);
|
this(index, word, word.length(), simpel, new ArrayList<String>(10));
|
||||||
var list = new ArrayList<String>(10);
|
clue.add(clu);
|
||||||
list.add(clue);
|
|
||||||
this(index, word, word.length(), complex, simpel, score, list);
|
|
||||||
}
|
}
|
||||||
public Lemma(String word, int simpel, int score, String clue) { this(LEMMA_COUNTER++, word, simpel, score, clue); }
|
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); }
|
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) {
|
int[] lenCounts) {
|
||||||
|
|
||||||
public Dict(Lemma[] wordz) {
|
public Dict(Lemma[] wordz) {
|
||||||
// Sort words by difficulty in ascending order
|
|
||||||
Lemma[] lemmas = wordz.clone();
|
Lemma[] lemmas = wordz.clone();
|
||||||
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
|
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>();
|
var map = new HashMap<String, Lemma>();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (var line : raw.split("\\R")) {
|
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 parts = line.split(",", 4);
|
||||||
var word = parts[0].trim();
|
var word = parts[0].trim();
|
||||||
if (first && word.equalsIgnoreCase("WOORD")) {
|
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>();
|
var lists = new ArrayList<IntList>();
|
||||||
for (var i = 0; i < pattern.length; i++) {
|
for (var i = 0; i < pattern.length; i++) {
|
||||||
var ch = pattern[i];
|
var ch = pattern[i];
|
||||||
if (ch != 0 && isLetter(ch)) {
|
if (isLetter(ch)) {
|
||||||
lists.add(entry.pos[i][ch - 'A']);
|
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) {
|
public FillResult(boolean ok, Grid grid, HashMap<String, Lemma> assigned, FillStats stats) {
|
||||||
double totalSimplicity = 0;
|
double totalSimplicity = 0;
|
||||||
if (ok) {
|
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();
|
totalSimplicity = assigned.isEmpty() ? 0 : totalSimplicity / assigned.size();
|
||||||
}
|
}
|
||||||
this(ok, grid, assigned, stats, totalSimplicity);
|
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];
|
var pat = new char[s.len];
|
||||||
for (var i = 0; i < s.len; i++) {
|
for (var i = 0; i < s.len; i++) {
|
||||||
var ch = grid.getCharAt(s.rs[i], s.cs[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;
|
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;
|
if (used.get(w.index())) return false;
|
||||||
|
|
||||||
for (var i = 0; i < pat.length; i++) {
|
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);
|
var undo = placeWord(grid, s, w);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import puzzle.SwedishGenerator.Lemma;
|
|||||||
import puzzle.SwedishGenerator.PuzzleResult;
|
import puzzle.SwedishGenerator.PuzzleResult;
|
||||||
import puzzle.SwedishGenerator.Rng;
|
import puzzle.SwedishGenerator.Rng;
|
||||||
import static puzzle.Main.indentLines;
|
import static puzzle.Main.indentLines;
|
||||||
|
import static puzzle.SwedishGenerator.C_DASH;
|
||||||
|
|
||||||
public class MainTest {
|
public class MainTest {
|
||||||
|
|
||||||
@@ -15,7 +16,6 @@ public class MainTest {
|
|||||||
MainTest t = new MainTest();
|
MainTest t = new MainTest();
|
||||||
t.testGridBasics();
|
t.testGridBasics();
|
||||||
t.testGridDeepCopy();
|
t.testGridDeepCopy();
|
||||||
t.testGridOffset();
|
|
||||||
t.testMini();
|
t.testMini();
|
||||||
t.testAttempt();
|
t.testAttempt();
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ public class MainTest {
|
|||||||
// Initialize with #
|
// Initialize with #
|
||||||
for (int r = 0; r < 3; r++) {
|
for (int r = 0; r < 3; r++) {
|
||||||
for (int c = 0; c < 4; c++) {
|
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('A', grid.getCharAt(0, 0));
|
||||||
Assertions.assertEquals('5', grid.getCharAt(1, 2));
|
Assertions.assertEquals('5', grid.getCharAt(1, 2));
|
||||||
Assertions.assertEquals('Z', grid.getCharAt(2, 3));
|
Assertions.assertEquals('Z', grid.getCharAt(2, 3));
|
||||||
Assertions.assertEquals('#', grid.getCharAt(1, 1));
|
Assertions.assertEquals(C_DASH, grid.getCharAt(1, 1));
|
||||||
|
|
||||||
// Test isLetterAt
|
// Test isLetterAt
|
||||||
Assertions.assertTrue(grid.isLetterAt(0, 0));
|
Assertions.assertTrue(grid.isLetterAt(0, 0));
|
||||||
@@ -74,13 +74,6 @@ public class MainTest {
|
|||||||
Assertions.assertEquals('A', grid.getCharAt(0, 0)); // Original should be unchanged
|
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
|
@Test
|
||||||
public void testMini() {
|
public void testMini() {
|
||||||
@@ -88,7 +81,7 @@ public class MainTest {
|
|||||||
grid.setCharAt(1, 1, '1');
|
grid.setCharAt(1, 1, '1');
|
||||||
Assertions.assertTrue(grid.isDigitAt(1, 1));
|
Assertions.assertTrue(grid.isDigitAt(1, 1));
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
public void testAttempt() {
|
public void testAttempt() {
|
||||||
// Arrange
|
// Arrange
|
||||||
var opts = new Main.Opts();
|
var opts = new Main.Opts();
|
||||||
|
|||||||
Reference in New Issue
Block a user