introduce bitloops
This commit is contained in:
@@ -7,9 +7,9 @@ import lombok.val;
|
||||
import puzzle.Export.Gridded.Replacar.Cell;
|
||||
import puzzle.Export.LetterVisit.LetterAt;
|
||||
import puzzle.SwedishGenerator.Clues;
|
||||
import puzzle.SwedishGenerator.DictEntry;
|
||||
import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -44,7 +44,7 @@ public record Export() {
|
||||
|
||||
static final String INIT = IntStream.range(0, R).mapToObj(l_ -> " ").collect(Collectors.joining("\n"));
|
||||
|
||||
public record ClueAt(int index, int clue) { }
|
||||
public record ClueAt(int index, int clue) { }
|
||||
|
||||
public record Clued(@Delegate Clues c) {
|
||||
|
||||
@@ -62,14 +62,14 @@ public record Export() {
|
||||
}
|
||||
public Stream<ClueAt> stream() {
|
||||
val stream = Stream.<ClueAt>builder();
|
||||
for (var l = c.lo & ~c.rlo & c.vlo ; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 1));
|
||||
for (var l = c.lo & ~c.rlo & ~c.vlo ; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 0));
|
||||
for (var l = c.lo & c.rlo & ~c.vlo ; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 2));
|
||||
for (var l = c.lo & c.rlo & c.vlo ; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 3));
|
||||
for (var h = c.hi & ~c.rhi & c.vhi ; h != X; h &= h - 1) stream.accept(new ClueAt(64 | Long.numberOfTrailingZeros(h), 1));
|
||||
for (var h = c.hi & ~c.rhi & ~c.vhi ; h != X; h &= h - 1) stream.accept(new ClueAt(64 | Long.numberOfTrailingZeros(h), 0));
|
||||
for (var h = c.hi & c.rhi & ~c.vhi ; h != X; h &= h - 1) stream.accept(new ClueAt((64 | Long.numberOfTrailingZeros(h)), 2));
|
||||
for (var h = c.hi & c.rhi & c.vhi ; h != X; h &= h - 1) stream.accept(new ClueAt((64 | Long.numberOfTrailingZeros(h)), 3));
|
||||
for (var l = c.lo & ~c.rlo & c.vlo; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 1));
|
||||
for (var l = c.lo & ~c.rlo & ~c.vlo; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 0));
|
||||
for (var l = c.lo & c.rlo & ~c.vlo; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 2));
|
||||
for (var l = c.lo & c.rlo & c.vlo; l != X; l &= l - 1) stream.accept(new ClueAt(Long.numberOfTrailingZeros(l), 3));
|
||||
for (var h = c.hi & ~c.rhi & c.vhi; h != X; h &= h - 1) stream.accept(new ClueAt(64 | Long.numberOfTrailingZeros(h), 1));
|
||||
for (var h = c.hi & ~c.rhi & ~c.vhi; h != X; h &= h - 1) stream.accept(new ClueAt(64 | Long.numberOfTrailingZeros(h), 0));
|
||||
for (var h = c.hi & c.rhi & ~c.vhi; h != X; h &= h - 1) stream.accept(new ClueAt((64 | Long.numberOfTrailingZeros(h)), 2));
|
||||
for (var h = c.hi & c.rhi & c.vhi; h != X; h &= h - 1) stream.accept(new ClueAt((64 | Long.numberOfTrailingZeros(h)), 3));
|
||||
|
||||
return stream.build();
|
||||
}
|
||||
@@ -225,22 +225,23 @@ public record Export() {
|
||||
|
||||
public record ExportedPuzzle(String[] grid, WordOut[] words, int difficulty, Rewards rewards) { }
|
||||
|
||||
public record PuzzleResult(Clued clues, FillResult filled) {
|
||||
public record PuzzleResult(Clued clues, Slotinfo[] slots, FillResult filled) {
|
||||
|
||||
Placed extractPlacedFromSlot(Slot s, long lemma) { return new Placed(lemma, s.key(), s.walk().toArray()); }
|
||||
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
|
||||
var g = filled().grid();
|
||||
var placed = new ArrayList<Placed>();
|
||||
var clueMap = filled().clueMap();
|
||||
val entries = new DictEntry[10];
|
||||
clues.forEachSlot((int key, long lo, long hi) -> {
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user