Search in sources :

Example 11 with Randoms

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);
    }
}
Also used : Randoms(lib.Randoms) SeparableMino(searcher.pack.separable_mino.SeparableMino) RecursiveMinoField(searcher.pack.mino_field.RecursiveMinoField) Test(org.junit.jupiter.api.Test)

Example 12 with Randoms

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();
}
Also used : Randoms(lib.Randoms) MinoFactory(core.mino.MinoFactory) AllSeparableMinoFactory(searcher.pack.separable_mino.AllSeparableMinoFactory) MinoShifter(core.mino.MinoShifter) AllSeparableMinoFactory(searcher.pack.separable_mino.AllSeparableMinoFactory)

Example 13 with Randoms

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);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 14 with Randoms

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);
    }
}
Also used : Action(common.datastore.action.Action) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) BlockInterpreter(common.parser.BlockInterpreter) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) LongTest(module.LongTest)

Example 15 with Randoms

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());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

Randoms (lib.Randoms)108 Test (org.junit.jupiter.api.Test)103 Piece (core.mino.Piece)58 LongTest (module.LongTest)32 Field (core.field.Field)29 Action (common.datastore.action.Action)25 LongPieces (common.datastore.blocks.LongPieces)24 MinoFactory (core.mino.MinoFactory)20 ArrayList (java.util.ArrayList)19 LockedCandidate (core.action.candidate.LockedCandidate)17 Mino (core.mino.Mino)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 MinoShifter (core.mino.MinoShifter)14 MinoRotation (core.srs.MinoRotation)14 Rotate (core.srs.Rotate)13 Collectors (java.util.stream.Collectors)13 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)12 PatternGenerator (common.pattern.PatternGenerator)12 List (java.util.List)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)12