introduce bitloops
This commit is contained in:
@@ -51,7 +51,7 @@ public record Export() {
|
||||
public Clued deepCopyGrid() { return new Clued(new Clues(c.lo, c.hi, c.vlo, c.vhi, c.rlo, c.rhi)); }
|
||||
String gridToString() {
|
||||
var sb = new StringBuilder(INIT);
|
||||
forEachSlot((s, l, a) -> {
|
||||
forEachSlot((s, _, _) -> {
|
||||
val idx = Slot.clueIndex(s);
|
||||
val r = idx & 7;
|
||||
val c = idx >>> 3;
|
||||
@@ -150,7 +150,7 @@ public record Export() {
|
||||
}
|
||||
String gridToString(Clues clues) {
|
||||
var sb = new StringBuilder(INIT);
|
||||
clues.forEachSlot((s, l, a) -> {
|
||||
clues.forEachSlot((s, _, _) -> {
|
||||
val idx = Slot.clueIndex(s);
|
||||
val r = idx & 7;
|
||||
val c = idx >>> 3;
|
||||
@@ -193,12 +193,11 @@ public record Export() {
|
||||
|
||||
interface Bit1029 {
|
||||
|
||||
public static long[] bit1029() { return new long[2048]; }
|
||||
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
|
||||
static public boolean get(long[] bits, int bitIndex) { return (bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
|
||||
static public void set(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
|
||||
static public void clear(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
|
||||
static public void clear(long[] bits) { Arrays.fill(bits, 0L); }
|
||||
static long[] bit1029() { return new long[2048]; }
|
||||
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
|
||||
static boolean get(long[] bits, int bitIndex) { return (bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
|
||||
static void set(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
|
||||
static void clear(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
|
||||
}
|
||||
|
||||
record Placed(long lemma, int slotKey, int[] cells) {
|
||||
@@ -228,21 +227,12 @@ public record Export() {
|
||||
public record PuzzleResult(Clued clues, Slotinfo[] slots, FillResult filled) {
|
||||
|
||||
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
|
||||
var g = filled().grid();
|
||||
var placed = new ArrayList<Placed>();
|
||||
var g = filled().grid();
|
||||
var placed = new ArrayList<Placed>();
|
||||
for (var slot : slots) {
|
||||
placed.add(new Placed(slot.assign().w, slot.key(), Gridded.walk((byte) slot.key(), slot.lo(), slot.hi()).toArray()));
|
||||
}
|
||||
|
||||
/* clues.forEachSlot((int key, long lo, long hi) -> {
|
||||
var word = clueMap[key];
|
||||
if (word != 0L) {
|
||||
placed.add(extractPlacedFromSlot(Slot.from(key, lo, hi, entries[Slot.length(lo, hi)]), word));
|
||||
} else {
|
||||
System.err.println("Could not find clue for slot: " + key);
|
||||
}
|
||||
});*/
|
||||
|
||||
// If nothing placed: return full grid mapped to letters/# only
|
||||
if (placed.isEmpty()) {
|
||||
return new ExportedPuzzle(g.exportGrid(clues.c, _ -> '#', '#'), new WordOut[0], difficulty, rewards);
|
||||
|
||||
@@ -377,7 +377,6 @@ public class Main {
|
||||
try {
|
||||
return _attempt(rng, dict, opts);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Failed to operate" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -973,7 +973,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
return true;
|
||||
}
|
||||
void chooseMRV() {
|
||||
SwedishGenerator.Slotinfo best = null;
|
||||
Slotinfo best = null;
|
||||
for (int i = 0, count, count2 = -1, bestScore = -1, n = TOTAL; i < n; i++) {
|
||||
var s = slots[i];
|
||||
if (s.assign.w != X) continue;
|
||||
@@ -1049,11 +1049,9 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
if (!placeWord(k, slo, shi, w)) continue;
|
||||
|
||||
Bit1029.set(used, lemIdx);
|
||||
//assigned[k] = w;
|
||||
s.assign.w = w;
|
||||
if (backtrack(depth + 1)) return true;
|
||||
s.assign.w = X;
|
||||
//assigned[k] = X;
|
||||
Bit1029.clear(used, lemIdx);
|
||||
glo = low;
|
||||
ghi = top;
|
||||
@@ -1073,15 +1071,13 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
low = glo;
|
||||
top = ghi;
|
||||
if (!placeWord(k, slo, shi, w)) continue;
|
||||
|
||||
|
||||
Bit1029.set(used, lemIdx);
|
||||
s.assign.w = w;
|
||||
//assigned[k] = w;
|
||||
|
||||
if (backtrack(depth + 1)) return true;
|
||||
s.assign.w = X;
|
||||
//assigned[k] = X;
|
||||
Bit1029.clear(used, lemIdx);
|
||||
|
||||
glo = low;
|
||||
ghi = top;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user