Search in sources :

Example 36 with LongPieces

use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.

the class ReverseOrderLookUpTest method parseJustRandom.

@Test
void parseJustRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 2; size <= 13; size++) {
        List<Piece> blocks = randoms.blocks(size);
        int fromDepth = blocks.size();
        ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(blocks.size(), fromDepth);
        List<LongPieces> reverse = reverseOrderLookUp.parse(blocks).map(LongPieces::new).collect(Collectors.toList());
        LongPieces target = new LongPieces(blocks);
        ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(blocks.size(), fromDepth);
        for (LongPieces pieces : reverse) {
            boolean isFound = forwardOrderLookUp.parse(pieces.getPieces()).map(LongPieces::new).anyMatch(target::equals);
            assertThat(isFound).isTrue();
        }
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 37 with LongPieces

use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.

the class ReverseOrderLookUpTest method parseOverRandom.

@Test
@LongTest
void parseOverRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 2; size <= 13; size++) {
        List<Piece> pieces = randoms.blocks(size);
        int fromDepth = pieces.size() + 1;
        ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(pieces.size(), fromDepth);
        List<Stream<Piece>> reverse = reverseOrderLookUp.parse(pieces).collect(Collectors.toList());
        LongPieces target = new LongPieces(pieces);
        ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(pieces.size(), fromDepth);
        for (Stream<Piece> stream : reverse) {
            List<Piece> sample = stream.map(block -> block != null ? block : randoms.block()).collect(Collectors.toList());
            boolean isFound = forwardOrderLookUp.parse(sample).map(LongPieces::new).anyMatch(target::equals);
            assertThat(isFound).isTrue();
        }
    }
}
Also used : Test(org.junit.jupiter.api.Test) Piece(core.mino.Piece) Randoms(lib.Randoms) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) Tag(org.junit.jupiter.api.Tag) LongTest(module.LongTest) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 38 with LongPieces

use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.

the class ReverseOrderLookUpTest method parseOver2Random.

@Test
void parseOver2Random() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 2; size <= 12; size++) {
        List<Piece> pieces = randoms.blocks(size);
        int fromDepth = pieces.size() + 2;
        ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(pieces.size(), fromDepth);
        List<Stream<Piece>> reverse = reverseOrderLookUp.parse(pieces).collect(Collectors.toList());
        LongPieces target = new LongPieces(pieces);
        ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(pieces.size(), fromDepth);
        for (Stream<Piece> stream : reverse) {
            List<Piece> sample = stream.map(block -> block != null ? block : randoms.block()).collect(Collectors.toList());
            boolean isFound = forwardOrderLookUp.parse(sample).map(LongPieces::new).anyMatch(target::equals);
            assertThat(isFound).isTrue();
        }
    }
}
Also used : Test(org.junit.jupiter.api.Test) Piece(core.mino.Piece) Randoms(lib.Randoms) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) Tag(org.junit.jupiter.api.Tag) LongTest(module.LongTest) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Randoms(lib.Randoms) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 39 with LongPieces

use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.

the class ForwardOrderLookUpTest method parseJustBlocksRandom.

@Test
void parseJustBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 2; size <= 15; size++) {
        List<Piece> pieces = randoms.blocks(size);
        int toDepth = pieces.size();
        ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, 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;
                }
            }
            // ホールドを追加
            sample.add(pieces.get(holdIndex));
            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 40 with LongPieces

use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.

the class ForwardOrderLookUpTest method parseJustBlocks.

@Test
void parseJustBlocks() throws Exception {
    List<Piece> pieceList = Arrays.asList(Piece.I, Piece.T, Piece.Z, Piece.O, Piece.I, Piece.L);
    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) HashSet(java.util.HashSet) Piece(core.mino.Piece) Randoms(lib.Randoms) Arrays(java.util.Arrays) List(java.util.List) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) PiecesNumberComparator(common.comparator.PiecesNumberComparator) Test(org.junit.jupiter.api.Test)

Aggregations

LongPieces (common.datastore.blocks.LongPieces)71 Test (org.junit.jupiter.api.Test)58 Piece (core.mino.Piece)42 PatternGenerator (common.pattern.PatternGenerator)38 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)36 Randoms (lib.Randoms)27 Collectors (java.util.stream.Collectors)22 Field (core.field.Field)19 Pieces (common.datastore.blocks.Pieces)16 LongTest (module.LongTest)16 List (java.util.List)14 Stream (java.util.stream.Stream)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 FieldFactory (core.field.FieldFactory)12 ArrayList (java.util.ArrayList)12 SizedBit (searcher.pack.SizedBit)12 MinoFactory (core.mino.MinoFactory)11 HashSet (java.util.HashSet)11 ExecutionException (java.util.concurrent.ExecutionException)10 BlockInterpreter (common.parser.BlockInterpreter)9