Gather data
This commit is contained in:
@@ -47,7 +47,7 @@ public record Export() {
|
||||
for (var r = 0; r < R; r++) {
|
||||
if (r > 0) sb.append('\n');
|
||||
for (var c = 0; c < C; c++) {
|
||||
sb.append(grid.isDigitAt(r, c) ? ' ' : (char) grid.byteAt(Grid.offset(r, c)));
|
||||
sb.append(grid.isDigitAt(Grid.offset(r, c)) ? ' ' : (char) grid.byteAt(Grid.offset(r, c)));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -158,7 +158,7 @@ public record Export() {
|
||||
for (var r = 0; r < R; r++) {
|
||||
var sb = new StringBuilder(C);
|
||||
for (var c = 0; c < C; c++) {
|
||||
sb.append(g.isLetterAt(r, c) ? (char) g.byteAt(Grid.offset(r, c)) : '#');
|
||||
sb.append(g.isLetterAt(r,c) ? (char) g.byteAt(Grid.offset(r, c)) : '#');
|
||||
}
|
||||
gridv2.add(sb.toString());
|
||||
}
|
||||
@@ -188,8 +188,9 @@ public record Export() {
|
||||
for (var p : placed) {
|
||||
for (var c : p.cells) {
|
||||
int rr = Grid.r(c), cc = Grid.c(c);
|
||||
if (inBounds(rr, cc) && g.isLetterAt(rr, cc)) {
|
||||
letterAt.put(Bit.pack(rr, cc), (char) g.byteAt(Grid.offset(rr, cc)));
|
||||
int idx = Grid.offset(rr,cc);
|
||||
if (inBounds(rr, cc) && g.isLetterAt(idx)) {
|
||||
letterAt.put(Bit.pack(rr, cc), (char) g.byteAt(idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ public record SwedishGenerator(Rng rng) {
|
||||
@FunctionalInterface interface SlotVisitor { void visit(int key, long packedPos, int len); }
|
||||
//@formatter:on
|
||||
static final int BAR_LEN = 22;
|
||||
static final int C = Config.PUZZLE_COLS;
|
||||
static final double CROSS_R = (C - 1) / 2.0;
|
||||
static final int R = Config.PUZZLE_ROWS;
|
||||
static final double CROSS_C = (R - 1) / 2.0;
|
||||
static final int SIZE = C * R;// ~18
|
||||
static final int C = Config.PUZZLE_COLS;
|
||||
static final double CROSS_R = (C - 1) / 2.0;
|
||||
static final int R = Config.PUZZLE_ROWS;
|
||||
static final double CROSS_C = (R - 1) / 2.0;
|
||||
static final int SIZE = C * R;// ~18
|
||||
static final double SIZED = (double) SIZE;// ~18
|
||||
static final int TARGET_CLUES = SIZE >> 2;
|
||||
static final int MAX_WORD_LENGTH = C <= R ? C : R;
|
||||
@@ -198,18 +198,17 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
record Grid(byte[] g, long[] bo) {
|
||||
|
||||
public Grid(byte[] g) { this(g, new long[2]); }
|
||||
static Grid createEmpty() { return new Grid(new byte[SIZE], new long[2]); }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
|
||||
int digitAt(int index) { return g[index] - 48; }
|
||||
public static int r(int offset) { return offset & 7; }
|
||||
public static int c(int offset) { return offset >>> 3; }
|
||||
static int offset(int r, int c) { return r | (c << 3); }
|
||||
Grid deepCopyGrid() { return new Grid(g.clone(), bo.clone()); }
|
||||
public byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
public byte byteAt(int pos) { return g[pos]; }
|
||||
void setCharAt(int r, int c, char ch) { g[offset(r, c)] = (byte) ch; }
|
||||
void setByteAt(int idx, byte ch) { g[idx] = ch; }
|
||||
public Grid(byte[] g) { this(g, new long[2]); }
|
||||
static Grid createEmpty() { return new Grid(new byte[SIZE], new long[2]); }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
|
||||
int digitAt(int index) { return g[index] - 48; }
|
||||
public static int r(int offset) { return offset & 7; }
|
||||
public static int c(int offset) { return offset >>> 3; }
|
||||
static int offset(int r, int c) { return r | (c << 3); }
|
||||
Grid deepCopyGrid() { return new Grid(g.clone(), bo.clone()); }
|
||||
public byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
public byte byteAt(int pos) { return g[pos]; }
|
||||
void setByteAt(int idx, byte ch) { g[idx] = ch; }
|
||||
void setAt(int idx, byte ch) {
|
||||
if (isDigit(ch)) setClue(idx, ch);
|
||||
else g[idx] = ch;
|
||||
@@ -225,18 +224,18 @@ public record SwedishGenerator(Rng rng) {
|
||||
if (idx < 64) bo[0] &= ~(1L << idx);
|
||||
else bo[1] &= ~(1L << (idx & 63));
|
||||
}
|
||||
public 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; }
|
||||
boolean isDigitAt(int index) { return (g[index] & 48) == 48; }
|
||||
static boolean isDigit(byte b) { return (b & 48) == 48; }
|
||||
boolean isLettercell(int r, int c) { return (g[offset(r, c)] & 48) != 48; }
|
||||
boolean isLetterAt(int index) { return (g[index] & 48) != 48; }
|
||||
public boolean isLetterAt(int r, int c) { return ((g[offset(r, c)] & 64) != 0); }
|
||||
public boolean isLetterAt(int index) { return (g[index] & 48) != 48; }
|
||||
public double similarity(Grid b) {
|
||||
var same = 0;
|
||||
for (int i = 0; i < SIZE; i++) if (g[i] == b.g[i]) same++;
|
||||
return same / SIZED;
|
||||
}
|
||||
int clueCount() { return Long.bitCount(bo[0]) + Long.bitCount(bo[1]); }
|
||||
int clueCount() { return Long.bitCount(bo[0]) + Long.bitCount(bo[1]); }
|
||||
|
||||
void forEachSetBit71(IntConsumer consumer) {
|
||||
for (var lo = bo[0]; lo != 0; lo &= lo - 1) consumer.accept(Long.numberOfTrailingZeros(lo));
|
||||
|
||||
Reference in New Issue
Block a user