Search in sources :

Example 56 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class AllSeparableMinoFactoryTest method create3x3.

@Test
void create3x3() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    int width = 3;
    int height = 3;
    Set<SeparableMino> minos = getSeparableMinos(minoFactory, minoShifter, width, height);
    assertThat(minos.stream()).hasSize(114);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.T))).hasSize(24);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.I))).hasSize(9);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.S))).hasSize(12);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.Z))).hasSize(12);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.O))).hasSize(9);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.L))).hasSize(24);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.J))).hasSize(24);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test)

Example 57 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class AllSeparableMinoFactoryTest method create3x5.

@Test
void create3x5() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    int width = 3;
    int height = 5;
    Set<SeparableMino> minos = getSeparableMinos(minoFactory, minoShifter, width, height);
    assertThat(minos.stream()).hasSize(540);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.T))).hasSize(120);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.I))).hasSize(30);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.S))).hasSize(60);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.Z))).hasSize(60);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.O))).hasSize(30);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.L))).hasSize(120);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.J))).hasSize(120);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test)

Example 58 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class MappedBasicSolutionsFactoryTest method createSeparableMinos.

private static SeparableMinos createSeparableMinos(SizedBit sizedBit) {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    return SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter)

Example 59 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class HarddropBuildUpListUpThreadLocal method initialValue.

@Override
protected BuildUpStream initialValue() {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    HarddropReachable reachable = new HarddropReachable(minoFactory, minoShifter, height);
    return new BuildUpStream(reachable, height);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) HarddropReachable(core.action.reachable.HarddropReachable) BuildUpStream(common.buildup.BuildUpStream)

Example 60 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class PathEntryPoint method run.

@Override
public void run() throws FinderException {
    output("# Setup Field");
    // Setup field
    Field field = settings.getField();
    Verify.field(field);
    // Setup max clear line
    int maxClearLine = settings.getMaxClearLine();
    Verify.maxClearLineUnder10(maxClearLine);
    // Setup reserved blocks
    BlockField reservedBlocks = settings.getReservedBlock();
    if (settings.isReserved()) {
        Verify.reservedBlocks(reservedBlocks);
        for (int y = maxClearLine - 1; 0 <= y; y--) {
            StringBuilder builder = new StringBuilder();
            for (int x = 0; x < 10; x++) {
                if (reservedBlocks.getBlock(x, y) != null)
                    builder.append(reservedBlocks.getBlock(x, y).getName());
                else if (!field.isEmpty(x, y))
                    builder.append('X');
                else
                    builder.append('_');
            }
            output(builder.toString());
        }
    } else {
        output(FieldView.toString(field, maxClearLine));
    }
    // Setup max depth
    // パフェに必要なミノ数
    int maxDepth = Verify.maxDepth(field, maxClearLine);
    output();
    // ========================================
    // Output user-defined
    output("# Initialize / User-defined");
    output("Max clear lines: " + maxClearLine);
    output("Using hold: " + (settings.isUsingHold() ? "use" : "avoid"));
    output("Drop: " + settings.getDropType().name().toLowerCase());
    output("Searching patterns:");
    // Setup patterns
    List<String> patterns = settings.getPatterns();
    PatternGenerator generator = Verify.patterns(patterns, maxDepth);
    // Output patterns
    for (String pattern : patterns) output("  " + pattern);
    output();
    // ========================================
    // Setup core
    output("# Initialize / System");
    int threadCount = getThreadCount();
    // Output system-defined
    output("Version = " + FinderConstant.VERSION);
    output("Threads = " + threadCount);
    output("Need Pieces = " + maxDepth);
    output();
    // ========================================
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    ColorConverter colorConverter = new ColorConverter();
    SizedBit sizedBit = decideSizedBitSolutionWidth(maxClearLine);
    SolutionFilter solutionFilter = new ForPathSolutionFilter(generator, maxClearLine);
    // Holdができるときは必要なミノ分(maxDepth + 1)だけを取り出す。maxDepth + 1だけないときはブロックの個数をそのまま指定
    output("# Enumerate pieces");
    boolean isUsingHold = settings.isUsingHold();
    int piecesDepth = generator.getDepth();
    output("Piece pop count = " + (isUsingHold && maxDepth < piecesDepth ? maxDepth + 1 : maxDepth));
    output();
    // ========================================
    output("# Cache");
    output("  -> Stopwatch start");
    Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
    BasicSolutions basicSolutions = calculateBasicSolutions(field, minoFactory, minoShifter, sizedBit, solutionFilter);
    stopwatch1.stop();
    output("     ... done");
    output("  -> Stopwatch stop : " + stopwatch1.toMessage(TimeUnit.MILLISECONDS));
    output();
    // ========================================
    output("# Search");
    output("  -> Stopwatch start");
    output("     ... searching");
    Stopwatch stopwatch2 = Stopwatch.createStartedStopwatch();
    PathCore pathCore = createPathCore(field, maxClearLine, maxDepth, patterns, minoFactory, colorConverter, sizedBit, solutionFilter, isUsingHold, basicSolutions, threadCount);
    List<PathPair> pathPairs = run(pathCore, field, sizedBit, reservedBlocks);
    stopwatch2.stop();
    output("     ... done");
    output("  -> Stopwatch stop : " + stopwatch2.toMessage(TimeUnit.MILLISECONDS));
    output();
    // ========================================
    output("# Output file");
    OutputType outputType = settings.getOutputType();
    PathOutput pathOutput = createOutput(outputType, generator, maxDepth);
    pathOutput.output(pathPairs, field, sizedBit);
    output();
    // ========================================
    output("# Finalize");
    output("done");
}
Also used : PatternGenerator(common.pattern.PatternGenerator) Stopwatch(lib.Stopwatch) EntryPoint(entry.EntryPoint) FilterOnDemandBasicSolutions(searcher.pack.solutions.FilterOnDemandBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) BlockField(common.datastore.BlockField) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) BlockField(common.datastore.BlockField) SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter)

Aggregations

MinoShifter (core.mino.MinoShifter)60 MinoFactory (core.mino.MinoFactory)59 MinoRotation (core.srs.MinoRotation)39 Field (core.field.Field)36 Test (org.junit.jupiter.api.Test)35 LongTest (module.LongTest)29 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)19 Piece (core.mino.Piece)19 InOutPairField (searcher.pack.InOutPairField)18 Randoms (lib.Randoms)17 LockedReachable (core.action.reachable.LockedReachable)15 LockedCandidate (core.action.candidate.LockedCandidate)14 PermutationIterable (common.iterable.PermutationIterable)12 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 PerfectValidator (searcher.common.validator.PerfectValidator)10 SizedBit (searcher.pack.SizedBit)10 SolutionFilter (searcher.pack.memento.SolutionFilter)10