Search in sources :

Example 21 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateJustRandomNoHold.

@Test
void enumerateJustRandomNoHold() throws Exception {
    List<Piece> failedPieces = Arrays.asList(Piece.I, Piece.O, Piece.L, Piece.J, Piece.S, Piece.Z);
    List<Piece> allPieces = new ArrayList<>(Piece.valueList());
    for (int size = 1; size <= 7; size++) {
        PatternGenerator blocksGenerator = new LoadedPatternGenerator("T, *p" + size);
        NormalEnumeratePieces core = new NormalEnumeratePieces(blocksGenerator, size + 1, false);
        Set<LongPieces> pieces = core.enumerate();
        for (int count = 0; count < 1000; count++) {
            List<Piece> sample = new ArrayList<>();
            sample.add(Piece.T);
            Collections.shuffle(allPieces);
            sample.addAll(allPieces.subList(0, size));
            assertThat(new LongPieces(sample)).isIn(pieces);
            for (Piece piece : failedPieces) {
                sample.set(0, piece);
                assertThat(new LongPieces(sample)).isNotIn(pieces);
            }
        }
    }
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Test(org.junit.jupiter.api.Test)

Example 22 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateHoldMulti.

@Test
void enumerateHoldMulti() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator(Arrays.asList("T, J, O, Z, I", "J, O, S, T, Z", "T, J, O, I, S", "T, J, O, Z, I"));
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 3, true);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(3);
    assertThat(core.getCounter()).isEqualTo(4);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Test(org.junit.jupiter.api.Test)

Example 23 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateHoldOver2.

@Test
void enumerateHoldOver2() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("*p7");
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 4, true);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(2520);
    assertThat(core.getCounter()).isEqualTo(5040);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Test(org.junit.jupiter.api.Test)

Example 24 with LongPieces

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

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

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