Search in sources :

Example 36 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class LockedReachable method checkRightRotation.

private boolean checkRightRotation(Field field, Mino mino, int x, int y) {
    Rotate currentRotate = mino.getRotate();
    Mino minoBefore = minoFactory.create(mino.getPiece(), currentRotate.getLeftRotate());
    // 右回転前のテストパターンを取得
    int[][] patterns = minoRotation.getRightPatternsFrom(minoBefore);
    for (int[] pattern : patterns) {
        int fromX = x - pattern[0];
        int fromY = y - pattern[1];
        if (canPutMinoInField(field, minoBefore, fromX, fromY)) {
            int[] kicks = minoRotation.getKicksWithRightRotation(field, minoBefore, mino, fromX, fromY);
            if (kicks != null && pattern[0] == kicks[0] && pattern[1] == kicks[1])
                if (check(field, minoBefore, fromX, fromY, From.None))
                    return true;
        }
    }
    return false;
}
Also used : Rotate(core.srs.Rotate) Mino(core.mino.Mino)

Example 37 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class OperationWithKeyInterpreter method parseToStream.

public static Stream<MinoOperationWithKey> parseToStream(String operations, MinoFactory minoFactory) {
    return Arrays.stream(operations.split(";")).map(s -> s.split(",")).map(strings -> {
        Piece piece = StringEnumTransform.toPiece(strings[0]);
        Rotate rotate = StringEnumTransform.toRotate(strings[1]);
        Mino mino = minoFactory.create(piece, rotate);
        int x = Integer.valueOf(strings[2]);
        int y = Integer.valueOf(strings[3]);
        long deleteKey = Long.valueOf(strings[4]);
        long usingKey = Long.valueOf(strings[5]);
        return new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
    });
}
Also used : OperationWithKey(common.datastore.OperationWithKey) Piece(core.mino.Piece) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) Mino(core.mino.Mino) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 38 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class ActionEncoder method coordinate_to_int.

private int coordinate_to_int(TetfuElement element) {
    int x = element.getX();
    int y = element.getY();
    ColorType type = element.getColorType();
    Rotate rotate = element.getRotate();
    if (!ColorType.isMinoBlock(type)) {
        x = 0;
        y = 22;
    } else if (type == ColorType.O && rotate == Rotate.Left) {
        x -= 1;
        y -= 1;
    } else if (type == ColorType.O && rotate == Rotate.Reverse)
        x -= 1;
    else if (type == ColorType.O && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.I && rotate == Rotate.Reverse)
        x -= 1;
    else if (type == ColorType.I && rotate == Rotate.Left)
        y += 1;
    else if (type == ColorType.S && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.S && rotate == Rotate.Right)
        x += 1;
    else if (type == ColorType.Z && rotate == Rotate.Spawn)
        y += 1;
    else if (type == ColorType.Z && rotate == Rotate.Left)
        x -= 1;
    return (TETFU_FIELD_TOP - y - 1) * TETFU_FIELD_WIDTH + x;
}
Also used : Rotate(core.srs.Rotate) ColorType(common.tetfu.common.ColorType)

Example 39 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class LockedReachable method checks.

@Override
public boolean checks(Field field, Mino mino, int x, int y, int appearY) {
    assert field.canPut(mino, x, y);
    this.appearY = appearY;
    lockedCache.clear();
    Piece piece = mino.getPiece();
    Rotate rotate = mino.getRotate();
    if (check(field, piece, x, y, rotate))
        return true;
    List<Action> actions = minoShifter.enumerateSameOtherActions(piece, rotate, x, y);
    for (Action action : actions) if (check(field, piece, action.getX(), action.getY(), action.getRotate()))
        return true;
    return false;
}
Also used : Action(common.datastore.action.Action) Rotate(core.srs.Rotate) Piece(core.mino.Piece)

Example 40 with Rotate

use of core.srs.Rotate in project solution-finder by knewjade.

the class AbstractAllOperationFactory method create.

public Set<T> create() {
    HashSet<T> pieces = new HashSet<>();
    HashSet<Mino> createdCheckSet = new HashSet<>();
    for (Piece piece : Piece.values()) {
        for (Rotate originRotate : Rotate.values()) {
            Rotate rotate = minoShifter.createTransformedRotate(piece, originRotate);
            Mino mino = minoFactory.create(piece, rotate);
            // 追加済みかチェック
            if (createdCheckSet.contains(mino))
                continue;
            createdCheckSet.add(mino);
            // ミノの高さを計算
            int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
            // フィールドの高さ以上にミノを使う場合はおけない
            if (fieldHeight < minoHeight)
                continue;
            // 行候補をリストにする
            ArrayList<Integer> lineIndexes = getLineIndexes(fieldHeight);
            // リストアップ
            ArrayList<T> piecesEachMino = generatePiecesEachMino(mino, lineIndexes, minoHeight);
            // 追加
            pieces.addAll(piecesEachMino);
        }
    }
    return pieces;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Aggregations

Rotate (core.srs.Rotate)55 Mino (core.mino.Mino)25 Piece (core.mino.Piece)25 Test (org.junit.jupiter.api.Test)14 Action (common.datastore.action.Action)13 ColorType (common.tetfu.common.ColorType)11 Randoms (lib.Randoms)11 HashSet (java.util.HashSet)10 ColoredField (common.tetfu.field.ColoredField)9 MinoFactory (core.mino.MinoFactory)9 List (java.util.List)9 MinimalAction (common.datastore.action.MinimalAction)7 TetfuPage (common.tetfu.TetfuPage)7 ColorConverter (common.tetfu.common.ColorConverter)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7 Field (core.field.Field)6 FinderParseException (exceptions.FinderParseException)6 SimpleOperation (common.datastore.SimpleOperation)5 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)5