Gather data
This commit is contained in:
@@ -19,23 +19,27 @@ import java.util.function.Supplier;
|
||||
@SuppressWarnings("ALL")
|
||||
public record SwedishGenerator(int[] buff) {
|
||||
|
||||
static final int W = Config.PUZZLE_COLS;
|
||||
static final int H = Config.PUZZLE_ROWS;
|
||||
static final int SIZE = W * H;
|
||||
static final int MAX_WORD_LENGTH = Math.min(W, H);
|
||||
static final int MIN_LEN = Config.MIN_LEN;
|
||||
static final int CLUE_SIZE = Config.CLUE_SIZE;
|
||||
static final int SIMPLICITY_DEFAULT_SCORE = 2;
|
||||
static final int MAX_TRIES_PER_SLOT = Config.MAX_TRIES_PER_SLOT;
|
||||
static final char C_DASH = '\0';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
record CandidateInfo(int[] indices, int count) { }
|
||||
|
||||
record nbrs_8(int x, int y) { }
|
||||
|
||||
static final int W = Config.PUZZLE_COLS;
|
||||
static final double CROSS_Y = (W - 1) / 2.0;
|
||||
static final int H = Config.PUZZLE_ROWS;
|
||||
static final double CROSS_X = (H - 1) / 2.0;
|
||||
static final int SIZE = W * H;
|
||||
static final int MAX_WORD_LENGTH = Math.min(W, H);
|
||||
static final int MIN_LEN = Config.MIN_LEN;
|
||||
static final int CLUE_SIZE = Config.CLUE_SIZE;
|
||||
static final int SIMPLICITY_DEFAULT_SCORE = 2;
|
||||
static final int MAX_TRIES_PER_SLOT = Config.MAX_TRIES_PER_SLOT;
|
||||
static final char C_DASH = '\0';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
static final ThreadLocal<Context> CTX = ThreadLocal.withInitial(Context::new);
|
||||
static boolean isLetter(char ch) { return ch >= 'A' && ch <= 'Z'; }
|
||||
static int clamp(int x, int a, int b) { return Math.max(a, Math.min(b, x)); }
|
||||
static record CandidateInfo(int[] indices, int count) { }
|
||||
|
||||
static record nbrs_8(int x, int y) { }
|
||||
public SwedishGenerator() { this(new int[8124]); }
|
||||
public SwedishGenerator() { this(new int[8124]); }
|
||||
|
||||
// Directions for '1'..'6'
|
||||
static final nbrs_8[] OFFSETS = new nbrs_8[7];
|
||||
@@ -124,8 +128,10 @@ public record SwedishGenerator(int[] buff) {
|
||||
void setCharAt(int r, int c, char ch) { g[offset(r, c)] = (byte) ch; }
|
||||
boolean isLetterAt(int r, int c) { return ((g[offset(r, c)] & 64) != 0); }
|
||||
boolean isDigitAt(int r, int c) { return (g[offset(r, c)] & 48) == 48; }
|
||||
public int H() {
|
||||
return g.length / W;
|
||||
public double similarity(Grid b) {
|
||||
var same = 0;
|
||||
for (int i = 0; i < SIZE; i++) if (g[i] == b.g[i]) same++;
|
||||
return same / (double) (SIZE);
|
||||
}
|
||||
}
|
||||
static Grid makeEmptyGrid() { return new Grid(new byte[SIZE]); }
|
||||
@@ -260,7 +266,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
return new Dict(map.values().toArray(Lemma[]::new));
|
||||
}
|
||||
private 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)];
|
||||
int i = 0, j = 0, k = 0, x = 0, y = 0;
|
||||
while (i < aLen && j < bLen) {
|
||||
@@ -324,7 +330,6 @@ public record SwedishGenerator(int[] buff) {
|
||||
public boolean horiz() { return horiz(key); }
|
||||
public int r(int i) { return r(rs, i); }
|
||||
public int c(int i) { return c(cs, i); }
|
||||
|
||||
public static boolean horiz(int key) { return ((key & 15) & 1) == 0; }
|
||||
public static int r(long rs, int i) { return (int) ((rs >> (i << 2)) & 15); }
|
||||
public static int c(long cs, int i) { return (int) ((cs >> (i << 2)) & 15); }
|
||||
@@ -441,7 +446,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
if (lenCounts[n] <= 0) penalty += 12000;
|
||||
}
|
||||
|
||||
boolean horiz = Slot.horiz((r << 8) | (c << 4) | d);
|
||||
boolean horiz = Slot.horiz(d);
|
||||
for (var i = 0; i < n; i++) {
|
||||
int sr = Slot.r(packedRs, i);
|
||||
int sc = Slot.c(packedCs, i);
|
||||
@@ -563,17 +568,13 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
Grid crossover(Rng rng, Grid a, Grid b) {
|
||||
var out = makeEmptyGrid();
|
||||
var cx = (H - 1) / 2.0;
|
||||
var cy = (W - 1) / 2.0;
|
||||
var theta = rng.nextFloat() * Math.PI;
|
||||
var nx = Math.cos(theta);
|
||||
var ny = Math.sin(theta);
|
||||
|
||||
for (var r = 0; r < H; r++)
|
||||
for (var c = 0; c < W; c++) {
|
||||
double x = r - cx, y = c - cy;
|
||||
var side = x * nx + y * ny;
|
||||
out.setCharAt(r, c, (side >= 0) ? a.getCharAt(r, c) : b.getCharAt(r, c));
|
||||
out.setCharAt(r, c, ((r - CROSS_X) * nx + (c - CROSS_Y) * ny >= 0) ? a.getCharAt(r, c) : b.getCharAt(r, c));
|
||||
}
|
||||
|
||||
for (var r = 0; r < H; r++)
|
||||
@@ -602,12 +603,6 @@ public record SwedishGenerator(int[] buff) {
|
||||
return best;
|
||||
}
|
||||
|
||||
double similarity(Grid a, Grid b) {
|
||||
var same = 0;
|
||||
for (var r = 0; r < H; r++) for (var c = 0; c < W; c++) if (a.byteAt(r, c) == b.byteAt(r, c)) same++;
|
||||
return same / (double) (W * H);
|
||||
}
|
||||
|
||||
public Grid generateMask(Rng rng, int[] lenCounts, int popSize, int gens, boolean verbose) {
|
||||
if (verbose) System.out.println("generateMask init pop: " + popSize);
|
||||
var pop = new ArrayList<Grid>();
|
||||
@@ -637,7 +632,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
if (next.size() >= popSize) break;
|
||||
var ok = true;
|
||||
for (var kept : next) {
|
||||
if (similarity(cand, kept) > 0.92) {
|
||||
if (cand.similarity(kept) > 0.92) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
@@ -666,9 +661,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
public int lastMRV;
|
||||
}
|
||||
|
||||
record Pick(Slot slot,
|
||||
CandidateInfo info,
|
||||
boolean done) { }
|
||||
record Pick(Slot slot, CandidateInfo info, boolean done) { }
|
||||
|
||||
public static record FillResult(boolean ok,
|
||||
Grid grid,
|
||||
@@ -932,7 +925,4 @@ public record SwedishGenerator(int[] buff) {
|
||||
return s + " ".repeat(n - s.length());
|
||||
}
|
||||
|
||||
// ---------------- Top-level generatePuzzle ----------------
|
||||
public record PuzzleResult(SwedishGenerator swe, Dict dict, Grid mask, FillResult filled) { }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user