This commit is contained in:
mike
2026-01-24 00:46:10 +01:00
parent 2a5b70896e
commit 3cc6570cdc
11 changed files with 88 additions and 72 deletions

View File

@@ -4,7 +4,7 @@
<module name="tools" /> <module name="tools" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="puzzle.*" /> <option name="PATTERN" value="precomp.*" />
<option name="ENABLED" value="true" /> <option name="ENABLED" value="true" />
</pattern> </pattern>
</extension> </extension>

View File

@@ -0,0 +1,17 @@
package precomp;
public sealed interface Mask
permits Const9x8.Cell, Const3x4.Cell, Mask.Masker {
record Masker(long lo, long hi, int index, int r, int c, byte d)
implements precomp.Mask { }
default Mask or(Mask o) { return new Masker(o.lo() | lo(), o.hi() | hi(), 0, 0, 0, (byte) 0); }
default Mask and(Mask o) { return new Masker(o.lo() & lo(), o.hi() & hi(), 0, 0, 0, (byte) 0); }
long hi();
long lo();
int index();
int r();
int c();
byte d();
}

View File

@@ -4,6 +4,7 @@ import anno.ConstGen;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import precomp.Mask;
import static java.lang.Long.bitCount; import static java.lang.Long.bitCount;
import static puzzle.SwedishGenerator.X; import static puzzle.SwedishGenerator.X;
//@formatter:on //@formatter:on

View File

