Gather data
This commit is contained in:
@@ -167,9 +167,34 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
if (idx < 64) bo[0] &= ~(1L << idx);
|
if (idx < 64) bo[0] &= ~(1L << idx);
|
||||||
else bo[1] &= ~(1L << (idx & 63));
|
else bo[1] &= ~(1L << (idx & 63));
|
||||||
}
|
}
|
||||||
static boolean isDigit(byte b) { return (b & 48) == 48; }
|
static boolean isDigit(byte b) { return (b & 48) == 48; }
|
||||||
boolean isDigitAt(int r, int c) { return isDigit(g[offset(r, c)]); }
|
boolean isDigitAt(int r, int c) { return isDigit(g[offset(r, c)]); }
|
||||||
boolean isDigitAt(int index) { return isDigit(g[index]); }
|
boolean isDigitAt(int index) { return isDigit(g[index]); }
|
||||||
|
boolean isClue(int index) {
|
||||||
|
if (index < 64) {
|
||||||
|
return (bo[0] >> index & 1L) != 0;
|
||||||
|
}
|
||||||
|
return (bo[1] >> (index & 63) & 1L) != 0;
|
||||||
|
}
|
||||||
|
boolean clueless(int idx) {
|
||||||
|
if (idx < 64) {
|
||||||
|
val test = (1L << idx);
|
||||||
|
if ((test & bo[0]) != 0L) {
|
||||||
|
g[idx] = DASH;
|
||||||
|
bo[0] &= ~test;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
val test = (1L << (idx & 63));
|
||||||
|
if ((test & bo[1]) != 0L) {
|
||||||
|
g[idx] = DASH;
|
||||||
|
bo[1] &= ~test;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
static boolean isLetter(byte b) { return (b & 64) != 0; }
|
static boolean isLetter(byte b) { return (b & 64) != 0; }
|
||||||
public boolean isLetterSet(int r, int c) { return isLetter(g[offset(r, c)]); }
|
public boolean isLetterSet(int r, int c) { return isLetter(g[offset(r, c)]); }
|
||||||
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||||
@@ -436,16 +461,6 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
|
|
||||||
if (!hasSlots) return 1_000_000_000L;
|
if (!hasSlots) return 1_000_000_000L;
|
||||||
|
|
||||||
int idx, h, v;
|
|
||||||
for (idx = 0; idx < SIZE; idx++) {
|
|
||||||
if (grid.isDigitAt(idx)) continue;
|
|
||||||
h = covH[idx];
|
|
||||||
v = covV[idx];
|
|
||||||
if (h == 0 && v == 0) penalty[0] += 1500;
|
|
||||||
else if (h > 0 && v > 0) { /* ok */ } else if (h + v == 1) penalty[0] += 200;
|
|
||||||
else penalty[0] += 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clue clustering (8-connected)
|
// clue clustering (8-connected)
|
||||||
var seen = ctx.seen;
|
var seen = ctx.seen;
|
||||||
seen.clear();
|
seen.clear();
|
||||||
@@ -488,23 +503,26 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
}
|
}
|
||||||
if (walls >= 3) penalty[0] += 400;
|
if (walls >= 3) penalty[0] += 400;
|
||||||
}*/
|
}*/
|
||||||
|
int h, v;
|
||||||
for (var rci : IT) {
|
for (var rci : IT) {
|
||||||
if (grid.isDigitAt(rci.i())) continue;
|
if (grid.isDigitAt(rci.i())) continue;
|
||||||
walls = (4 - rci.nbrCount()) + Long.bitCount(rci.n1() & grid.bo[0]) + Long.bitCount(rci.n2() & grid.bo[1]);
|
if ((4 - rci.nbrCount()) + Long.bitCount(rci.n1() & grid.bo[0]) + Long.bitCount(rci.n2() & grid.bo[1]) >= 3) penalty[0] += 400;
|
||||||
if (walls >= 3) penalty[0] += 400;
|
h = covH[rci.i()];
|
||||||
|
v = covV[rci.i()];
|
||||||
|
if (h == 0 && v == 0) penalty[0] += 1500;
|
||||||
|
else if (h > 0 && v > 0) { /* ok */ }
|
||||||
|
else if (h + v == 1) penalty[0] += 200;
|
||||||
|
else penalty[0] += 600;
|
||||||
}
|
}
|
||||||
return penalty[0];
|
return penalty[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Grid randomMask() {
|
Grid randomMask() {
|
||||||
var g = Grid.createEmpty();
|
var g = Grid.createEmpty();
|
||||||
int placed = 0, guard = 0;
|
for (int placed = 0, guard = 0, idx; placed < TARGET_CLUES && guard < 4000; guard++) {
|
||||||
|
idx = Grid.offset(rng.randint(0, R - 1),
|
||||||
while (placed < TARGET_CLUES && guard++ < 4000) {
|
rng.randint(0, C - 1));
|
||||||
var idx = Grid.offset(rng.randint(0, R - 1),
|
if (g.isClue(idx)) continue;
|
||||||
rng.randint(0, C - 1));
|
|
||||||
if (g.isDigitAt(idx)) continue;
|
|
||||||
var d = OFFSETS[rng.randbyte(1, 4)];
|
var d = OFFSETS[rng.randbyte(1, 4)];
|
||||||
|
|
||||||
if (hasRoomForClue(g, idx, d)) {
|
if (hasRoomForClue(g, idx, d)) {
|
||||||
@@ -525,9 +543,7 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
clamp(cx + (rng.randint(-2, 2) + rng.randint(-2, 2)), 0, R - 1),
|
clamp(cx + (rng.randint(-2, 2) + rng.randint(-2, 2)), 0, R - 1),
|
||||||
clamp(cy + (rng.randint(-2, 2) + rng.randint(-2, 2)), 0, C - 1));
|
clamp(cy + (rng.randint(-2, 2) + rng.randint(-2, 2)), 0, C - 1));
|
||||||
|
|
||||||
if (g.isDigitAt(ri)) {
|
if (!g.clueless(ri)) {
|
||||||
g.clearClue(ri);
|
|
||||||
} else {
|
|
||||||
var d = OFFSETS[rng.randint(1, 4)];
|
var d = OFFSETS[rng.randint(1, 4)];
|
||||||
if (hasRoomForClue(g, ri, d)) g.setClue(ri, d.dbyte());
|
if (hasRoomForClue(g, ri, d)) g.setClue(ri, d.dbyte());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user