Search in sources :

Example 66 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateOverRandomNoHold.

@Test
void enumerateOverRandomNoHold() 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, 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 - 1));
            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 67 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateHoldOverOne.

@Test
void enumerateHoldOverOne() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("I, S, Z, O, T, J, L");
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 4, true);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(1);
    assertThat(core.getCounter()).isEqualTo(1);
}
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 68 with LongPieces

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

the class NormalEnumeratePiecesTest method enumerateNoHoldOver3.

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

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

the class NormalEnumeratePiecesTest method enumerateNoHoldOver2.

@Test
void enumerateNoHoldOver2() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("*p7");
    NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 4, false);
    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 70 with LongPieces

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

the class PercentCoreTest method assertPercentCore.

private void assertPercentCore(Obj obj, double successPercent) throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator(obj.patterns);
    NormalEnumeratePieces enumeratePieces = new NormalEnumeratePieces(generator, obj.maxDepth, obj.isUsingHold);
    Set<LongPieces> blocks = enumeratePieces.enumerate();
    Injector injector = Guice.createInjector(new BasicModule(obj.maxClearLine));
    Optional<ExecutorService> executorService = obj.isSingleThread ? Optional.empty() : Optional.of(injector.getInstance(ExecutorService.class));
    LockedCandidateThreadLocal candidateThreadLocal = injector.getInstance(LockedCandidateThreadLocal.class);
    LockedReachableThreadLocal reachableThreadLocal = injector.getInstance(LockedReachableThreadLocal.class);
    MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
    PercentCore percentCore = getPercentCore(obj, executorService.orElse(null), candidateThreadLocal, reachableThreadLocal, minoFactory);
    Field field = FieldFactory.createField(obj.marks);
    percentCore.run(field, blocks, obj.maxClearLine, obj.maxDepth);
    executorService.ifPresent(ExecutorService::shutdown);
    assertThat(percentCore.getResultTree().getSuccessPercent()).isEqualTo(successPercent);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) BasicModule(module.BasicModule) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Field(core.field.Field) LongPieces(common.datastore.blocks.LongPieces) Injector(com.google.inject.Injector) LockedCandidateThreadLocal(concurrent.LockedCandidateThreadLocal) NormalEnumeratePieces(entry.searching_pieces.NormalEnumeratePieces) ExecutorService(java.util.concurrent.ExecutorService) MinoFactory(core.mino.MinoFactory)

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