@@ -6,6 +6,7 @@ import anno.Shaped;
import lombok.experimental.Delegate; import lombok.experimental.Delegate;
import lombok.val; import lombok.val;
import precomp.Const9x8; import precomp.Const9x8;
import precomp.Mask;
import puzzle.Riddle.ClueSign; import puzzle.Riddle.ClueSign;
import puzzle.Riddle.ExportedPuzzle; import puzzle.Riddle.ExportedPuzzle;
import puzzle.Riddle.Placed; import puzzle.Riddle.Placed;
@@ -17,6 +18,9 @@ import puzzle.SwedishGenerator.Grid;
import puzzle.SwedishGenerator.Slotinfo; import puzzle.SwedishGenerator.Slotinfo;
import static puzzle.Masker.Slot; import static puzzle.Masker.Slot;
import static puzzle.SwedishGenerator.X; import static puzzle.SwedishGenerator.X;
import puzzle.SwedishGenerator.Lemma;
import java.util.stream.Stream;
import java.util.Arrays;
@GenerateShapedCopies( @GenerateShapedCopies(
packageName = "puzzle", packageName = "puzzle",
@@ -48,14 +52,6 @@ public record Export() {
static int INDEX_COL(int idx) { return idx / R; } static int INDEX_COL(int idx) { return idx / R; }
static int INDEX(int idx, int cols) { return INDEX_ROW(idx) * cols + INDEX_COL(idx); } static int INDEX(int idx, int cols) { return INDEX_ROW(idx) * cols + INDEX_COL(idx); }
record Lettrix(int index, byte letter) {
public int row() { return INDEX_ROW(index); }
public int col() { return INDEX_COL(index); }
public byte human() { return LETTER(letter); }
static Lettrix from(int index, byte[] bytes) { return new Lettrix(index, bytes[index]); }
public int index(int cols) { return (row() * cols) + col(); }
}
public static String gridToString(Clues clues) { public static String gridToString(Clues clues) {
val chars = BYTES.get().table(); val chars = BYTES.get().table();
var signa = new Signa(clues); var signa = new Signa(clues);
@@ -65,17 +61,30 @@ public record Export() {
return result; return result;
} }
record Puzzle(@Delegate Grid grid, Clues cl) record Puzzle(@Delegate Grid grid, Mask[] cells, Clues cl)
implements Stream<Lettrix> { implements Stream<Mask> {
public Puzzle(Clues clues) { this(new Grid(new byte[SIZE], clues.lo, clues.hi), clues); } public Puzzle {
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) set(Long.numberOfTrailingZeros(l), cells, grid.g);
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) set(HI(Long.numberOfTrailingZeros(h)), cells, grid.g);
new Signa(cl).forEach(v -> cells[v.index()] = CELLS[v.index() * 33 + 27 + Slot.dir(v.clue())]);
}
static void set(int idx, Mask[] cells, byte[] read) { cells[idx] = CELLS[idx * 33 + read[idx]]; }
public Puzzle(Grid grid, Clues cl) { this(grid, new Mask[grid.g.length], cl); }
public Puzzle(Clues clues) { this(new Grid(new byte[SIZE], clues.lo, clues.hi), new Mask[SIZE], clues); }
public Puzzle(Signa clues) { this(clues.c()); } public Puzzle(Signa clues) { this(clues.c()); }
public @Delegate Stream<Lettrix> stream() { public @Delegate Stream<Mask> stream() {
val stream = Stream.<Lettrix>builder(); val stream = Stream.<Mask>builder();
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) stream.accept(Lettrix.from(Long.numberOfTrailingZeros(l), grid.g)); for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) stream.accept(cells[Long.numberOfTrailingZeros(l)]);
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(Lettrix.from(HI(Long.numberOfTrailingZeros(h)), grid.g)); for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(cells[HI(Long.numberOfTrailingZeros(h))]);
return stream.build(); return stream.build();
} }
public Puzzle sync() {
for (var l = grid.lo & MASK_LO & ~cl.lo; l != X; l &= l - 1) set(Long.numberOfTrailingZeros(l), cells, grid.g);
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) set(HI(Long.numberOfTrailingZeros(h)), cells, grid.g);
new Signa(cl).forEach(v -> cells[v.index()] = CELLS[v.index() * 33 + 27 + Slot.dir(v.clue())]);
return this;
}
} }
public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) { public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) {
@@ -83,19 +92,19 @@ public record Export() {
public String exportGrid(ClueSign clueChar, byte[] template) { public String exportGrid(ClueSign clueChar, byte[] template) {
var sb = template.clone(); var sb = template.clone();
for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key()))); for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key())));
puzzle.forEach((l) -> sb[l.index(C + 1)] = l.human()); puzzle.forEach((l) -> sb[INDEX(l.index(), C + 1)] = LETTER(l.d()));
return new String(sb); return new String(sb);
} }
public String cluesGridToString() { return gridToString(clues.c()); } public String cluesGridToString() { return gridToString(clues.c()); }
public String gridRenderHuman() { return exportGrid(_ -> SPACE, INIT_GRID_OUTPUT_DASH_ARR); } public String gridRenderHuman() { return exportGrid(_ -> SPACE, INIT_GRID_OUTPUT_DASH_ARR); }
public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); } public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); }
public ExportedPuzzle exportFormatFromFilled(Rewards rewards, rci[] rcis) { public ExportedPuzzle exportFormatFromFilled(Rewards rewards) {
if (slots.length == 0) { if (slots.length == 0) {
return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards); return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards);
} }
var placed = Arrays.stream(slots) var placed = Arrays.stream(slots)
.map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi()).mapToObj(i -> rcis[i]).toArray(rci[]::new))) .map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi()).mapToObj(idx-> puzzle.cells[idx]).toArray(Mask[]::new)))
.toArray(Placed[]::new); .toArray(Placed[]::new);
// 2) bounding box around all word cells + arrow cells, with 1-cell margin // 2) bounding box around all word cells + arrow cells, with 1-cell margin
@@ -120,10 +129,10 @@ public record Export() {
for (int i = width; i < template.length; i += width + 1) template[i] = LINE_BREAK; for (int i = width; i < template.length; i += width + 1) template[i] = LINE_BREAK;
puzzle.forEach(l -> { puzzle.forEach(l -> {
int rr = l.row() - MINR; int rr = l.r() - MINR;
int cc = l.col() - MINC; int cc = l.c() - MINC;
if (rr >= 0 && rr < height && cc >= 0 && cc < width) { if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
template[rr * (width + 1) + cc] = l.human(); template[rr * (width + 1) + cc] = LETTER(l.d());
} }
}); });
var grid = new String(template).split("\n"); var grid = new String(template).split("\n");

View File

@@ -106,7 +106,7 @@ public class Main {
section("Grid (human)"); section("Grid (human)");
System.out.print(indentLines(res.gridRenderHuman())); System.out.print(indentLines(res.gridRenderHuman()));
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1), Masker.IT); var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1));
section("Clues"); section("Clues");
info("status : generating..."); info("status : generating...");

View File

@@ -1,14 +0,0 @@
package puzzle;
public interface Mask {
record Masker(long lo, long hi,int index,byte d)
implements Mask { }
default Mask or(Mask o) { return new Masker(o.lo() | lo(), o.hi() | hi(), 0, (byte) 0); }
default Mask and(Mask o) { return new Masker(o.lo() & lo(), o.hi() & hi(), 0, (byte) 0); }
long hi();
long lo();
int index();
byte d();
}

