Gather data
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package puzzle;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -23,6 +29,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
record nbrs_8(int x, int y) { }
|
||||
|
||||
record nbrs_16(int x, int y, int dx, int dy) { }
|
||||
|
||||
static final int W = Config.PUZZLE_COLS;
|
||||
static final double CROSS_Y = (W - 1) / 2.0;
|
||||
static final int H = Config.PUZZLE_ROWS;
|
||||
@@ -42,29 +50,22 @@ public record SwedishGenerator(int[] buff) {
|
||||
public SwedishGenerator() { this(new int[8124]); }
|
||||
|
||||
// Directions for '1'..'6'
|
||||
static final nbrs_8[] OFFSETS = new nbrs_8[7];
|
||||
static final nbrs_8[] STEPS = new nbrs_8[7];
|
||||
static {
|
||||
// 1: up
|
||||
OFFSETS[1] = new nbrs_8(-1, 0);
|
||||
STEPS[1] = new nbrs_8(-1, 0);
|
||||
// 2: right
|
||||
OFFSETS[2] = new nbrs_8(0, 1);
|
||||
STEPS[2] = new nbrs_8(0, 1);
|
||||
// 3: down
|
||||
OFFSETS[3] = new nbrs_8(1, 0);
|
||||
STEPS[3] = new nbrs_8(1, 0);
|
||||
// 4: left
|
||||
OFFSETS[4] = new nbrs_8(0, -1);
|
||||
STEPS[4] = new nbrs_8(0, -1);
|
||||
// 5: vertical down, clue is on the right of the first letter
|
||||
OFFSETS[5] = new nbrs_8(0, -1);
|
||||
STEPS[5] = new nbrs_8(1, 0);
|
||||
// 6: vertical down, clue is on the left of the first letter
|
||||
OFFSETS[6] = new nbrs_8(0, 1);
|
||||
STEPS[6] = new nbrs_8(1, 0);
|
||||
}
|
||||
final static nbrs_8[] nbrs8 = new nbrs_8[]{
|
||||
static final nbrs_16[] OFFSETS = new nbrs_16[]{
|
||||
null,
|
||||
// 1: up
|
||||
new nbrs_16(-1, 0, -1, 0),
|
||||
// 2: right
|
||||
new nbrs_16(0, 1, 0, 1),
|
||||
// 3: down
|
||||
new nbrs_16(1, 0, 1, 0),
|
||||
// 4: left
|
||||
new nbrs_16(0, -1, 0, -1),
|
||||
// 5: vertical down, clue is on the right of the first letter
|
||||
new nbrs_16(0, -1, 1, 0),
|
||||
// 6: vertical down, clue is on the left of the first letter
|
||||
new nbrs_16(0, 1, 1, 0)
|
||||
};
|
||||
final static nbrs_8[] nbrs8 = new nbrs_8[]{
|
||||
new nbrs_8(-1, -1),
|
||||
new nbrs_8(-1, 0),
|
||||
new nbrs_8(-1, 1),
|
||||
@@ -74,7 +75,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
new nbrs_8(1, 0),
|
||||
new nbrs_8(1, 1)
|
||||
};
|
||||
static final nbrs_8[] nbrs4 = new nbrs_8[]{
|
||||
static final SwedishGenerator.nbrs_8[] nbrs4 = new nbrs_8[]{
|
||||
new nbrs_8(-1, 0),
|
||||
new nbrs_8(1, 0),
|
||||
new nbrs_8(0, -1),
|
||||
@@ -90,7 +91,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
IntList[] intListBuffer,
|
||||
long[] undoBuffer) {
|
||||
|
||||
public Context() { this(new int[256], new int[256], new int[256], new int[256], new BitSet(256), new char[32], new IntList[32], new long[2048]); }
|
||||
public Context() { this(new int[SIZE], new int[SIZE], new int[SIZE], new int[SIZE], new BitSet(128), new char[MAX_WORD_LENGTH], new IntList[MAX_WORD_LENGTH], new long[2048]); }
|
||||
void setPatter(char[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
|
||||
}
|
||||
|
||||
@@ -195,11 +196,11 @@ public record SwedishGenerator(int[] buff) {
|
||||
int[] lenCounts) {
|
||||
|
||||
public Dict(Lemma[] wordz) {
|
||||
Lemma[] lemmas = wordz.clone();
|
||||
var lemmas = wordz.clone();
|
||||
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
|
||||
|
||||
var lenCounts = new int[MAX_WORD_LENGTH+1];
|
||||
var index = new DictEntry[MAX_WORD_LENGTH+1];
|
||||
var lenCounts = new int[MAX_WORD_LENGTH + 1];
|
||||
var index = new DictEntry[MAX_WORD_LENGTH + 1];
|
||||
Arrays.setAll(index, i -> new DictEntry(i));
|
||||
int maxLength = -1;
|
||||
for (var lemma : lemmas) {
|
||||
@@ -229,8 +230,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
raw = "WOORD,level_1_to_10,hint\nEU,2,hint\nUUR,2,hint\nAUTO,2,hint\nBOOM,2,hint\nHUIS,2,hint\nKAT,2,hint\nZEE,2,hint\nRODE,2,hint\nDRAAD,2,hint\nKENNIS,2,hint\nNETWERK,2,hint\nPAKTE,2,hint\n";
|
||||
}
|
||||
|
||||
var map = new HashMap<String, Lemma>();
|
||||
boolean first = true;
|
||||
var map = new HashMap<String, Lemma>();
|
||||
var first = true;
|
||||
for (var line : raw.split("\\R")) {
|
||||
if (line.isBlank()) {
|
||||
System.err.println("Empty line: " + line);
|
||||
@@ -283,10 +284,10 @@ public record SwedishGenerator(int[] buff) {
|
||||
return Arrays.copyOf(buff, k);
|
||||
}
|
||||
|
||||
CandidateInfo candidateInfoForPattern(Context ctx, DictEntry entry, int len) {
|
||||
char[] pattern = ctx.pattern;
|
||||
var listBuffer = ctx.intListBuffer;
|
||||
int listCount = 0;
|
||||
SwedishGenerator.CandidateInfo candidateInfoForPattern(Context ctx, DictEntry entry, int len) {
|
||||
var pattern = ctx.pattern;
|
||||
var listBuffer = ctx.intListBuffer;
|
||||
var listCount = 0;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var ch = pattern[i];
|
||||
if (isLetter(ch)) {
|
||||
@@ -351,14 +352,11 @@ public record SwedishGenerator(int[] buff) {
|
||||
for (var r = 0; r < H; r++) {
|
||||
for (var c = 0; c < W; c++) {
|
||||
if (!grid.isDigitAt(r, c)) continue;
|
||||
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;
|
||||
if (grid.isDigitAt(rr, cc)) continue;
|
||||
var d = grid.digitAt(r, c);
|
||||
var nbrs16 = OFFSETS[d];
|
||||
int rr = r + nbrs16.x, cc = c + nbrs16.y;
|
||||
|
||||
if (rr < 0 || rr >= H || cc < 0 || cc >= W || grid.isDigitAt(rr, cc)) continue;
|
||||
long packedRs = 0;
|
||||
long packedCs = 0;
|
||||
var n = 0;
|
||||
@@ -367,8 +365,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
packedRs |= (long) rr << (n << 2);
|
||||
packedCs |= (long) cc << (n << 2);
|
||||
n++;
|
||||
rr += dr;
|
||||
cc += dc;
|
||||
rr += nbrs16.dx;
|
||||
cc += nbrs16.dy;
|
||||
}
|
||||
if (n > 0) {
|
||||
visitor.visit((r << 8) | (c << 4) | d, packedRs, packedCs, n);
|
||||
@@ -384,15 +382,13 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
|
||||
boolean hasRoomForClue(Grid grid, int r, int c, char d) {
|
||||
var di = d - '0';
|
||||
int or = OFFSETS[di].x, oc = OFFSETS[di].y;
|
||||
int dr = STEPS[di].x, dc = STEPS[di].y;
|
||||
int rr = r + or, cc = c + oc;
|
||||
var run = 0;
|
||||
var nbrs16 = OFFSETS[d - '0'];
|
||||
int rr = r + nbrs16.x, cc = c + nbrs16.y;
|
||||
var run = 0;
|
||||
while (rr >= 0 && rr < H && cc >= 0 && cc < W && (grid.isLettercell(rr, cc)) && run < MAX_WORD_LENGTH) {
|
||||
run++;
|
||||
rr += dr;
|
||||
cc += dc;
|
||||
rr += nbrs16.dx;
|
||||
cc += nbrs16.dy;
|
||||
if (run >= MIN_LEN) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -417,13 +413,10 @@ public record SwedishGenerator(int[] buff) {
|
||||
for (var r = 0; r < H; r++) {
|
||||
for (var c = 0; c < W; c++) {
|
||||
if (!grid.isDigitAt(r, c)) continue;
|
||||
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;
|
||||
if (grid.isDigitAt(rr, cc)) continue;
|
||||
var d = grid.digitAt(r, c);
|
||||
var nbrs16 = OFFSETS[d];
|
||||
int rr = r + nbrs16.x, cc = c + nbrs16.y;
|
||||
if (rr < 0 || rr >= H || cc < 0 || cc >= W || grid.isDigitAt(rr, cc)) continue;
|
||||
|
||||
long packedRs = 0;
|
||||
long packedCs = 0;
|
||||
@@ -434,8 +427,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
packedRs |= (long) rr << (n << 2);
|
||||
packedCs |= (long) cc << (n << 2);
|
||||
n++;
|
||||
rr += dr;
|
||||
cc += dc;
|
||||
rr += nbrs16.dx;
|
||||
cc += nbrs16.dy;
|
||||
}
|
||||
if (n == 0) continue;
|
||||
hasSlots = true;
|
||||
@@ -446,14 +439,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
if (lenCounts[n] <= 0) penalty += 12000;
|
||||
}
|
||||
|
||||
boolean horiz = Slot.horiz(d);
|
||||
for (var i = 0; i < n; i++) {
|
||||
int sr = Slot.r(packedRs, i);
|
||||
int sc = Slot.c(packedCs, i);
|
||||
int idx = grid.offset(sr, sc);
|
||||
if (horiz) covH[idx] += 1;
|
||||
else covV[idx] += 1;
|
||||
}
|
||||
var horiz = Slot.horiz(d) ? covH : covV;
|
||||
for (var i = 0; i < n; i++) horiz[grid.offset(Slot.r(packedRs, i), Slot.c(packedCs, i))] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,8 +706,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
|
||||
int logEveryMs, int timeLimitMs, boolean verbose) {
|
||||
boolean multiThreaded = Thread.currentThread().getName().contains("pool");
|
||||
var grid = mask.deepCopyGrid();
|
||||
var slots = extractSlots(grid);
|
||||
var grid = mask.deepCopyGrid();
|
||||
var slots = extractSlots(grid);
|
||||
|
||||
var used = new BitSet();
|
||||
var assigned = new HashMap<Integer, Lemma>();
|
||||
|
||||
Reference in New Issue
Block a user