initial commit

This commit is contained in:
mike
2025-12-19 14:34:13 +01:00
parent 6f0a04f0a1
commit bd6a5a1d2e
8 changed files with 422 additions and 62 deletions

72
src/puzzle/Main.java Normal file
View File

@@ -0,0 +1,72 @@
package puzzle;
public class Main {
// ---------------- CLI ----------------
public static class Opts {
public int seed = 1;
public int pop = 18;
public int gens = 100;
public int tries = 50;
public String wordsPath = "./word-list.txt";
}
static void usage() {
System.out.println("""
Usage:
java SwedishGenerator [--seed N] [--pop N] [--gens N] [--tries N] [--words word-list.txt]
Defaults:
--seed 1
--pop 18
--gens 100
--tries 50
--words ./word-list.txt
""");
}
static Opts parseArgs(String[] argv) {
var out = new Opts();
for (int i = 0; i < argv.length; i++) {
String a = argv[i];
String v = (i + 1 < argv.length) ? argv[i + 1] : null;
if (a.equals("--help") || a.equals("-h")) {
usage();
System.exit(0);
}
if (a.equals("--seed")) { out.seed = Integer.parseInt(v); i++; }
else if (a.equals("--pop")) { out.pop = Integer.parseInt(v); i++; }
else if (a.equals("--gens")) { out.gens = Integer.parseInt(v); i++; }
else if (a.equals("--tries")) { out.tries = Integer.parseInt(v); i++; }
else if (a.equals("--words")) { out.wordsPath = v; i++; }
else throw new IllegalArgumentException("Unknown arg: " + a);
}
return out;
}
public static void main(String[] args) {
var opts = parseArgs(args);
var res = SwedishGenerator.generatePuzzle(opts);
if (res == null) {
System.out.println("No solution found within tries.");
System.exit(1);
}
System.out.println("\n=== GENERATED MASK ===");
System.out.println(SwedishGenerator.gridToString(res.mask));
System.out.println("\n=== FILLED PUZZLE (RAW) ===");
System.out.println(SwedishGenerator.gridToString(res.filled.grid));
System.out.println("\n=== FILLED PUZZLE (HUMAN) ===");
System.out.println(SwedishGenerator.renderHuman(res.filled.grid));
var out = ExportFormat.exportFormatFromFilled(res, 1, new ExportFormat.Rewards(50, 2, 1));
System.out.println("gridv2:");
for (String row : out.gridv2) System.out.println(row);
System.out.println("words: " + out.words.size());
for (var w : out.words) {
System.out.printf("%s %s start=(%d,%d) arrow=(%d,%d)%n",
w.word, w.direction, w.startRow, w.startCol, w.arrowRow, w.arrowCol);
}
}
}