redo
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
package puzzle;
|
package puzzle;
|
||||||
|
|
||||||
import module java.base;
|
import module java.base;
|
||||||
|
import anno.ConstGen;
|
||||||
import anno.DictGen;
|
import anno.DictGen;
|
||||||
|
import anno.GenerateNeighbor;
|
||||||
|
import anno.GenerateNeighbors;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
import precomp.Neighbors9x8;
|
||||||
import puzzle.SwedishGenerator.Rng;
|
import puzzle.SwedishGenerator.Rng;
|
||||||
|
|
||||||
import static puzzle.Export.*;
|
import static puzzle.Export.*;
|
||||||
@@ -18,8 +22,14 @@ import static puzzle.SwedishGenerator.*;
|
|||||||
minLen = 2,
|
minLen = 2,
|
||||||
maxLen = 8
|
maxLen = 8
|
||||||
)
|
)
|
||||||
|
@ConstGen(C = 9, R = 8, packageName = "precomp", className = "Const9x8")
|
||||||
|
@GenerateNeighbors({
|
||||||
|
@GenerateNeighbor(C = 9, R = 8, packageName = "precomp", className = "Neighbors9x8", MIN_LEN = 2),
|
||||||
|
@GenerateNeighbor(C = 4, R = 3, packageName = "precomp", className = "Neighbors4x3", MIN_LEN = 2)
|
||||||
|
})
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
final static rci RCI = Masker.IT[0];
|
||||||
final static String OUT_DIR = envOrDefault("OUT_DIR", "/data/puzzle");
|
final static String OUT_DIR = envOrDefault("OUT_DIR", "/data/puzzle");
|
||||||
final static Path PUZZLE_DIR = Paths.get(OUT_DIR, "puzzles");
|
final static Path PUZZLE_DIR = Paths.get(OUT_DIR, "puzzles");
|
||||||
static final Path INDEX_FILE = PUZZLE_DIR.resolve("index.json");
|
static final Path INDEX_FILE = PUZZLE_DIR.resolve("index.json");
|
||||||
@@ -83,13 +93,13 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
section("Mask");
|
section("Mask");
|
||||||
System.out.print(indentLines(res.clues().gridToString(), " "));
|
System.out.print(indentLines(res.clues().gridToString()));
|
||||||
|
|
||||||
section("Grid (raw)");
|
section("Grid (raw)");
|
||||||
System.out.print(indentLines(res.grid().gridToString(), " "));
|
System.out.print(indentLines(res.grid().gridToString()));
|
||||||
|
|
||||||
section("Grid (human)");
|
section("Grid (human)");
|
||||||
System.out.print(indentLines(res.grid().renderHuman(), " "));
|
System.out.print(indentLines(res.grid().renderHuman()));
|
||||||
|
|
||||||
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1));
|
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1));
|
||||||
|
|
||||||
@@ -178,11 +188,11 @@ public class Main {
|
|||||||
return s.substring(0, Math.max(0, max - 1)) + "…";
|
return s.substring(0, Math.max(0, max - 1)) + "…";
|
||||||
}
|
}
|
||||||
|
|
||||||
static String indentLines(String s, String indent) {
|
static String indentLines(String s) {
|
||||||
if (s == null || s.isEmpty()) return "";
|
if (s == null || s.isEmpty()) return "";
|
||||||
var lines = s.split("\\R", -1);
|
var lines = s.split("\\R", -1);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
for (var line : lines) sb.append(indent).append(line).append('\n');
|
for (var line : lines) sb.append(" ").append(line).append('\n');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +366,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static Clues generateNewClues(Rng rng, Opts opts) {
|
static Clues generateNewClues(Rng rng, Opts opts) {
|
||||||
var masker = new Masker(rng, new int[Masker.STACK_SIZE], Clues.createEmpty());
|
var masker = new Masker_Neighbors9x8(rng, new int[Masker_Neighbors9x8.STACK_SIZE], Clues.createEmpty());
|
||||||
return masker.generateMask(opts.clueSize, opts.pop, opts.gens, opts.offspring);
|
return masker.generateMask(opts.clueSize, opts.pop, opts.gens, opts.offspring);
|
||||||
}
|
}
|
||||||
static PuzzleResult _attempt(Rng rng, Dict dict, Opts opts) {
|
static PuzzleResult _attempt(Rng rng, Dict dict, Opts opts) {
|
||||||
@@ -367,8 +377,8 @@ public class Main {
|
|||||||
//val mask = generateClues();
|
//val mask = generateClues();
|
||||||
if (mask == null) return null;
|
if (mask == null) return null;
|
||||||
|
|
||||||
val slotInfo = Masker.slots(mask, dict.index(), dict.reversed());
|
val slotInfo = Masker_Neighbors9x8.slots(mask, dict.index(), dict.reversed());
|
||||||
var grid = Slotinfo.grid(slotInfo);// mask.toGrid();
|
var grid = Masker_Neighbors9x8.grid(slotInfo, Neighbors9x8.SIZE);// mask.toGrid();
|
||||||
var filled = fillMask(rng, slotInfo, grid.lo, grid.hi, grid.g);
|
var filled = fillMask(rng, slotInfo, grid.lo, grid.hi, grid.g);
|
||||||
|
|
||||||
if (!multiThreaded) {
|
if (!multiThreaded) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import anno.GenerateShapedCopies;
|
|||||||
import anno.Shaped;
|
import anno.Shaped;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import precomp.Neighbors9x8;
|
import precomp.Neighbors9x8;
|
||||||
import gen.rci;
|
|
||||||
|
|
||||||
import static java.lang.Long.*;
|
import static java.lang.Long.*;
|
||||||
import static puzzle.SwedishGenerator.*;
|
import static puzzle.SwedishGenerator.*;
|
||||||
@@ -53,6 +52,14 @@ public final class Masker {
|
|||||||
|
|
||||||
return (bitCount(matchLo & MASK_LO) + bitCount(matchHi & MASK_HI)) / SIZED;
|
return (bitCount(matchLo & MASK_LO) + bitCount(matchHi & MASK_HI)) / SIZED;
|
||||||
}
|
}
|
||||||
|
public static Grid grid(Slotinfo[] slots, int size) {
|
||||||
|
long lo = X, hi = X;
|
||||||
|
for (var slot : slots) {
|
||||||
|
lo |= slot.lo();
|
||||||
|
hi |= slot.hi();
|
||||||
|
}
|
||||||
|
return new Grid(new byte[size], ~lo & MASK_LO, ~hi & MASK_HI);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isValid(Clues c) {
|
public boolean isValid(Clues c) {
|
||||||
return findOffendingClue(c) == -1;
|
return findOffendingClue(c) == -1;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public record SwedishGenerator() {
|
|||||||
|
|
||||||
public static final int MAX_TRIES_PER_SLOT = 500;// MAX_TRIES_PER_SLOT;
|
public static final int MAX_TRIES_PER_SLOT = 500;// MAX_TRIES_PER_SLOT;
|
||||||
public static final long X = 0L;
|
public static final long X = 0L;
|
||||||
@Shaped private static final int SIZE = Neighbors9x8.SIZE;
|
@Shaped static final int SIZE = Neighbors9x8.SIZE;
|
||||||
@Shaped private static final long RANGE_0_SIZE = Neighbors9x8.RANGE_0_SIZE;
|
@Shaped private static final long RANGE_0_SIZE = Neighbors9x8.RANGE_0_SIZE;
|
||||||
@Shaped private static final long RANGE_0_624 = Neighbors9x8.RANGE_0_624;
|
@Shaped private static final long RANGE_0_624 = Neighbors9x8.RANGE_0_624;
|
||||||
|
|
||||||
@@ -118,14 +118,6 @@ public record SwedishGenerator() {
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
public static boolean increasing(int dir) { return (dir & 2) == 0; }
|
public static boolean increasing(int dir) { return (dir & 2) == 0; }
|
||||||
public static Grid grid(Slotinfo[] slots) {
|
|
||||||
long lo = X, hi = X;
|
|
||||||
for (var slot : slots) {
|
|
||||||
lo |= slot.lo;
|
|
||||||
hi |= slot.hi;
|
|
||||||
}
|
|
||||||
return new Grid(new byte[SIZE], ~lo, ~hi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long patternForSlot(final long glo, final long ghi, final byte[] g, final long lo, final long hi) {
|
public static long patternForSlot(final long glo, final long ghi, final byte[] g, final long lo, final long hi) {
|
||||||
|
|||||||
3
src/main/java/puzzle/rci.java
Normal file
3
src/main/java/puzzle/rci.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package puzzle;
|
||||||
|
|
||||||
|
public record rci(int r, int c, int i, long n1, long n2, int nbrCount, long n8_1, long n8_2, double cross_r, double cross_c) {}
|
||||||
@@ -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 gen.rci;
|
import precomp.Neighbors9x8;
|
||||||
import puzzle.Export.Vestigium;
|
import puzzle.Export.Vestigium;
|
||||||
import puzzle.Export.Signa;
|
import puzzle.Export.Signa;
|
||||||
import puzzle.Export.Puzzle;
|
import puzzle.Export.Puzzle;
|
||||||
@@ -180,13 +180,13 @@ public class MainTest {
|
|||||||
r7c0d2, r7c1d1, r7c4d2, r7c5d2, r7c8d3
|
r7c0d2, r7c1d1, r7c4d2, r7c5d2, r7c8d3
|
||||||
);
|
);
|
||||||
var slotInfo = mask.slots(DictData950.DICT950);
|
var slotInfo = mask.slots(DictData950.DICT950);
|
||||||
var grid = Slotinfo.grid(slotInfo);
|
var grid = Masker.grid(slotInfo, Neighbors9x8.SIZE);
|
||||||
var filled = fillMask(rng, slotInfo, grid.lo, grid.hi, grid.g);
|
var filled = fillMask(rng, slotInfo, grid.lo, grid.hi, grid.g);
|
||||||
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
|
Assertions.assertTrue(filled.ok(), "Puzzle generation failed (not ok)");
|
||||||
Assertions.assertEquals(17, Slotinfo.wordCount(0, slotInfo), "Number of assigned words changed");
|
Assertions.assertEquals(17, Slotinfo.wordCount(0, slotInfo), "Number of assigned words changed");
|
||||||
Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get()));
|
Assertions.assertEquals("BEADEMT", Lemma.asWord(slotInfo[0].assign().w, Export.BYTES.get()));
|
||||||
Assertions.assertEquals(74732156493031040L, grid.lo);
|
Assertions.assertEquals(74732156493031040L, grid.lo);
|
||||||
Assertions.assertEquals(-63L, grid.hi);
|
Assertions.assertEquals(193L, grid.hi);
|
||||||
var g = new Puzzle(grid, mask.c());
|
var g = new Puzzle(grid, mask.c());
|
||||||
g.gridToString();
|
g.gridToString();
|
||||||
var aa = new PuzzleResult(mask, g, slotInfo, filled).exportFormatFromFilled(new Rewards(1, 1, 1));
|
var aa = new PuzzleResult(mask, g, slotInfo, filled).exportFormatFromFilled(new Rewards(1, 1, 1));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import anno.DictGen;
|
|||||||
import anno.Dictionaries;
|
import anno.Dictionaries;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import precomp.Neighbors9x8;
|
||||||
import puzzle.Export.Clue;
|
import puzzle.Export.Clue;
|
||||||
import puzzle.Export.Signa;
|
import puzzle.Export.Signa;
|
||||||
import puzzle.Export.Puzzle;
|
import puzzle.Export.Puzzle;
|
||||||
@@ -72,7 +73,7 @@ public class PerformanceTest {
|
|||||||
|
|
||||||
for (var i = 0; i < iterations; i++) {
|
for (var i = 0; i < iterations; i++) {
|
||||||
val slotInfo = Masker.slots(arr[c], DICT800);
|
val slotInfo = Masker.slots(arr[c], DICT800);
|
||||||
var grid = Slotinfo.grid(slotInfo);
|
var grid = Masker.grid(slotInfo, Neighbors9x8.SIZE);
|
||||||
val result = fillMask(rng, slotInfo,grid.lo,grid.hi, grid.g);
|
val result = fillMask(rng, slotInfo,grid.lo,grid.hi, grid.g);
|
||||||
if (result.ok()) successCount++;
|
if (result.ok()) successCount++;
|
||||||
totalNodes += result.nodes();
|
totalNodes += result.nodes();
|
||||||
@@ -142,7 +143,7 @@ public class PerformanceTest {
|
|||||||
// Reset assignments for each iteration
|
// Reset assignments for each iteration
|
||||||
for (var s : slots) s.assign().w = 0;
|
for (var s : slots) s.assign().w = 0;
|
||||||
|
|
||||||
var grid = Slotinfo.grid(slots);
|
var grid = Masker.grid(slots, Neighbors9x8.SIZE);
|
||||||
val result = fillMask(rng, slots, grid.lo,grid.hi,grid.g);
|
val result = fillMask(rng, slots, grid.lo,grid.hi,grid.g);
|
||||||
if (result.ok()) {
|
if (result.ok()) {
|
||||||
successCount++;
|
successCount++;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ 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 precomp.Neighbors9x8;
|
import precomp.Neighbors9x8;
|
||||||
import gen.rci;
|
|
||||||
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
|
import puzzle.DictJavaGeneratorMulti.DictEntryDTO.IntListDTO;
|
||||||
import puzzle.Export.Signa;
|
import puzzle.Export.Signa;
|
||||||
import puzzle.Export.Puzzle;
|
import puzzle.Export.Puzzle;
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package puzzle;
|
package puzzle;
|
||||||
|
|
||||||
import puzzle.Masker_Neighbors4x3;
|
|
||||||
import gen.Test123X_Neighbors4x3;
|
import gen.Test123X_Neighbors4x3;
|
||||||
import gen.Test123X_Neighbors9x8;
|
import gen.Test123X_Neighbors9x8;
|
||||||
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.Puzzle;
|
||||||
|
import puzzle.Export.PuzzleResult;
|
||||||
|
import puzzle.Export.Rewards;
|
||||||
import puzzle.Export.Signa;
|
import puzzle.Export.Signa;
|
||||||
import puzzle.Export.Vestigium;
|
import puzzle.Export.Vestigium;
|
||||||
|
import puzzle.SwedishGenerator.Rng;
|
||||||
import puzzle.dict800.DictData800;
|
import puzzle.dict800.DictData800;
|
||||||
import puzzle.dict950.DictData950;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import static precomp.Const9x8.Cell.r0c0d1;
|
import static precomp.Const9x8.Cell.r0c0d1;
|
||||||
import static precomp.Const9x8.Cell.r1c0d1;
|
import static precomp.Const9x8.Cell.r1c0d1;
|
||||||
@@ -34,7 +36,8 @@ public class TestDuplication {
|
|||||||
val map = mask.stream().collect(Collectors.toMap(Vestigium::index, Vestigium::clue));
|
val map = mask.stream().collect(Collectors.toMap(Vestigium::index, Vestigium::clue));
|
||||||
Assertions.assertEquals(4, map.size());
|
Assertions.assertEquals(4, map.size());
|
||||||
var slots = Masker_Neighbors4x3.slots(mask.c(), DictData800.DICT800);
|
var slots = Masker_Neighbors4x3.slots(mask.c(), DictData800.DICT800);
|
||||||
// var filled = fillMask(rng, slotInfo, grid, false);
|
var grid = Masker_Neighbors4x3.grid(slots, Masker_Neighbors4x3.SIZE);
|
||||||
// val res = new PuzzleResult(new Clued(mask), new Gridded(grid), slotInfo, filled).exportFormatFromFilled(0, new Rewards(0, 0, 0));
|
var filled = SwedishGenerator.fillMask(new Rng(1), slots, grid.lo, grid.hi, grid.g);
|
||||||
|
val res = new PuzzleResult(new Signa(mask.c()), new Puzzle(grid, mask.c()), slots, filled).exportFormatFromFilled(new Rewards(0, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user