Gather data
This commit is contained in:
@@ -291,18 +291,26 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
|
|
||||||
return new CandidateInfo(cur, curLen);
|
return new CandidateInfo(cur, curLen);
|
||||||
}
|
}
|
||||||
static record Slot(String key, int clueR, int clueC, int dir, long rs, long cs, int len, boolean horiz) {
|
static record Slot(int key, long rs, long cs, int len) {
|
||||||
|
|
||||||
public Slot(int clueR, int clueC, int d, long rs, long cs, int len) {
|
public Slot(int clueR, int clueC, int d, long rs, long cs, int len) {
|
||||||
this(clueR + "," + clueC + ":" + d, clueR, clueC, d, rs, cs, len, d == 2 || d == 4);
|
this((clueR << 8) | (clueC << 4) | d, rs, cs, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int clueR() { return (key >> 8) & 15; }
|
||||||
|
public int clueC() { return (key >> 4) & 15; }
|
||||||
|
public int dir() { return key & 15; }
|
||||||
|
public boolean horiz() {
|
||||||
|
return (dir() & 1) == 0;
|
||||||
|
/* var d = dir();
|
||||||
|
return d == 2 || d == 4;*/
|
||||||
|
}
|
||||||
public int r(int i) { return (int) ((rs >> (i << 2)) & 15); }
|
public int r(int i) { return (int) ((rs >> (i << 2)) & 15); }
|
||||||
public int c(int i) { return (int) ((cs >> (i << 2)) & 15); }
|
public int c(int i) { return (int) ((cs >> (i << 2)) & 15); }
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Slot> extractSlots(Grid grid) {
|
ArrayList<Slot> extractSlots(Grid grid) {
|
||||||
var slots = new ArrayList<Slot>();
|
var slots = new ArrayList<Slot>(64);
|
||||||
for (var r = 0; r < H; r++) {
|
for (var r = 0; r < H; r++) {
|
||||||
for (var c = 0; c < W; c++) {
|
for (var c = 0; c < W; c++) {
|
||||||
if (!grid.isDigitAt(r, c)) continue;
|
if (!grid.isDigitAt(r, c)) continue;
|
||||||
@@ -364,16 +372,20 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
var covV = new int[H][W];
|
var covV = new int[H][W];
|
||||||
|
|
||||||
for (var s : slots) {
|
for (var s : slots) {
|
||||||
if (s.len < MIN_LEN) penalty += 8000;
|
if (s.len < MIN_LEN) {
|
||||||
if (s.len > MAX_LEN) penalty += 8000 + (long) (s.len - MAX_LEN) * 500L;
|
penalty += 8000;
|
||||||
|
}
|
||||||
if (s.len >= MIN_LEN && s.len <= MAX_LEN) {
|
/* else if (s.len > MAX_LEN) {
|
||||||
|
penalty += 8000 + (long) (s.len - MAX_LEN) * 500L;
|
||||||
|
throw new RuntimeException();
|
||||||
|
}*/
|
||||||
|
else {
|
||||||
if (lenCounts[s.len] <= 0) penalty += 12000;
|
if (lenCounts[s.len] <= 0) penalty += 12000;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < s.len; i++) {
|
for (var i = 0; i < s.len; i++) {
|
||||||
int r = s.r(i), c = s.c(i);
|
int r = s.r(i), c = s.c(i);
|
||||||
if (s.horiz) covH[r][c] += 1;
|
if (s.horiz()) covH[r][c] += 1;
|
||||||
else covV[r][c] += 1;
|
else covV[r][c] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,11 +609,11 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
|
|
||||||
public static final record FillResult(boolean ok,
|
public static final record FillResult(boolean ok,
|
||||||
Grid grid,
|
Grid grid,
|
||||||
HashMap<String, Lemma> clueMap,
|
HashMap<Integer, Lemma> clueMap,
|
||||||
FillStats stats,
|
FillStats stats,
|
||||||
double simplicity) {
|
double simplicity) {
|
||||||
|
|
||||||
public FillResult(boolean ok, Grid grid, HashMap<String, Lemma> assigned, FillStats stats) {
|
public FillResult(boolean ok, Grid grid, HashMap<Integer, Lemma> assigned, FillStats stats) {
|
||||||
double totalSimplicity = 0;
|
double totalSimplicity = 0;
|
||||||
if (ok) {
|
if (ok) {
|
||||||
for (var w : assigned.values()) totalSimplicity += w.simpel;
|
for (var w : assigned.values()) totalSimplicity += w.simpel;
|
||||||
@@ -628,9 +640,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
|
|
||||||
static Undo placeWord(Grid grid, Slot s, Lemma w) {
|
static Undo placeWord(Grid grid, Slot s, Lemma w) {
|
||||||
var ur = new UndoPlace[s.len];
|
var ur = new UndoPlace[s.len];
|
||||||
/* var urs = new int[s.len];
|
|
||||||
var ucs = new int[s.len];
|
|
||||||
var up = new char[s.len];*/
|
|
||||||
var n = 0;
|
var n = 0;
|
||||||
|
|
||||||
for (var i = 0; i < s.len; i++) {
|
for (var i = 0; i < s.len; i++) {
|
||||||
@@ -639,9 +648,6 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
var ch = w.charAt(i);
|
var ch = w.charAt(i);
|
||||||
if (cur == C_DASH) {
|
if (cur == C_DASH) {
|
||||||
ur[n] = new UndoPlace(r, c, C_DASH);
|
ur[n] = new UndoPlace(r, c, C_DASH);
|
||||||
/*urs[n] = r;
|
|
||||||
ucs[n] = c;
|
|
||||||
up[n] = C_DASH;*/
|
|
||||||
n++;
|
n++;
|
||||||
grid.setCharAt(r, c, ch);
|
grid.setCharAt(r, c, ch);
|
||||||
} else {
|
} else {
|
||||||
@@ -663,12 +669,10 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
|
|||||||
int logEveryMs, int timeLimitMs, boolean verbose) {
|
int logEveryMs, int timeLimitMs, boolean verbose) {
|
||||||
|
|
||||||
var grid = mask.deepCopyGrid();
|
var grid = mask.deepCopyGrid();
|
||||||
var allSlots = extractSlots(grid);
|
var slots = extractSlots(grid);
|
||||||
var slots = new ArrayList<Slot>();
|
|
||||||
for (var s : allSlots) if (s.len >= MIN_LEN && s.len <= MAX_LEN) slots.add(s);
|
|
||||||
|
|
||||||
var used = new BitSet();
|
var used = new BitSet();
|
||||||
var assigned = new HashMap<String, Lemma>();
|
var assigned = new HashMap<Integer, Lemma>();
|
||||||
|
|
||||||
var cellCount = new int[H][W];
|
var cellCount = new int[H][W];
|
||||||
for (var s : slots) for (var i = 0; i < s.len; i++) cellCount[s.r(i)][s.c(i)]++;
|
for (var s : slots) for (var i = 0; i < s.len; i++) cellCount[s.r(i)][s.c(i)]++;
|
||||||
|
|||||||
18
src/test/java/puzzle/SlotTest.java
Normal file
18
src/test/java/puzzle/SlotTest.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package puzzle;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import puzzle.SwedishGenerator.Slot;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class SlotTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHoriz() {
|
||||||
|
assertTrue(new Slot(0, 0, 2, 0L, 0L, 5).horiz());
|
||||||
|
assertTrue(new Slot(0, 0, 4, 0L, 0L, 5).horiz());
|
||||||
|
assertFalse(new Slot(0, 0, 1, 0L, 3L, 5).horiz());
|
||||||
|
assertFalse(new Slot(0, 0, 3, 0L, 3L, 5).horiz());
|
||||||
|
assertFalse(new Slot(0, 0, 5, 0L, 3L, 5).horiz());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user