Search in sources :

Example 11 with LongPieces

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

the class PackSearcherComparingParityBasedTest method testAllSRSValidPacksHeight5.

// 高さ5: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
void testAllSRSValidPacksHeight5() throws Exception {
    int width = 2;
    int height = 5;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height5.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : java.util(java.util) Pieces(common.datastore.blocks.Pieces) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) MinoShifter(core.mino.MinoShifter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) Piece(core.mino.Piece) Files(java.nio.file.Files) InOutPairField(searcher.pack.InOutPairField) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Example 12 with LongPieces

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

the class CheckerUsingHoldTest method assertResult.

private void assertResult(Field field, int maxClearLine, LockedReachable reachable, List<Piece> blocks) {
    Result result = checker.getResult();
    // Check blocks is same
    List<Piece> resultPieces = parseToBlocks(result);
    Piece lastHoldPiece = result.getLastHold();
    HashSet<LongPieces> pieces = OrderLookup.reverseBlocks(resultPieces, blocks.size()).stream().map(StackOrder::toStream).map(stream -> stream.map(block -> block != null ? block : lastHoldPiece)).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
    assertThat(pieces).contains(new LongPieces(blocks));
    // Check can build result
    Operations operations = parseToOperations(result);
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, maxClearLine);
    boolean cansBuild = BuildUp.cansBuild(field, operationWithKeys, maxClearLine, reachable);
    assertThat(cansBuild).isTrue();
}
Also used : Randoms(lib.Randoms) java.util(java.util) OperationTransform(common.parser.OperationTransform) common.datastore(common.datastore) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ResultHelper(common.ResultHelper) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) PerfectValidator(searcher.common.validator.PerfectValidator) OrderLookup(common.order.OrderLookup) Candidate(core.action.candidate.Candidate) FieldFactory(core.field.FieldFactory) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) MinoRotation(core.srs.MinoRotation) StackOrder(common.order.StackOrder) LockedReachable(core.action.reachable.LockedReachable) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) BuildUp(common.buildup.BuildUp) BlockInterpreter(common.parser.BlockInterpreter) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Field(core.field.Field) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Piece(core.mino.Piece) LongPieces(common.datastore.blocks.LongPieces)

Example 13 with LongPieces

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

the class CheckerUsingHoldTest method testPossiblePerfect.

@Test
@LongTest
void testPossiblePerfect() throws Exception {
    // Field
    Field field = FieldFactory.createSmallField();
    int maxClearLine = 4;
    int maxDepth = 10;
    // Set to check No Possible Perfect
    String noPerfectPath = ClassLoader.getSystemResource("orders/noperfect.txt").getPath();
    HashSet<LongPieces> noPerfectSet = Files.lines(Paths.get(noPerfectPath)).map(BlockInterpreter::parse).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100; count++) {
        // Set test case
        int cycle = randoms.nextIntClosed(0, 8);
        List<Piece> pieces = randoms.block11InCycle(cycle);
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        boolean expectedFlag = !noPerfectSet.contains(new LongPieces(pieces));
        assertThat(isSucceed).isEqualTo(expectedFlag);
        // Check result
        if (isSucceed)
            assertResult(field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) BlockInterpreter(common.parser.BlockInterpreter) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) LongTest(module.LongTest)

Example 14 with LongPieces

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

the class HoldBreakEnumeratePiecesTest method enumerateJustAny.

@Test
void enumerateJustAny() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator("T, O, S");
    HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(generator, 3);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(4);
    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 15 with LongPieces

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

the class HoldBreakEnumeratePiecesTest method enumerateMulti.

@Test
void enumerateMulti() throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator(Arrays.asList("T, J, O, Z", "T, O, J, T", "T, J, O, Z"));
    HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(generator, 3);
    Set<LongPieces> pieces = core.enumerate();
    assertThat(pieces).hasSize(13);
    assertThat(core.getCounter()).isEqualTo(3);
}
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)

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