Gather data
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package puzzle;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* SwedishGenerator.java
|
||||
@@ -15,22 +17,14 @@ import java.util.function.Predicate;
|
||||
* java SwedishGenerator [--seed N] [--pop N] [--gens N] [--tries N] [--words word-list.txt]
|
||||
*/
|
||||
@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, int[] buff) {
|
||||
|
||||
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 {
|
||||
|
||||
static byte[] EXAMPLE = new byte[0];
|
||||
}
|
||||
public SwedishGenerator {
|
||||
Data.EXAMPLE = new byte[SIZE];
|
||||
Arrays.fill(Data.EXAMPLE, DASH);
|
||||
}
|
||||
public SwedishGenerator(int W, int H) { this(W, H, W * H, Math.min(W, H)); }
|
||||
public SwedishGenerator(int W, int H) { this(W, H, W * H, Math.min(W, H), new int[10000]); }
|
||||
public SwedishGenerator() { this(9, 8); }
|
||||
|
||||
static final int CLUE_SIZE = 4,
|
||||
@@ -79,7 +73,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
static final char FIRST_ABC = 'A';
|
||||
static final char LAST_ABC = 'Z';
|
||||
static final char FIRST_ARROW = '1', LAST_ARROW = '6', HOR_ARROW_1 = '2', HOR_ARROW_2 = '4';
|
||||
static boolean isDigit(char ch) { return ch >= FIRST_ARROW && ch <= LAST_ARROW; }
|
||||
static boolean isLetter(char ch) { return ch >= FIRST_ABC && ch <= LAST_ABC; }
|
||||
|
||||
static final class Rng {
|
||||
@@ -112,15 +105,16 @@ 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; }
|
||||
private int offset(int r, int c) { return r * W + c; }
|
||||
boolean isLettercell(int r, int c) { return !isDigitAt(r, c); }
|
||||
char getCharAt(int r, int c) { return (char) (g[getOffset(r, c)] & 0xFF); }
|
||||
byte byteAt(int r, int c) { return g[getOffset(r, c)]; }
|
||||
void setCharAt(int r, int c, char ch) { g[getOffset(r, c)] = (byte) ch; }
|
||||
boolean isLetterAt(int r, int c) { return ((g[getOffset(r, c)] & 64) != 0); }
|
||||
boolean isDigitAt(int r, int c) { return (g[getOffset(r, c)] & 48) == 48; }
|
||||
char getCharAt(int r, int c) { return (char) (g[offset(r, c)] & 0xFF); }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
|
||||
byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
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; }
|
||||
}
|
||||
Grid makeEmptyGrid() { return new Grid(Data.EXAMPLE.clone(), H, W); }
|
||||
Grid makeEmptyGrid() { return new Grid(new byte[SIZE], H, W); }
|
||||
|
||||
String gridToString(Grid g) {
|
||||
var sb = new StringBuilder();
|
||||
@@ -252,23 +246,23 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
|
||||
return new Dict(map.values().toArray(Lemma[]::new));
|
||||
}
|
||||
|
||||
static int[] intersectSorted(int[] a, int aLen, int[] b, int bLen) {
|
||||
var out = new int[Math.min(aLen, bLen)];
|
||||
int i = 0, j = 0, k = 0;
|
||||
int[] intersectSorted(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) {
|
||||
int x = a[i], y = b[j];
|
||||
x = a[i];
|
||||
y = b[j];
|
||||
if (x == y) {
|
||||
out[k++] = x;
|
||||
buff[k++] = x;
|
||||
i++;
|
||||
j++;
|
||||
} else if (x < y) i++;
|
||||
else j++;
|
||||
}
|
||||
return Arrays.copyOf(out, k);
|
||||
return Arrays.copyOf(buff, k);
|
||||
}
|
||||
|
||||
static CandidateInfo candidateInfoForPattern(DictEntry entry, char[] pattern /* 0 means null */) {
|
||||
CandidateInfo candidateInfoForPattern(DictEntry entry, char[] pattern ) {
|
||||
var lists = new ArrayList<IntList>();
|
||||
for (var i = 0; i < pattern.length; i++) {
|
||||
var ch = pattern[i];
|
||||
@@ -296,10 +290,10 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
|
||||
return new CandidateInfo(cur, curLen);
|
||||
}
|
||||
static record Slot(String key, int clueR, int clueC, char dir, int[] rs, int[] cs, int len, boolean horiz) {
|
||||
static record Slot(String key, int clueR, int clueC, int dir, int[] rs, int[] cs, int len, boolean horiz) {
|
||||
|
||||
public Slot(int clueR, int clueC, char dir, int[] rs, int[] cs) {
|
||||
this(clueR + "," + clueC + ":" + dir, clueR, clueC, dir, rs, cs, rs.length, dir == HOR_ARROW_1 || dir == HOR_ARROW_2);
|
||||
public Slot(int clueR, int clueC, int d, int[] rs, int[] cs) {
|
||||
this(clueR + "," + clueC + ":" + d, clueR, clueC, d, rs, cs, rs.length, d == 2 || d == 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,10 +302,9 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
for (var r = 0; r < H; r++) {
|
||||
for (var c = 0; c < W; c++) {
|
||||
if (!grid.isDigitAt(r, c)) continue;
|
||||
var d = grid.getCharAt(r, c);
|
||||
var dir = d - '0';
|
||||
int or = OFFSETS[dir].x, oc = OFFSETS[dir].y;
|
||||
int dr = STEPS[dir].x, dc = STEPS[dir].y;
|
||||
var d = grid.digitAt(r, c);
|
||||
int or = OFFSETS[d].x, oc = OFFSETS[d].y;
|
||||
int dr = STEPS[d].x, dc = STEPS[d].y;
|
||||
|
||||
int rr = r + or, cc = c + oc;
|
||||
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
|
||||
@@ -502,8 +495,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN) {
|
||||
|
||||
for (var r = 0; r < H; r++)
|
||||
for (var c = 0; c < W; c++) {
|
||||
var ch = out.getCharAt(r, c);
|
||||
if (isDigit(ch) && !hasRoomForClue(out, r, c, ch)) out.setCharAt(r, c, C_DASH);
|
||||
if (out.isDigitAt(r, c) && !hasRoomForClue(out, r, c, out.getCharAt(r, c))) out.setCharAt(r, c, C_DASH);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user