Search in sources :

Example 31 with LongPieces

use of common.datastore.blocks.LongPieces 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 32 with LongPieces

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

the class HoldBreakEnumeratePieces method enumerate.

@Override
public Set<LongPieces> enumerate() throws IOException {
    assert counter == -1;
    int depth = generator.getDepth();
    ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(maxDepth, depth);
    AtomicInteger counter = new AtomicInteger();
    HashSet<LongPieces> searchingPieces = create(depth, forwardOrderLookUp, counter);
    this.counter = counter.get();
    return searchingPieces;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForwardOrderLookUp(common.order.ForwardOrderLookUp) LongPieces(common.datastore.blocks.LongPieces)

Example 33 with LongPieces

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

the class NormalEnumeratePieces method enumerate.

@Override
public Set<LongPieces> enumerate() {
    assert counter == -1;
    int depth = generator.getDepth();
    AtomicInteger counter = new AtomicInteger();
    HashSet<LongPieces> searchingPieces = create(depth, counter);
    this.counter = counter.get();
    return searchingPieces;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongPieces(common.datastore.blocks.LongPieces)

Example 34 with LongPieces

use of common.datastore.blocks.LongPieces 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)

Example 35 with LongPieces

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

the class OrderLookupTest method forwardOverBlocksRandom.

@Test
void forwardOverBlocksRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int size = 3; size <= 13; size++) {
        List<Piece> pieceList = randoms.blocks(size);
        int toDepth = pieceList.size() - 1;
        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

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