introduce bitloops

This commit is contained in:
mike
2026-01-21 06:12:05 +01:00
parent 386777e576
commit ebcbc9b33c
13 changed files with 35 additions and 407 deletions

View File

@@ -1,13 +0,0 @@
package puzzle;
import gen.GenDict;
@GenDict(
packageName = "puzzle.dict950",
className = "DictData950",
scv = "/home/mike/dev/puzzle-generator/nl_score_hints_v4.csv",
simpleMax = 950,
minLen = 2,
maxLen = 8
)
public class DictMark { }

View File

@@ -1,20 +0,0 @@
package puzzle;
import gen.GenerateDict;
@GenerateDict(
packageName = "puzzle",
packageNameDict = "puzzle",
classNameDict = "DictData",
className = "LemmaData",
scv = "nl_score_hints_v4.csv",
words = {
"EEN", "NAAR", "IEDEREEN", "A", "C", "X", "TEST", "IN", "INE", "INER", "INEREN", "INERENA", "INERENAE",
"APPLE", "AXE", "ABC", "ABD", "AZ", "AB",
"AT", "CAT", "DOGS", "APPLY", "BANAN", "BANANA", "BANANAS", "BANANASS"
},
simpleMax=900,
minLen = 2,
maxLen = 8
)
public class DictMarker { }

View File

@@ -251,8 +251,7 @@ public record Export() {
return new ExportedPuzzle(grid.exportGrid(_ -> '#', '#'), new WordOut[0], 1, rewards);
}
var placed = Arrays.stream(slots).map(slot -> new Placed(slot.assign().w, slot.key(), Gridded.cellWalk((byte) slot.key(), slot.lo(), slot.hi()).toArray())).toArray(
Placed[]::new);
var placed = Arrays.stream(slots).map(slot -> new Placed(slot.assign().w, slot.key(), Gridded.cellWalk((byte) slot.key(), slot.lo(), slot.hi()).toArray())).toArray(Placed[]::new);
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
int minR = Integer.MAX_VALUE, minC = Integer.MAX_VALUE;

View File

@@ -114,7 +114,6 @@ public class Main {
else rebuildIndex();
info("indexUpdated : " + INDEX_FILE);
} catch (IOException e) {
e.printStackTrace();
err("Failed to write: " + FILE_NAME);
err("Reason : " + e.getMessage());
System.exit(2);
@@ -345,7 +344,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;
}
@@ -445,7 +443,6 @@ public class Main {
Files.writeString(indexPath, content, StandardCharsets.UTF_8);
info("indexUpdated : " + indexPath);
} catch (IOException e) {
e.printStackTrace();
err("Failed to update index.json: " + e.getMessage());
}
}
@@ -486,12 +483,10 @@ public class Main {
var pathInIndex = "/puzzles/" + filename;
records.add(toIndexRecordJson(id, pathInIndex, date, theme, difficulty, createdAt));
} catch (IOException e) {
e.printStackTrace();
err("Failed to read " + path + ": " + e.getMessage());
}
});
} catch (IOException e) {
e.printStackTrace();
err("Failed to list puzzles: " + e.getMessage());
return;
}
@@ -502,7 +497,6 @@ public class Main {
Files.writeString(indexPath, content, StandardCharsets.UTF_8);
info("Successfully rebuilt index.json with " + records.size() + " records.");
} catch (IOException e) {
e.printStackTrace();
err("Failed to write index.json: " + e.getMessage());
}
}

View File

@@ -14,6 +14,10 @@ import static puzzle.SwedishGenerator.*;
public final class Masker {
public static final rci[] IT = Neighbors9x8.IT;
public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
public static final long[] PATH_HI = Neighbors9x8.PATH_HI;
public static final long MASK_LO = -1L;
public static final long MASK_HI = Neighbors9x8.MASK_HI;//(1L << (SIZE - 64)) - 1;
private final Rng rng;
private final int[] stack;
private final Clues cache;

View File

@@ -23,12 +23,6 @@ public class Meta {
static final ByteOrder ORDER = ByteOrder.BIG_ENDIAN;
static record ShardRec(String word, long w, int simpel, String[] clues) { }
static final Path projectRoot = Path.of("").toAbsolutePath().normalize(); // current working dir
//static final Path dir = projectRoot.resolve("src/main/resources/shards");
//static final Path shardData = dir.resolve("shard0.data");
//static final Path shardMap = dir.resolve("shard0.map");
static final Path dir = detectShardDir();
static final Path shardData = dir.resolve("shard0.data");
static final Path shardMap = dir.resolve("shard0.map");

View File

@@ -1,5 +1,8 @@
package puzzle;
import gen.GenDict;
import gen.GenerateConst;
import gen.GenerateNeighbors;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.val;
@@ -25,18 +28,24 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
* java SwedishGenerator [--seed N] [--pop N] [--gens N] [--tries N] [--words word-list.txt]
*/
@SuppressWarnings("ALL")
@GenerateNeighbors(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2)
@GenerateConst(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
@GenDict(
packageName = "puzzle.dict950",
className = "DictData950",
scv = "/home/mike/dev/puzzle-generator/nl_score_hints_v4.csv",
simpleMax = 950,
minLen = 2,
maxLen = 8
)
public record SwedishGenerator() {
public static final long X = 0L;
public static final int LOG_EVERY_MS = 200;
public static final int BAR_LEN = 22;
public static final int C = Neighbors9x8.C;
public static final int R = Neighbors9x8.R;
public static final int SIZE = Neighbors9x8.SIZE;// ~18
public static final int SIZE_MIN_1 = Neighbors9x8.SIZE_MIN_1;// ~18
public static final double SIZED = Neighbors9x8.SIZED;// ~18
public static final long MASK_LO = -1L;
public static final long MASK_HI = Neighbors9x8.MASK_HI;//(1L << (SIZE - 64)) - 1;
public static final int MAX_WORD_LENGTH = Neighbors9x8.R;
public static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
public static final int MIN_LEN = Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
@@ -65,9 +74,6 @@ public record SwedishGenerator() {
public static record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed, FillStats stats) { }
//@formatter:on
public static final long[] PATH_LO = Neighbors9x8.PATH_LO;
public static final long[] PATH_HI = Neighbors9x8.PATH_HI;
public static final class Rng {
private int x;
@@ -115,7 +121,6 @@ public record SwedishGenerator() {
return new String(bytes, 0, bi, US_ASCII);
}
static int unpackIndex(long w) { return (int) (w >>> 40); }
static int unpackShardIndex(long w) { return (int) (w >>> 43); }
static int unpackSize(long w) { return (int) (w >>> 40) & 7; }
static int unpackLetters(long w) { return (int) (w & LETTER_MASK); }
static long pack43(long w) {

View File

@@ -1,6 +0,0 @@
// file: app/Trigger.java
package puzzle;
import gen.GenerateConst;
@GenerateConst(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
public final class TriggerConstants { }

View File

@@ -1,5 +0,0 @@
package puzzle;
import gen.GenerateNeighbors;
@GenerateNeighbors(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2)
public final class TriggerNeighbors4x3 { }

View File

@@ -1,6 +0,0 @@
// file: app/Trigger.java
package puzzle;
import gen.GenerateNeighbors;
@GenerateNeighbors(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2)
public final class TriggerNeighbors9x8 { }