use of lib.Randoms in project solution-finder by knewjade.
the class MinoFieldComparatorTest method compareMinoFieldDiffMino.
@Test
void compareMinoFieldDiffMino() {
Randoms randoms = new Randoms();
List<SeparableMino> minos = separableMinos.getMinos();
MinoFieldComparator comparator = new MinoFieldComparator();
for (int count = 0; count < 100000; count++) {
int index1 = randoms.nextInt(0, minos.size());
SeparableMino mino1 = minos.get(index1);
RecursiveMinoField recursiveMinoField1 = new RecursiveMinoField(mino1, ColumnFieldFactory.createField(), separableMinos);
int index2 = randoms.nextInt(0, minos.size() - 1);
if (index1 == index2)
index2 += 1;
SeparableMino mino2 = minos.get(index2);
RecursiveMinoField recursiveMinoField2 = new RecursiveMinoField(mino2, ColumnFieldFactory.createField(), separableMinos);
// assert is not 0 & sign reversed
assertThat(comparator.compare(recursiveMinoField1, recursiveMinoField2) * comparator.compare(recursiveMinoField2, recursiveMinoField1)).isLessThan(0);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class SeparableMinosTest method createSeparableMinoSet.
private Set<SeparableMino> createSeparableMinoSet() {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
int fieldHeight = randoms.nextIntClosed(1, 10);
int fieldWidth = randoms.nextIntClosed(1, 4);
SizedBit sizedBit = new SizedBit(fieldWidth, fieldHeight);
AllSeparableMinoFactory separableMinoFactory = new AllSeparableMinoFactory(minoFactory, minoShifter, sizedBit.getWidth(), sizedBit.getHeight(), sizedBit.getFillBoard());
return separableMinoFactory.create();
}
use of lib.Randoms in project solution-finder by knewjade.
the class SlideXOperationWithKeyTest method get.
@Test
void get() {
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
Mino mino = new Mino(piece, rotate);
int x = randoms.nextInt(0, 10);
int y = randoms.nextInt(0, 10);
long usingKey = randoms.key();
long deleteKey = randoms.key();
FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
int slide = randoms.nextInt(4);
SlideXOperationWithKey key = new SlideXOperationWithKey(operationWithKey, slide);
assertThat(key).returns(x + slide, SlideXOperationWithKey::getX).returns(y, SlideXOperationWithKey::getY).returns(deleteKey, SlideXOperationWithKey::getNeedDeletedKey).returns(usingKey, SlideXOperationWithKey::getUsingKey);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testPossiblePerfect.
@Test
@LongTest
void testPossiblePerfect() throws Exception {
// Field
Field field = FieldFactory.createSmallField();
int maxClearLine = 4;
int maxDepth = 10;
// Set to check No Possible Perfect
String noPerfectPath = ClassLoader.getSystemResource("orders/noperfect.txt").getPath();
HashSet<LongPieces> noPerfectSet = Files.lines(Paths.get(noPerfectPath)).map(BlockInterpreter::parse).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
// Set test case
int cycle = randoms.nextIntClosed(0, 8);
List<Piece> pieces = randoms.block11InCycle(cycle);
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
boolean expectedFlag = !noPerfectSet.contains(new LongPieces(pieces));
assertThat(isSucceed).isEqualTo(expectedFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class CheckmateNoHoldReuseTest method randomCheckmateOverBlock.
@Test
@LongTest
void randomCheckmateOverBlock() {
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
int maxClearLine = randoms.nextInt(3, 8);
int maxDepth = randoms.nextIntClosed(5, 7);
List<Piece> pieces = randoms.blocks(maxDepth + 1);
Field field = randoms.field(maxClearLine, maxDepth);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
for (int swap = 0; swap < 250; swap++) {
int index = randoms.nextInt(3, pieces.size());
Piece pop = pieces.remove(index);
pieces.add(pop);
stopwatchNoUse.start();
List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchNoUse.stop();
stopwatchReuse.start();
List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchReuse.stop();
assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
}
// assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
}
}
Aggregations