Search in sources :

Example 31 with Rotate

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

the class DeepdropCandidate method search.

@Override
public Set<Action> search(Field field, Piece piece, int appearY) {
    HashSet<Action> actions = new HashSet<>();
    for (Rotate rotate : Rotate.values()) {
        Mino mino = minoFactory.create(piece, rotate);
        for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
            for (int y = appearY - mino.getMaxY() - 1; -mino.getMinY() <= y; y--) {
                if (field.canPut(mino, x, y) && field.isOnGround(mino, x, y)) {
                    Action action = minoShifter.createTransformedAction(piece, rotate, x, y);
                    actions.add(action);
                }
            }
        }
    }
    return actions;
}
Also used : Action(common.datastore.action.Action) Rotate(core.srs.Rotate) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 32 with Rotate

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

the class HarddropCandidate method search.

@Override
public // ハードドロップで置くことができ、appearY以下にミノがすべて収まる場所を列挙する
Set<Action> search(Field field, Piece piece, int appearY) {
    HashSet<Action> actions = new HashSet<>();
    for (Rotate rotate : minoShifter.getUniqueRotates(piece)) {
        Mino mino = minoFactory.create(piece, rotate);
        int y = appearY - mino.getMinY();
        int maxY = appearY - mino.getMaxY();
        for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
            int harddropY = field.getYOnHarddrop(mino, x, y);
            if (harddropY < maxY) {
                Action action = minoShifter.createTransformedAction(piece, rotate, x, harddropY);
                actions.add(action);
            }
        }
    }
    return actions;
}
Also used : Action(common.datastore.action.Action) Rotate(core.srs.Rotate) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 33 with Rotate

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

the class LockedCandidate 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)) {
                    lockedCache.found(x, y, currentRotate);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Rotate(core.srs.Rotate) Mino(core.mino.Mino)

Example 34 with Rotate

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

the class LockedCandidate method checkLeftRotation.

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

Example 35 with Rotate

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

the class HarddropReachable 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;
    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)

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