Search in sources :

Example 6 with PatternGenerator

use of common.pattern.PatternGenerator 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 7 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class HoldBreakEnumeratePiecesTest method enumerate2.

@Test
void enumerate2() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("*p7");
    HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(generator, 4);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(840);
    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 8 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class NormalEnumeratePiecesTest method enumerateHoldJust.

@Test
void enumerateHoldJust() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("*p3");
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 3, true);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(210);
    assertThat(core.getCounter()).isEqualTo(210);
}
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 9 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class NormalEnumeratePiecesTest method enumerateHoldOver3.

@Test
void enumerateHoldOver3() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("I, *p7");
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 4, true);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(840);
    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 10 with PatternGenerator

use of common.pattern.PatternGenerator 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)

Aggregations

PatternGenerator (common.pattern.PatternGenerator)71 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)67 Test (org.junit.jupiter.api.Test)35 LongPieces (common.datastore.blocks.LongPieces)34 AnalyzeTree (common.tree.AnalyzeTree)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)27 Piece (core.mino.Piece)13 Randoms (lib.Randoms)12 Field (core.field.Field)10 Pieces (common.datastore.blocks.Pieces)9 MinoFactory (core.mino.MinoFactory)9 LongTest (module.LongTest)9 Action (common.datastore.action.Action)6 LockedCandidate (core.action.candidate.LockedCandidate)6 MinoShifter (core.mino.MinoShifter)6 HashSet (java.util.HashSet)6 PerfectValidator (searcher.common.validator.PerfectValidator)6 EntryPoint (entry.EntryPoint)5 ColorConverter (common.tetfu.common.ColorConverter)4