Search in sources :

Example 26 with Randoms

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

the class NeighborTest method getNextRightRotateDestinations.

@Test
void getNextRightRotateDestinations() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.create());
    Randoms randoms = new Randoms();
    List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
    neighbor.updateRightRotateDestination(samples);
    assertThat(neighbor.getNextRightRotateDestinations()).containsAll(samples);
}
Also used : Randoms(lib.Randoms) ArrayList(java.util.ArrayList) Mino(core.mino.Mino) Test(org.junit.jupiter.api.Test)

Example 27 with Randoms

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

the class HoldBreakEnumeratePiecesTest method enumerateJustRandom.

@Test
void enumerateJustRandom() 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);
        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;
                }
            }
            // ホールドを追加
            sample.add(blocks.get(holdIndex));
            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)

Example 28 with Randoms

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

the class ForwardOrderLookUpTest method parseOver2BlocksRandom.

@Test
void parseOver2BlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 4; size <= 15; size++) {
        List<Piece> pieces = randoms.blocks(size);
        int toDepth = pieces.size();
        ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth - 2, 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 - 1; 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 29 with Randoms

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

the class OrderLookupTest method forwardOver2BlocksRandom.

@Test
void forwardOver2BlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 4; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int toDepth = pieceList.size() - 2;
        PiecesNumberComparator comparator = new PiecesNumberComparator();
        List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
        ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
        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)

Example 30 with Randoms

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

the class OrderLookupTest method forwardJustBlocksRandom.

@Test
void forwardJustBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 2; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int toDepth = pieceList.size();
        PiecesNumberComparator comparator = new PiecesNumberComparator();
        List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
        ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
        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