Search in sources :

Example 41 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class MoveEntryPoint method run.

@Override
public void run() throws FinderException {
    output("# Setup Field");
    // Setup field
    Field field = settings.getField();
    Verify.field(field);
    int maxClearLine = settings.getMaxClearLine();
    output(FieldView.toString(field, maxClearLine));
    // Setup max depth
    // パフェに必要なミノ数
    int maxDepth = Verify.maxDepth(field, maxClearLine);
    output();
    // ========================================
    output("Searching patterns:");
    // Setup patterns
    List<String> patterns = settings.getPatterns();
    PatternGenerator generator = Verify.patterns(patterns);
    // Output patterns
    for (String pattern : patterns) output("  " + pattern);
    output();
    // ========================================
    // baseファイル
    MyFile base = new MyFile(settings.getOutputBaseFilePath());
    base.mkdirs();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    ColorConverter colorConverter = new ColorConverter();
    PerfectValidator perfectValidator = new PerfectValidator();
    PutterNoHold<Action> putter = new PutterNoHold<>(minoFactory, perfectValidator);
    output("# Calculate");
    try (BufferedWriter bw = base.newBufferedWriter()) {
        List<Pieces> pieces = generator.blocksStream().collect(Collectors.toList());
        for (Pieces piece : pieces) {
            String using = piece.blockStream().map(Piece::getName).collect(Collectors.joining());
            output("   -> " + using);
            TreeSet<Order> first = putter.first(field, piece.getPieceArray(), new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine), maxClearLine, maxDepth);
            for (Order order : first) {
                Stream<Operation> operationStream = order.getHistory().getOperationStream();
                List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, new Operations(operationStream), minoFactory, maxClearLine);
                BlockField blockField = OperationTransform.parseToBlockField(operationWithKeys, minoFactory, maxClearLine);
                String encodeColor = encodeColor(field, minoFactory, colorConverter, blockField);
                String encodeGray = encodeGray(order.getField(), minoFactory, colorConverter);
                bw.write(String.format("%s,%s,%s", using, encodeColor, encodeGray));
                bw.newLine();
            }
        }
        bw.flush();
    } catch (IOException e) {
        throw new FinderExecuteException("Failed to output file", e);
    }
}
Also used : Action(common.datastore.action.Action) MyFile(entry.path.output.MyFile) Operation(common.datastore.Operation) BufferedWriter(java.io.BufferedWriter) BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) LockedCandidate(core.action.candidate.LockedCandidate) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) PutterNoHold(searcher.PutterNoHold) PerfectValidator(searcher.common.validator.PerfectValidator) Operations(common.datastore.Operations) Pieces(common.datastore.blocks.Pieces) Order(common.datastore.order.Order) PatternGenerator(common.pattern.PatternGenerator) IOException(java.io.IOException) EntryPoint(entry.EntryPoint) MinoRotation(core.srs.MinoRotation) MinoShifter(core.mino.MinoShifter) FinderExecuteException(exceptions.FinderExecuteException)

Example 42 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckmateUsingHoldTest method testMultiPath1.

@Test
void testMultiPath1() throws Exception {
    // Field
    String marks = "" + "X________X" + "XX__XX__XX" + "XX__XX__XX" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 3;
    int maxDepth = 4;
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    // Set test case
    List<Piece> pieces = Arrays.asList(J, L, S, Z);
    int expectedCount = 4;
    // Execute
    List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
    assertThat(results).as(pieces.toString()).hasSize(expectedCount);
    // Check result
    for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 43 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckmateUsingHoldTest method testLong9.

@Test
void testLong9() throws Exception {
    List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {

        {
            add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z), 29));
            add(new Pair<>(Arrays.asList(T, S, L, I, Z, J, L, O, O, S), 49));
            add(new Pair<>(Arrays.asList(L, Z, S, J, Z, Z, Z, I, T, T), 40));
            // PCF: 106
            add(new Pair<>(Arrays.asList(T, T, S, S, Z, Z, L, L, J, J), 107));
            add(new Pair<>(Arrays.asList(O, S, O, S, Z, L, Z, L, I, I), 3));
            // PCF: 112
            add(new Pair<>(Arrays.asList(J, I, T, O, L, S, I, T, Z, O), 113));
            add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L, L), 82));
            add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 36));
            // PCF: 16
            add(new Pair<>(Arrays.asList(Z, S, T, I, O, J, L, Z, S), 17));
            add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 36));
        }
    };
    // Field
    String marks = "" + "__________" + "X_________" + "X_________" + "XX________" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 4;
    int maxDepth = 9;
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    for (Pair<List<Piece>, Integer> testCase : testCases) {
        // Set test case
        List<Piece> pieces = testCase.getKey();
        int expectedCount = testCase.getValue();
        // Execute
        List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(results).as(pieces.toString()).hasSize(expectedCount);
        // Check result
        for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 44 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckmateUsingHoldTest method testCaseList.

@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, int expectedCount) throws Exception {
    // Field
    int maxClearLine = 4;
    int maxDepth = 10;
    Field field = FieldFactory.createField(maxClearLine);
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    // Set test case
    List<Piece> piecesList = pieces.getPieces();
    // Execute
    List<Result> results = checkmate.search(field, piecesList, candidate, maxClearLine, maxDepth);
    assertThat(results).as(piecesList.toString()).hasSize(expectedCount);
    // Check result
    for (Result result : results) assertResult(result, field, maxClearLine, reachable, piecesList);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

LockedCandidate (core.action.candidate.LockedCandidate)44 Action (common.datastore.action.Action)43 Field (core.field.Field)43 Piece (core.mino.Piece)40 LongTest (module.LongTest)38 Test (org.junit.jupiter.api.Test)32 LockedReachable (core.action.reachable.LockedReachable)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Randoms (lib.Randoms)15 PerfectValidator (searcher.common.validator.PerfectValidator)13 MinoFactory (core.mino.MinoFactory)12 MinoShifter (core.mino.MinoShifter)12 MinoRotation (core.srs.MinoRotation)12 List (java.util.List)11 Result (common.datastore.Result)8 AnalyzeTree (common.tree.AnalyzeTree)8 Stopwatch (lib.Stopwatch)8 ArrayList (java.util.ArrayList)7 PatternGenerator (common.pattern.PatternGenerator)6 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)6