introduce bitloops
This commit is contained in:
@@ -3,6 +3,7 @@ package puzzle;
|
||||
import module java.base;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.Export.Clue;
|
||||
import puzzle.Export.Clued;
|
||||
import puzzle.Export.Gridded;
|
||||
import puzzle.Masker.Clues;
|
||||
@@ -12,12 +13,14 @@ import puzzle.SwedishGenerator.Slotinfo;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static puzzle.SwedishGenerator.fillMask;
|
||||
import static puzzle.dict800.DictData.DICT800;
|
||||
import static puzzle.dict900.DictData.DICT900;
|
||||
|
||||
public class PerformanceTest {
|
||||
|
||||
final DictEntry[] EN = DictData.DICT.index();
|
||||
final DictEntry[] EN = DICT800.index();
|
||||
void main() {
|
||||
testPerformance();
|
||||
testIncrementalComplexity();
|
||||
}
|
||||
@Test
|
||||
void testPerformance() {
|
||||
@@ -80,7 +83,7 @@ public class PerformanceTest {
|
||||
" 1 \n" +
|
||||
"221 22\n";
|
||||
val mask = Clued.parse(maskStr);
|
||||
val allSlots = Masker.slots(mask.c(), EN);
|
||||
val allSlots = Masker.slots(mask.c(), DICT900.index());
|
||||
//mask.toGrid()
|
||||
System.out.println("[DEBUG_LOG] \n--- Incremental Complexity Test ---");
|
||||
System.out.println("[DEBUG_LOG] Full Slot Layout:");
|
||||
@@ -123,7 +126,9 @@ public class PerformanceTest {
|
||||
for (Slotinfo s : slots) s.assign().w = 0;
|
||||
|
||||
val result = fillMask(rng, slots, Slotinfo.grid(slots));
|
||||
if (result.ok()) successCount++;
|
||||
if (result.ok()) {
|
||||
successCount++;
|
||||
}
|
||||
totalNodes += result.nodes();
|
||||
totalBacktracks += result.backtracks();
|
||||
}
|
||||
@@ -132,6 +137,7 @@ public class PerformanceTest {
|
||||
|
||||
System.out.printf(Locale.ROOT, "[DEBUG_LOG] %s: %d/%d SUCCESS | avg nodes=%d | avg backtracks=%d | total time=%.3fs%n",
|
||||
label, successCount, iterations, totalNodes / iterations, totalBacktracks / iterations, totalDuration);
|
||||
visualizeSlots(slots);
|
||||
}
|
||||
|
||||
private void visualizeSlots(Slotinfo[] slots) {
|
||||
@@ -141,39 +147,17 @@ public class PerformanceTest {
|
||||
for (int r = 0; r < R; r++) Arrays.fill(display[r], ' ');
|
||||
|
||||
for (Slotinfo slot : slots) {
|
||||
int key = slot.key();
|
||||
int dir = Masker.Slot.dir(key);
|
||||
int clueIdx = Masker.Slot.clueIndex(key);
|
||||
int key = slot.key();
|
||||
Clue dir = Clue.from(Masker.Slot.dir(key));
|
||||
int clueIdx = Masker.Slot.clueIndex(key);
|
||||
|
||||
int cr = Masker.IT[clueIdx].r();
|
||||
int cc = Masker.IT[clueIdx].c();
|
||||
|
||||
// User requested: aAAAA for a four letter to RIGHT clue slot.
|
||||
// SwedishGenerator: 1=RIGHT, 0=DOWN, 2=UP, 3=LEFT
|
||||
char clueChar;
|
||||
char slotChar;
|
||||
switch (dir) {
|
||||
case 1:
|
||||
clueChar = 'a';
|
||||
slotChar = 'A';
|
||||
break; // RIGHT
|
||||
case 0:
|
||||
clueChar = 'b';
|
||||
slotChar = 'B';
|
||||
break; // DOWN
|
||||
case 2:
|
||||
clueChar = 'c';
|
||||
slotChar = 'C';
|
||||
break; // UP
|
||||
case 3:
|
||||
clueChar = 'd';
|
||||
slotChar = 'D';
|
||||
break; // LEFT
|
||||
default:
|
||||
clueChar = '?';
|
||||
slotChar = '?';
|
||||
}
|
||||
|
||||
char clueChar = dir.clueChar;
|
||||
char slotChar = dir.slotChar;
|
||||
display[cr][cc] = clueChar;
|
||||
|
||||
Gridded.cellWalk((byte) slot.key(), slot.lo(), slot.hi()).forEach(idx -> {
|
||||
|
||||
Reference in New Issue
Block a user