Gather data
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package puzzle;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import puzzle.ExportFormat.Bit;
|
||||
import puzzle.ExportFormat.Bit1029;
|
||||
import puzzle.ExportFormat.Gridded;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -50,7 +52,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
static final char C_DASH = '\0';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
static final ThreadLocal<Context> CTX = ThreadLocal.withInitial(Context::new);
|
||||
static boolean isLetter(byte b) { return b >= 'A' && b <= 'Z'; }
|
||||
static boolean isLetter(byte b) { return (b & 64) != 0; }
|
||||
static int clamp(int x, int a, int b) { return Math.max(a, Math.min(b, x)); }
|
||||
|
||||
public SwedishGenerator() { this(new int[8124]); }
|
||||
@@ -131,28 +133,24 @@ public record SwedishGenerator(int[] buff) {
|
||||
|
||||
record Grid(byte[] g) {
|
||||
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 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()); }
|
||||
char getCharAt(int r, int c) { return (char) (g[offset(r, c)]); }
|
||||
byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
byte byteAt(int pos) { return g[pos]; }
|
||||
byte byteAtStatic(int r, int c) { return g[offset(r, c)]; }
|
||||
void setCharAt(int r, int c, char ch) { g[offset(r, c)] = (byte) ch; }
|
||||
void setByteAt(int r, int c, byte ch) { g[offset(r, c)] = ch; }
|
||||
void setDigitAt(int r, int c, int ch) { g[offset(r, c)] = (byte) (_48 + ch); }
|
||||
void setCharAt(int idx, char ch) { g[idx] = (byte) ch; }
|
||||
void setByteAt(int idx, byte ch) { g[idx] = ch; }
|
||||
void clear(int r, int c) { g[offset(r, c)] = 0; }
|
||||
void clear(int idx) { g[idx] = 0; }
|
||||
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; }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 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()); }
|
||||
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 r, int c, byte ch) { g[offset(r, c)] = ch; }
|
||||
void setByteAt(int idx, byte ch) { g[idx] = ch; }
|
||||
void clear(int r, int c) { g[offset(r, c)] = DASH; }
|
||||
void clear(int idx) { g[idx] = DASH; }
|
||||
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 double similarity(Grid b) {
|
||||
var same = 0;
|
||||
for (int i = 0; i < SIZE; i++) if (g[i] == b.g[i]) same++;
|
||||
@@ -161,26 +159,6 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
static Grid makeEmptyGrid() { return new Grid(new byte[SIZE]); }
|
||||
|
||||
String gridToString(Grid g) {
|
||||
var sb = new StringBuilder();
|
||||
for (var r = 0; r < R; r++) {
|
||||
if (r > 0) sb.append('\n');
|
||||
for (var c = 0; c < C; c++) sb.append((char) g.byteAt(r, c));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String renderHuman(Grid g) {
|
||||
var sb = new StringBuilder();
|
||||
for (var r = 0; r < R; r++) {
|
||||
if (r > 0) sb.append('\n');
|
||||
for (var c = 0; c < C; c++) {
|
||||
sb.append(g.isDigitAt(r, c) ? ' ' : (char) g.byteAt(r, c));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static final class IntList {
|
||||
|
||||
int[] a = new int[8];
|
||||
@@ -717,12 +695,12 @@ public record SwedishGenerator(int[] buff) {
|
||||
record Pick(SwedishGenerator.Slot slot, SwedishGenerator.CandidateInfo info, boolean done) { }
|
||||
|
||||
public static record FillResult(boolean ok,
|
||||
Grid grid,
|
||||
Gridded grid,
|
||||
HashMap<Integer, SwedishGenerator.Lemma> clueMap,
|
||||
FillStats stats,
|
||||
double simplicity) {
|
||||
|
||||
public FillResult(boolean ok, Grid grid, HashMap<Integer, Lemma> assigned, FillStats stats) {
|
||||
public FillResult(boolean ok, Gridded grid, HashMap<Integer, Lemma> assigned, FillStats stats) {
|
||||
double totalSimplicity = 0;
|
||||
if (ok) {
|
||||
for (var w : assigned.values()) totalSimplicity += w.simpel;
|
||||
@@ -957,7 +935,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
|
||||
stats.seconds = (System.currentTimeMillis() - t0) / 1000.0;
|
||||
var res = new FillResult(ok, grid, assigned, stats);
|
||||
var res = new FillResult(ok, new Gridded(grid), assigned, stats);
|
||||
|
||||
// print a final progress line
|
||||
if (verbose && !multiThreaded) {
|
||||
|
||||
Reference in New Issue
Block a user