Search in sources :

Example 1 with MinoOperationWithKey

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

the class SRSValidSolutionFilter method testLast.

@Override
public boolean testLast(MinoFieldMemento memento) {
    if (!test(memento))
        return false;
    LinkedList<MinoOperationWithKey> operations = memento.getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
    Reachable reachable = reachableThreadLocal.get();
    return BuildUp.existsValidBuildPattern(field, operations, sizedBit.getHeight(), reachable);
}
Also used : MinoOperationWithKey(common.datastore.MinoOperationWithKey) Reachable(core.action.reachable.Reachable)

Example 2 with MinoOperationWithKey

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

the class BuildUp method cansBuild.

// 指定した手順で組み立てられるか確認
public static boolean cansBuild(Field fieldOrigin, List<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
    Field field = fieldOrigin.freeze(height);
    for (MinoOperationWithKey operationWithKey : operationWithKeys) {
        long deleteKey = field.clearLineReturnKey();
        long needDeletedKey = operationWithKey.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) != needDeletedKey) {
            // 必要な列が消えていない
            return false;
        }
        // すでに下のラインが消えているときは、その分スライドさせる
        int originalY = operationWithKey.getY();
        int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
        Mino mino = operationWithKey.getMino();
        int x = operationWithKey.getX();
        int y = originalY - deletedLines;
        if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height)) {
            field.put(mino, x, y);
            field.insertBlackLineWithKey(deleteKey);
        } else {
            return false;
        }
    }
    return true;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Mino(core.mino.Mino)

Example 3 with MinoOperationWithKey

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

the class BuildUp method existsValidBuildPatternRecursive.

private static boolean existsValidBuildPatternRecursive(Field field, LinkedList<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
    long deleteKey = field.clearLineReturnKey();
    for (int index = 0; index < operationWithKeys.size(); index++) {
        MinoOperationWithKey key = operationWithKeys.remove(index);
        long needDeletedKey = key.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) != needDeletedKey) {
            // 必要な列が消えていない
            operationWithKeys.add(index, key);
            continue;
        }
        // すでに下のラインが消えているときは、その分スライドさせる
        int originalY = key.getY();
        int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
        Mino mino = key.getMino();
        int x = key.getX();
        int y = originalY - deletedLines;
        if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height - mino.getMinY())) {
            if (operationWithKeys.isEmpty())
                return true;
            Field nextField = field.freeze(height);
            nextField.put(mino, x, y);
            nextField.insertBlackLineWithKey(deleteKey);
            boolean exists = existsValidBuildPatternRecursive(nextField, operationWithKeys, height, reachable);
            if (exists)
                return true;
        }
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
    return false;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Mino(core.mino.Mino)

Example 4 with MinoOperationWithKey

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

the class BuildUp method existsValidByOrder.

// block順番で組み立てられる手順が存在するかチェックする
// operationsで使用するミノとblocksが一致していること
public static boolean existsValidByOrder(Field field, Stream<MinoOperationWithKey> operations, List<Piece> pieces, int height, Reachable reachable) {
    EnumMap<Piece, LinkedList<MinoOperationWithKey>> eachBlocks = operations.sequential().collect(() -> new EnumMap<Piece, LinkedList<MinoOperationWithKey>>(Piece.class), (blockLinkedListEnumMap, operationWithKey) -> {
        Piece piece = operationWithKey.getPiece();
        LinkedList<MinoOperationWithKey> operationWithKeys = blockLinkedListEnumMap.computeIfAbsent(piece, b -> new LinkedList<>());
        operationWithKeys.add(operationWithKey);
    }, EnumMap::putAll);
    return existsValidByOrder(field.freeze(height), eachBlocks, pieces, height, reachable, 0);
}
Also used : MinoOperationWithKey(common.datastore.MinoOperationWithKey) Piece(core.mino.Piece) EnumMap(java.util.EnumMap) LinkedList(java.util.LinkedList)

Example 5 with MinoOperationWithKey

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

the class BuildUpStreamTest method buildUp1.

@Test
void buildUp1() {
    // Create LockedReachable
    int height = 4;
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    // Create OperationWithKey List
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
    Operations operations = OperationInterpreter.parseToOperations("J,0,1,0;S,L,1,2;O,0,2,1;J,2,2,1");
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
    // Create Pieces
    Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
    // Assertion
    assertThat(valid).hasSize(2).contains("JSOJ", "JOSJ");
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) MinoRotation(core.srs.MinoRotation) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

MinoOperationWithKey (common.datastore.MinoOperationWithKey)32 Field (core.field.Field)23 MinoFactory (core.mino.MinoFactory)15 Piece (core.mino.Piece)15 Operations (common.datastore.Operations)12 Collectors (java.util.stream.Collectors)12 ColumnField (core.column_field.ColumnField)11 Test (org.junit.jupiter.api.Test)11 InOutPairField (searcher.pack.InOutPairField)11 List (java.util.List)10 OperationWithKey (common.datastore.OperationWithKey)9 Mino (core.mino.Mino)9 Randoms (lib.Randoms)9 LongTest (module.LongTest)9 SizedBit (searcher.pack.SizedBit)9 SeparableMino (searcher.pack.separable_mino.SeparableMino)9 Result (searcher.pack.task.Result)9 SRSValidSolutionFilter (searcher.pack.memento.SRSValidSolutionFilter)8 SolutionFilter (searcher.pack.memento.SolutionFilter)8 OnDemandBasicSolutions (searcher.pack.solutions.OnDemandBasicSolutions)8