Search in sources :

Example 51 with Randoms

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

the class PermutationIterableTest method iteratorRandomBlock.

@Test
@LongTest
void iteratorRandomBlock() throws Exception {
    Randoms randoms = new Randoms();
    ArrayList<Piece> allPieces = Lists.newArrayList(Iterables.concat(Piece.valueList(), Piece.valueList()));
    for (int pop = 1; pop <= 7; pop++) {
        PermutationIterable<Piece> iterable = new PermutationIterable<>(allPieces, pop);
        HashSet<LongPieces> sets = StreamSupport.stream(iterable.spliterator(), false).map(Collection::stream).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
        // ランダムにサンプルを選択し、必ず列挙したセットの中にあることを確認
        for (int count = 0; count < 1000; count++) {
            List<Piece> sample = randoms.sample(allPieces, pop);
            LongPieces pieces = new LongPieces(sample);
            assertThat(pieces).isIn(sets);
        }
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 52 with Randoms

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

the class ForwardOrderLookUpTest method parseOverBlocksRandom.

@Test
void parseOverBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 3; size <= 15; size++) {
        List<Piece> pieces = randoms.blocks(size);
        int toDepth = pieces.size();
        ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth - 1, pieces.size());
        HashSet<LongPieces> forward = lookUp.parse(pieces).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
        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(pieces.get(index));
                } else {
                    // ホールドを追加
                    sample.add(pieces.get(holdIndex));
                    holdIndex = index;
                }
            }
            assertThat(new LongPieces(sample)).isIn(forward);
        }
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 53 with Randoms

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

the class OperationHistoryTest method random.

@Test
void random() throws ExecutionException, InterruptedException {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 1000; count++) {
        int size = randoms.nextInt(1, 10);
        ArrayList<Operation> operations = new ArrayList<>();
        OperationHistory history = new OperationHistory(size);
        for (int index = 0; index < size; index++) {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int y = randoms.nextInt(4);
            int x = randoms.nextInt(10);
            MinimalAction action = MinimalAction.create(x, y, rotate);
            history = history.recordAndReturnNew(piece, action);
            operations.add(new SimpleOperation(piece, rotate, x, y));
        }
        List<Operation> actual = history.getOperationStream().collect(Collectors.toList());
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Example 54 with Randoms

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

the class OrderLookupTest method reverseOver2BlocksRandom.

@Test
void reverseOver2BlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int fromDepth = pieceList.size() + 2;
        Comparator<List<Piece>> comparator = new ListComparator<>(Comparator.nullsFirst(Comparator.comparingInt(Piece::getNumber)));
        List<List<Piece>> forward1 = OrderLookup.reverseBlocks(pieceList, fromDepth).stream().map(StackOrder::toList).sorted(comparator).collect(Collectors.toList());
        ReverseOrderLookUp lookUp = new ReverseOrderLookUp(pieceList.size(), fromDepth);
        List<List<Piece>> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).sorted(comparator).collect(Collectors.toList());
        assertThat(forward2).isEqualTo(forward1);
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) ListComparator(lib.ListComparator) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 55 with Randoms

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

the class OrderLookupTest method reverseJustBlocksRandom.

@Test
void reverseJustBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int fromDepth = pieceList.size();
        PiecesNumberComparator comparator = new PiecesNumberComparator();
        List<LongPieces> forward1 = OrderLookup.reverseBlocks(pieceList, fromDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
        ReverseOrderLookUp lookUp = new ReverseOrderLookUp(pieceList.size(), fromDepth);
        List<LongPieces> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
        assertThat(forward2).isEqualTo(forward1);
    }
}
Also used : Test(org.junit.jupiter.api.Test) Piece(core.mino.Piece) Randoms(lib.Randoms) Arrays(java.util.Arrays) List(java.util.List) ListComparator(lib.ListComparator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) 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