View File

@@ -3,6 +3,7 @@ package puzzle;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.experimental.Delegate; import lombok.experimental.Delegate;
import lombok.val; import lombok.val;
import precomp.Mask;
import puzzle.Masker.Slot; import puzzle.Masker.Slot;
import puzzle.Meta.ShardLem; import puzzle.Meta.ShardLem;
import puzzle.SwedishGenerator.Lemma; import puzzle.SwedishGenerator.Lemma;
@@ -87,20 +88,6 @@ public class Riddle {
public record Vestigium(int index, int clue) { } public record Vestigium(int index, int clue) { }
record Placed(long lemma, int slotKey, rci[] cells) {
public static final char HORIZONTAL = 'h';
static final char VERTICAL = 'v';
static final char[] DIRECTION = { Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.VERTICAL };
public int arrowCol() { return cells[0].c(); }
public int arrowRow() { return cells[0].r(); }
public int startRow() { return cells[1].r(); }
public int startCol() { return cells[1].c(); }
public boolean isReversed() { return !Slotinfo.increasing(slotKey); }
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
}
public record ExportedPuzzle(String[] grid, WordOut[] words, int difficulty, Rewards rewards) { } public record ExportedPuzzle(String[] grid, WordOut[] words, int difficulty, Rewards rewards) { }
public record Rewards(int coins, int stars, int hints) { } public record Rewards(int coins, int stars, int hints) { }
@@ -174,4 +161,18 @@ public class Riddle {
return stream.build(); return stream.build();
} }
} }
public record Placed(long lemma, int slotKey, Mask[] cells) {
public static final char HORIZONTAL = 'h';
static final char VERTICAL = 'v';
static final char[] DIRECTION = { Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.VERTICAL };
public int arrowCol() { return cells[0].c(); }
public int arrowRow() { return cells[0].r(); }
public int startRow() { return cells[1].r(); }
public int startCol() { return cells[1].c(); }
public boolean isReversed() { return !Slotinfo.increasing(slotKey); }
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
}
} }

View File

@@ -5,7 +5,7 @@ import anno.DictGen;
import lombok.val; import lombok.val;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import puzzle.Export.Lettrix; import precomp.Mask;
import puzzle.Export.Puzzle; import puzzle.Export.Puzzle;
import puzzle.Export.PuzzleResult; import puzzle.Export.PuzzleResult;
import puzzle.Main.Opts; import puzzle.Main.Opts;
@@ -148,7 +148,7 @@ public class MainTest {
r1c1.or(r0c1).lo(); r1c1.or(r0c1).lo();
// Test set/get // Test set/get
GridBuilder.placeWord(grid.grid(), grid.grid().g, r2c1d2.slotKey, (1L << OFF_1_1) | (1L << OFF_0_1), 0, AZ); GridBuilder.placeWord(grid.grid(), grid.grid().g, r2c1d2.slotKey, (1L << OFF_1_1) | (1L << OFF_0_1), 0, AZ);
val map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); val map = new Puzzle(grid.grid(), clues.c()).collect(Collectors.toMap(Mask::index, Mask::d));
Assertions.assertEquals(LETTER_A, map.get(OFF_1_1)); Assertions.assertEquals(LETTER_A, map.get(OFF_1_1));
Assertions.assertEquals(LETTER_Z, map.get(OFF_0_1)); Assertions.assertEquals(LETTER_Z, map.get(OFF_0_1));
var clueMap = clues.stream().collect(Collectors.toMap(Riddle.Vestigium::index, Riddle.Vestigium::clue)); var clueMap = clues.stream().collect(Collectors.toMap(Riddle.Vestigium::index, Riddle.Vestigium::clue));
@@ -233,9 +233,11 @@ public class MainTest {
Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get().wordBytes())); Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get().wordBytes()));
Assertions.assertEquals(74732156493031040L, grid.lo); Assertions.assertEquals(74732156493031040L, grid.lo);
Assertions.assertEquals(193L, grid.hi); Assertions.assertEquals(193L, grid.hi);
grid.lo = ~mask.c().lo;
grid.hi = 0xFFL & ~mask.c().hi;
var g = new Puzzle(grid, mask.c()); var g = new Puzzle(grid, mask.c());
var result = new PuzzleResult(mask, g, slotInfo, filled); var result = new PuzzleResult(mask, g, slotInfo, filled);
var aa = result.exportFormatFromFilled(new Rewards(1, 1, 1), Masker.IT); var aa = result.exportFormatFromFilled(new Rewards(1, 1, 1));
result.gridGridToString(); result.gridGridToString();
System.out.println(String.join("\n", aa.grid())); System.out.println(String.join("\n", aa.grid()));

