Search in sources :

Example 1 with PositionLimitParser

use of _implements.parity_based_pack.step2.PositionLimitParser 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)

Example 2 with PositionLimitParser

use of _implements.parity_based_pack.step2.PositionLimitParser in project solution-finder by knewjade.

the class ParityBasedPackSearcher method search.

public Stream<List<MinoOperationWithKey>> search(List<Piece> usingPieces) {
    // 準備
    MinoFactory minoFactory = new MinoFactory();
    PositionLimitParser positionLimitParser = new PositionLimitParser(minoFactory, maxClearLine);
    LockedReachableThreadLocal threadLocal = new LockedReachableThreadLocal(maxClearLine);
    ParityField parityField = new ParityField(field);
    PieceCounter pieceCounter = new PieceCounter(usingPieces);
    ColumnParityLimitation limitation = new ColumnParityLimitation(pieceCounter, parityField, maxClearLine);
    return limitation.enumerate().parallelStream().map(EstimateBuilder::create).flatMap(Collection::stream).flatMap(deltaLimitedMinos -> parseToSortedFullLimitedMinoStream(positionLimitParser, deltaLimitedMinos)).limit(// parallelでの並列数をリセットする(同時実行数を増やす)
    Long.MAX_VALUE).flatMap(sets -> new CrossBuilder(sets, field, maxClearLine).create().stream()).filter(operationWithKeys -> BuildUp.existsValidBuildPattern(verifyField, operationWithKeys, maxClearLine, threadLocal.get()));
}
Also used : PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) Piece(core.mino.Piece) EstimateBuilder(_implements.parity_based_pack.step1.EstimateBuilder) PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) BuildUp(common.buildup.BuildUp) Collection(java.util.Collection) MinoOperationWithKey(common.datastore.MinoOperationWithKey) DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) Collectors(java.util.stream.Collectors) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) PieceCounter(common.datastore.PieceCounter) List(java.util.List) Field(core.field.Field) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Comparator(java.util.Comparator) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) PieceCounter(common.datastore.PieceCounter) Collection(java.util.Collection) MinoFactory(core.mino.MinoFactory) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation)

Aggregations

ColumnParityLimitation (_implements.parity_based_pack.step1.ColumnParityLimitation)2 DeltaLimitedMino (_implements.parity_based_pack.step1.DeltaLimitedMino)2 EstimateBuilder (_implements.parity_based_pack.step1.EstimateBuilder)2 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)2 PositionLimitParser (_implements.parity_based_pack.step2.PositionLimitParser)2 CrossBuilder (_implements.parity_based_pack.step3.CrossBuilder)2 BuildUp (common.buildup.BuildUp)2 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)2 Field (core.field.Field)2 MinoFactory (core.mino.MinoFactory)2 Piece (core.mino.Piece)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 OperationWithKeyComparator (common.comparator.OperationWithKeyComparator)1 common.datastore (common.datastore)1 MinoOperationWithKey (common.datastore.MinoOperationWithKey)1 PieceCounter (common.datastore.PieceCounter)1 CombinationIterable (common.iterable.CombinationIterable)1 OperationWithKeyInterpreter (common.parser.OperationWithKeyInterpreter)1 Tetfu (common.tetfu.Tetfu)1