Search in sources :

Example 1 with DeltaLimitedMino

use of _implements.parity_based_pack.step1.DeltaLimitedMino in project solution-finder by knewjade.

the class Main3 method search.

public static List<List<MinoOperationWithKey>> search(List<Piece> usedPieces, Field field, int maxClearLine, Field verifyField) {
    MinoFactory minoFactory = new MinoFactory();
    PositionLimitParser positionLimitParser = new PositionLimitParser(minoFactory, maxClearLine);
    LockedReachableThreadLocal threadLocal = new LockedReachableThreadLocal(maxClearLine);
    ParityField parityField = new ParityField(field);
    PieceCounter pieceCounter = new PieceCounter(usedPieces);
    ColumnParityLimitation limitation = new ColumnParityLimitation(pieceCounter, parityField, maxClearLine);
    return limitation.enumerate().parallelStream().map(EstimateBuilder::create).flatMap(Collection::stream).flatMap((List<DeltaLimitedMino> deltaLimitedMinos) -> {
        // 変換 DeltaLimitedMinos to FullLimitedMino
        List<List<FullLimitedMino>> collect = deltaLimitedMinos.stream().map(positionLimitParser::parse).collect(Collectors.toList());
        // 候補数が小さい順  // 同種のブロックを固めるため
        List<Piece> priority = collect.stream().sorted(Comparator.comparingInt(List::size)).map(fullLimitedMinos -> fullLimitedMinos.get(0).getMino().getPiece()).collect(Collectors.toList());
        // ソートする
        collect.sort((o1, o2) -> {
            int compare = Integer.compare(priority.indexOf(o1.get(0).getMino().getPiece()), priority.indexOf(o2.get(0).getMino().getPiece()));
            if (compare != 0)
                return compare;
            return -Integer.compare(o1.size(), o2.size());
        });
        return Stream.of(collect);
    }).limit(Long.MAX_VALUE).flatMap(sets -> new CrossBuilder(sets, field, maxClearLine).create().stream()).filter(operationWithKeys -> BuildUp.existsValidBuildPattern(verifyField, operationWithKeys, maxClearLine, threadLocal.get())).collect(Collectors.toList());
}
Also used : PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) java.util(java.util) Stopwatch(lib.Stopwatch) ColorType(common.tetfu.common.ColorType) OperationWithKeyComparator(common.comparator.OperationWithKeyComparator) common.datastore(common.datastore) DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) Tetfu(common.tetfu.Tetfu) FieldView(core.field.FieldView) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Piece(core.mino.Piece) EstimateBuilder(_implements.parity_based_pack.step1.EstimateBuilder) PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) Predicate(java.util.function.Predicate) BuildUp(common.buildup.BuildUp) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) TimeUnit(java.util.concurrent.TimeUnit) Field(core.field.Field) Stream(java.util.stream.Stream) OperationWithKeyInterpreter(common.parser.OperationWithKeyInterpreter) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) Piece(core.mino.Piece) EstimateBuilder(_implements.parity_based_pack.step1.EstimateBuilder) MinoFactory(core.mino.MinoFactory)

Aggregations

ColumnParityLimitation (_implements.parity_based_pack.step1.ColumnParityLimitation)1 DeltaLimitedMino (_implements.parity_based_pack.step1.DeltaLimitedMino)1 EstimateBuilder (_implements.parity_based_pack.step1.EstimateBuilder)1 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)1 PositionLimitParser (_implements.parity_based_pack.step2.PositionLimitParser)1 CrossBuilder (_implements.parity_based_pack.step3.CrossBuilder)1 BuildUp (common.buildup.BuildUp)1 OperationWithKeyComparator (common.comparator.OperationWithKeyComparator)1 common.datastore (common.datastore)1 CombinationIterable (common.iterable.CombinationIterable)1 OperationWithKeyInterpreter (common.parser.OperationWithKeyInterpreter)1 Tetfu (common.tetfu.Tetfu)1 TetfuElement (common.tetfu.TetfuElement)1 ColorConverter (common.tetfu.common.ColorConverter)1 ColorType (common.tetfu.common.ColorType)1 ColoredField (common.tetfu.field.ColoredField)1 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)1 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)1 Field (core.field.Field)1 FieldFactory (core.field.FieldFactory)1