introduce bitloops

This commit is contained in:
mike
2026-01-17 04:18:35 +01:00
parent 81ea708345
commit 47b33af09d
8 changed files with 680 additions and 676 deletions

View File

@@ -6,7 +6,7 @@ import lombok.experimental.Delegate;
import lombok.val;
import puzzle.Export.Gridded.Replacar.Cell;
import puzzle.Export.LetterVisit.LetterAt;
import puzzle.SwedishGenerator.Clues;
import puzzle.Masker.Clues;
import puzzle.SwedishGenerator.FillResult;
import puzzle.SwedishGenerator.Grid;
import puzzle.SwedishGenerator.Slotinfo;
@@ -19,7 +19,7 @@ import java.util.stream.IntStream;
import java.util.stream.Stream;
import static puzzle.SwedishGenerator.R;
import static puzzle.SwedishGenerator.Lemma;
import static puzzle.SwedishGenerator.Slot;
import static puzzle.Masker.Slot;
import static puzzle.SwedishGenerator.C;
import static puzzle.SwedishGenerator.X;
@@ -100,7 +100,7 @@ public record Export() {
for (var h = grid.hi & ~clues.hi; h != X; h &= h - 1) visitor.visit(64 | Long.numberOfTrailingZeros(h), grid.g);
}
public static IntStream walk(byte base, long lo, long hi) {
if (Slot.increasing(base)) {
if (Slotinfo.increasing(base)) {
return IntStream.concat(
IntStream.generate(new IntSupplier() {
@@ -209,7 +209,7 @@ public record Export() {
public int arrowRow() { return SwedishGenerator.IT[Slot.clueIndex(slotKey)].r(); }
public int startRow() { return SwedishGenerator.IT[cells[0]].r(); }
public int startCol() { return SwedishGenerator.IT[cells[0]].c(); }
public boolean isReversed() { return !Slot.increasing(slotKey); }
public boolean isReversed() { return !Slotinfo.increasing(slotKey); }
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
}
@@ -224,10 +224,9 @@ public record Export() {
public record ExportedPuzzle(String[] grid, WordOut[] words, int difficulty, Rewards rewards) { }
public record PuzzleResult(Clued clues, Slotinfo[] slots, FillResult filled) {
public record PuzzleResult(Clued clues, Gridded grid, Slotinfo[] slots, FillResult filled) {
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
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()));
@@ -235,7 +234,7 @@ public record Export() {
// 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);
return new ExportedPuzzle(grid.exportGrid(clues.c, _ -> '#', '#'), new WordOut[0], difficulty, rewards);
}
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
@@ -259,7 +258,7 @@ public record Export() {
// 3) map of only used letter cells (everything else becomes '#')
var letterAt = new HashMap<Integer, Character>();
g.forEachLetter(clues.c(), (idx, letter) -> {
grid.forEachLetter(clues.c(), (idx, letter) -> {
if (letter == 0) return;
letterAt.put(idx, (char) (64 | letter));
});