View File

@@ -311,21 +311,21 @@ public class MarkerTest {
@Test @Test
void testExportFormatFromFilled() { void testExportFormatFromFilled() {
val clues = Riddle.Signa.of(r0c0d1, r0c5d3); val clues = Riddle.Signa.of(r0c0d1, r0c5d3);
var grid = new Puzzle(clues); var puzzle = new Puzzle(clues);
// key = (cellIndex << 2) | (direction) // key = (cellIndex << 2) | (direction)
var key = r0c0d1.slotKey; var key = r0c0d1.slotKey;
var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4); var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4);
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST)); assertTrue(placeWord(puzzle.grid(), puzzle.grid().g, key, lo, 0L, TEST));
var fillResult = new FillResult(true, 0, 0, 0, 0); var fillResult = new FillResult(true, 0, 0, 0, 0);
var puzzleResult = new PuzzleResult(clues, grid, new Slotinfo[]{ var puzzleResult = new PuzzleResult(clues, new Puzzle(puzzle.grid(), puzzle.cl()), new Slotinfo[]{
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null, 0) new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null, 0)
}, fillResult); }, fillResult);
var rewards = new Rewards(10, 5, 1); var rewards = new Rewards(10, 5, 1);
var exported = puzzleResult.exportFormatFromFilled(rewards, Masker.IT); var exported = puzzleResult.exportFormatFromFilled(rewards);
assertNotNull(exported); assertNotNull(exported);
assertEquals(709, exported.difficulty()); assertEquals(709, exported.difficulty());
@@ -364,7 +364,7 @@ public class MarkerTest {
var fillResult = new FillResult(true, 0, 0, 0, 0); var fillResult = new FillResult(true, 0, 0, 0, 0);
var puzzleResult = new PuzzleResult(new Signa(clues), new Puzzle(grid, clues), new Slotinfo[0], fillResult); var puzzleResult = new PuzzleResult(new Signa(clues), new Puzzle(grid, clues), new Slotinfo[0], fillResult);
var exported = puzzleResult.exportFormatFromFilled(new Rewards(0, 0, 0), Masker.IT); var exported = puzzleResult.exportFormatFromFilled(new Rewards(0, 0, 0));
assertNotNull(exported); assertNotNull(exported);
assertEquals(0, exported.words().length); assertEquals(0, exported.words().length);

View File

@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import precomp.Neighbors9x8; import precomp.Neighbors9x8;
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO; import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
import puzzle.Export.Lettrix; import precomp.Mask;
import puzzle.Export.Puzzle; import puzzle.Export.Puzzle;
import puzzle.Riddle.Signa; import puzzle.Riddle.Signa;
import puzzle.Masker.Slot; import puzzle.Masker.Slot;
@@ -128,7 +128,7 @@ public class SwedishGeneratorTest {
void testPatternForSlotAllLetters() { void testPatternForSlotAllLetters() {
var grid = new Puzzle(Riddle.Signa.of(r0c0d1)); var grid = new Puzzle(Riddle.Signa.of(r0c0d1));
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).or(r0c3).lo(), X, ABC); GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).or(r0c3).lo(), X, ABC);
val map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); val map = grid.sync().collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(LETTER_A, map.get(OFF_0_1)); assertEquals(LETTER_A, map.get(OFF_0_1));
assertEquals(LETTER_B, map.get(OFF_0_2)); assertEquals(LETTER_B, map.get(OFF_0_2));
assertEquals(LETTER_C, map.get(OFF_0_3)); assertEquals(LETTER_C, map.get(OFF_0_3));
@@ -160,9 +160,9 @@ public class SwedishGeneratorTest {
@Test @Test
void testGrid() { void testGrid() {
var grid = new Puzzle(Clues.createEmpty()); var p = new Puzzle(Clues.createEmpty());
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0d0.mask, X, WORD_A); GridBuilder.placeWord(p.grid(), p.grid().g, r0c0d1.slotKey, r0c0d0.mask, X, WORD_A);
val arr = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); val arr = p.sync().collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(1, arr.size()); assertEquals(1, arr.size());
assertEquals(LETTER_A, arr.get(OFF_0_0)); assertEquals(LETTER_A, arr.get(OFF_0_0));
} }
@@ -286,7 +286,7 @@ public class SwedishGeneratorTest {
var grid = new Puzzle(Clues.createEmpty()); var grid = new Puzzle(Clues.createEmpty());
assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC)); assertTrue(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC));
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); var map = new Puzzle(grid.grid(), grid.cl()).collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(3, map.size()); assertEquals(3, map.size());
assertEquals(LETTER_A, map.get(OFF_0_0)); assertEquals(LETTER_A, map.get(OFF_0_0));
assertEquals(LETTER_B, map.get(OFF_0_1)); assertEquals(LETTER_B, map.get(OFF_0_1));
@@ -297,7 +297,7 @@ public class SwedishGeneratorTest {
// 3. Conflict: place "ABD" where "ABC" is // 3. Conflict: place "ABD" where "ABC" is
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABD)); assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABD));
// Verify grid is unchanged (still "ABC") // Verify grid is unchanged (still "ABC")
map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); map = new Puzzle(grid.grid(), grid.cl()).collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(3, map.size()); assertEquals(3, map.size());
assertEquals(LETTER_A, map.get(OFF_0_0)); assertEquals(LETTER_A, map.get(OFF_0_0));
assertEquals(LETTER_B, map.get(OFF_0_1)); assertEquals(LETTER_B, map.get(OFF_0_1));
@@ -307,7 +307,7 @@ public class SwedishGeneratorTest {
grid = new Puzzle(Clues.createEmpty()); grid = new Puzzle(Clues.createEmpty());
GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, 1L << OFF_0_2, 0, WORD_X); // Conflict at the end GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, 1L << OFF_0_2, 0, WORD_X); // Conflict at the end
assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC)); assertFalse(GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c0.or(r0c1).or(r0c2).lo(), X, ABC));
map = grid.stream().collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); map = new Puzzle(grid.grid(), grid.cl()).collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(1, map.size()); assertEquals(1, map.size());
assertEquals(LETTER_X, map.get(OFF_0_2)); assertEquals(LETTER_X, map.get(OFF_0_2));
} }
@@ -321,14 +321,14 @@ public class SwedishGeneratorTest {
var placed = GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).lo(), X, AZ); var placed = GridBuilder.placeWord(grid.grid(), grid.grid().g, r0c0d1.slotKey, r0c1.or(r0c2).lo(), X, AZ);
assertTrue(placed); assertTrue(placed);
var map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); var map = new Puzzle(grid.grid(), grid.cl()).collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(2, map.size()); assertEquals(2, map.size());
assertEquals(LETTER_A, map.get(OFF_0_1)); assertEquals(LETTER_A, map.get(OFF_0_1));
assertEquals(LETTER_Z, map.get(OFF_0_2)); assertEquals(LETTER_Z, map.get(OFF_0_2));
grid.grid().hi = top; grid.grid().hi = top;
grid.grid().lo = low; grid.grid().lo = low;
map = grid.collect(Collectors.toMap(Lettrix::index, Lettrix::letter)); map = grid.collect(Collectors.toMap(Mask::index, Mask::d));
assertEquals(0, map.size()); assertEquals(0, map.size());
assertFalse(map.containsKey(OFF_0_1)); assertFalse(map.containsKey(OFF_0_1));
assertFalse(map.containsKey(OFF_0_2)); assertFalse(map.containsKey(OFF_0_2));

View File

@@ -40,7 +40,7 @@ public class TestDuplication {
var result = new ExportX_Const3x4.PuzzleResult(new Signa(mask.c()), grid1, slots, filled); var result = new ExportX_Const3x4.PuzzleResult(new Signa(mask.c()), grid1, slots, filled);
if (filled.ok()) { if (filled.ok()) {
System.out.println(filled); System.out.println(filled);
val res = result.exportFormatFromFilled(new Rewards(0, 0, 0), Masker_Neighbors3x4.IT); val res = result.exportFormatFromFilled(new Rewards(0, 0, 0));
System.out.println(String.join("\n", res.grid())); System.out.println(String.join("\n", res.grid()));
} }
} }