introduce bitloops
This commit is contained in:
@@ -41,7 +41,7 @@ import static java.nio.charset.StandardCharsets.*;
|
||||
* java SwedishGenerator [--seed N] [--pop N] [--gens N] [--tries N] [--words word-list.txt]
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
record CandidateInfo(int[] indices, int count) { }
|
||||
|
||||
@@ -283,6 +283,15 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
for (var l = lo; l != X; l &= l - 1) processSlot(this, visitor, Long.numberOfTrailingZeros(l));
|
||||
for (var h = hi; h != X; h &= h - 1) processSlot(this, visitor, 64 | Long.numberOfTrailingZeros(h));
|
||||
}
|
||||
public Clues from(Clues best) {
|
||||
lo = best.lo;
|
||||
hi = best.hi;
|
||||
vlo = best.vlo;
|
||||
vhi = best.vhi;
|
||||
rlo = best.rlo;
|
||||
rhi = best.rhi;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static record Grid(byte[] g, long lo, long hi) {
|
||||
@@ -605,8 +614,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
}
|
||||
return g;
|
||||
}
|
||||
Clues mutate(Clues clues) {
|
||||
var c = clues.deepCopyGrid();
|
||||
Clues mutate(Clues c) {
|
||||
int ri;
|
||||
var bytes = MUTATE_RI[rng.randint(0, SIZE_MIN_1)];
|
||||
for (var k = 0; k < 4; k++) {
|
||||
@@ -666,6 +674,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
var fails = 0;
|
||||
|
||||
while (fails < limit) {
|
||||
cache.from(best);
|
||||
var cand = mutate(best);
|
||||
var f = maskFitness(cand);
|
||||
if (f < bestF) {
|
||||
@@ -673,6 +682,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
bestF = f;
|
||||
fails = 0;
|
||||
} else {
|
||||
best.from(cache);
|
||||
fails++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user