Search in sources :

Example 91 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class VisitedTreeTest method random.

@Test
void random() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 7; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
        VisitedTree tree = new VisitedTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 92 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class VisitedTreeTest method randomLong.

@Test
@LongTest
void randomLong() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 8; size <= 11; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
        VisitedTree tree = new VisitedTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 93 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class FullOperationSeparableMinoComparatorTest method compareMinoFieldDiff.

@Test
void compareMinoFieldDiff() {
    List<SeparableMino> minos = separableMinos.getMinos();
    Randoms randoms = new Randoms();
    FullOperationSeparableMinoComparator comparator = new FullOperationSeparableMinoComparator();
    for (int count = 0; count < 100000; count++) {
        int index1 = randoms.nextInt(minos.size() - 1);
        int index2 = randoms.nextInt(minos.size());
        if (index1 == index2)
            index2 += 1;
        // assert is not 0 & sign reversed
        SeparableMino mino1 = minos.get(index1);
        SeparableMino mino2 = minos.get(index2);
        assertThat(comparator.compare(mino1, mino2) * comparator.compare(mino2, mino1)).isLessThan(0);
    }
}
Also used : Randoms(lib.Randoms) SeparableMino(searcher.pack.separable_mino.SeparableMino) Test(org.junit.jupiter.api.Test)

Example 94 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class MinoFieldComparatorTest method compareMinoFieldDiffSize.

@Test
void compareMinoFieldDiffSize() {
    Randoms randoms = new Randoms();
    List<SeparableMino> minos = separableMinos.getMinos();
    int index = randoms.nextInt(0, minos.size() - 1);
    SeparableMino mino = minos.get(index);
    RecursiveMinoField recursiveMinoField1 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
    RecursiveMinoField recursiveMinoField2 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
    recursiveMinoField2 = new RecursiveMinoField(mino, recursiveMinoField2, ColumnFieldFactory.createField(), separableMinos);
    // assert is not 0 & sign reversed
    MinoFieldComparator comparator = new MinoFieldComparator();
    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 95 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class HoldBreakEnumeratePiecesTest method enumerateOverRandom.

@Test
void enumerateOverRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 3; size <= 15; size++) {
        List<Piece> blocks = randoms.blocks(size);
        String pattern = blocks.stream().map(Piece::getName).collect(Collectors.joining(","));
        PatternGenerator blocksGenerator = new LoadedPatternGenerator(pattern);
        HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(blocksGenerator, size - 1);
        Set<LongPieces> pieces = core.enumerate();
        for (int count = 0; count < 10000; count++) {
            ArrayList<Piece> sample = new ArrayList<>();
            int holdIndex = 0;
            for (int index = 1; index < size; index++) {
                if (randoms.nextBoolean(0.3)) {
                    // そのまま追加
                    sample.add(blocks.get(index));
                } else {
                    // ホールドを追加
                    sample.add(blocks.get(holdIndex));
                    holdIndex = index;
                }
            }
            assertThat(new LongPieces(sample)).isIn(pieces);
        }
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

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