introduce bitloops

This commit is contained in:
mike
2026-01-20 10:21:38 +01:00
parent e8e0344212
commit 3cd17d170a
4 changed files with 14 additions and 25 deletions

View File

@@ -246,22 +246,10 @@ public record Export() {
public record PuzzleResult(Clued clues, Gridded grid, Slotinfo[] slots, FillResult filled) {
static public long calcSimpel(Slotinfo[] slots) {
int k = 0;
long simpel = 0L;
for (var n = 1; n < slots.length; n++) {
if (slots[n].assign().w != X) {
k++;
simpel += Meta.lookup(slots[n].assign().w).simpel();
}
}
simpel = k == 0 ? 0 : simpel / k;
return simpel;
}
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
public ExportedPuzzle exportFormatFromFilled(Rewards rewards) {
// If nothing placed: return full grid mapped to letters/# only
if (slots.length == 0) {
return new ExportedPuzzle(grid.exportGrid(clues.c, _ -> '#', '#'), new WordOut[0], difficulty, rewards);
return new ExportedPuzzle(grid.exportGrid(clues.c, _ -> '#', '#'), 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(
@@ -307,7 +295,11 @@ public record Export() {
p.arrowCol() - MIN_C,
p.isReversed(), bytes
)).toArray(WordOut[]::new);
return new ExportedPuzzle(gridv2, wordsOut, difficulty, rewards);
var total = 0.0001d;
for (var word : wordsOut) {
total += word.complex();
}
return new ExportedPuzzle(gridv2, wordsOut, (int) (total / wordsOut.length), rewards);
}
}

View File

@@ -87,16 +87,13 @@ public class Main {
section("Grid (human)");
System.out.print(indentLines(res.grid().renderHuman(res.clues().c()), " "));
var exported = res.exportFormatFromFilled(1, new Rewards(50, 2, 1));
var total = 0.0001d;
for (var word : exported.words()) {
total += word.complex();
}
var exported = res.exportFormatFromFilled(new Rewards(50, 2, 1));
section("Clues");
info("status : generating...");
info("generatedFor : " + exported.words().length);
info("status : done");
info("simpel : " + (total / exported.words().length));
info("simpel : " + exported.difficulty());
section("Words");
printWordsTable(exported.words());

View File

@@ -54,10 +54,10 @@ public class ExportFormatTest {
}, fillResult);
var rewards = new Rewards(10, 5, 1);
var exported = puzzleResult.exportFormatFromFilled(2, rewards);
var exported = puzzleResult.exportFormatFromFilled(rewards);
assertNotNull(exported);
assertEquals(2, exported.difficulty());
assertEquals(709, exported.difficulty());
assertEquals(rewards, exported.rewards());
// Check words
@@ -93,7 +93,7 @@ public class ExportFormatTest {
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
var puzzleResult = new PuzzleResult(new Clued(clues), new Gridded(grid, clues), new Slotinfo[0], fillResult);
var exported = puzzleResult.exportFormatFromFilled(1, new Rewards(0, 0, 0));
var exported = puzzleResult.exportFormatFromFilled(new Rewards(0, 0, 0));
assertNotNull(exported);
assertEquals(0, exported.words().length);

View File

@@ -222,7 +222,7 @@ public class MainTest {
Assertions.assertEquals(-1L, grid.hi);
var g = new Gridded(grid, mask.c());
g.gridToString(mask.c());
var aa = new PuzzleResult(mask, g, slotInfo, filled).exportFormatFromFilled(1, new Rewards(1, 1, 1));
var aa = new PuzzleResult(mask, g, slotInfo, filled).exportFormatFromFilled(new Rewards(1, 1, 1));
System.out.println(String.join("\n", aa.grid()));
}