Search in sources :

Example 21 with Rotate

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

the class MinoTransform method refresh.

private void refresh() {
    for (List<Rotate> reverse : reverseMap.values()) reverse.clear();
    for (Rotate rotate : Rotate.values()) {
        int index = rotate.getNumber();
        Rotate newRotate = rotates[index];
        if (newRotate != null && rotate != newRotate) {
            // 変換後の回転が同じになる、他の回転とも関連づける
            for (Rotate r : reverseMap.get(newRotate)) {
                reverseMap.get(r).add(rotate);
                reverseMap.get(rotate).add(r);
            }
            // 変換前と変換後を関連づける
            reverseMap.get(newRotate).add(rotate);
            reverseMap.get(rotate).add(newRotate);
        }
    }
}
Also used : Rotate(core.srs.Rotate)

Example 22 with Rotate

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

the class MinoTransform method enumerateOthers.

List<Action> enumerateOthers(int x, int y, Rotate rotate) {
    List<Action> actions = new ArrayList<>();
    int currentRotateIndex = rotate.getNumber();
    int newX = x + this.offsetsX[currentRotateIndex];
    int newY = y + offsetsY[currentRotateIndex];
    for (Rotate prevRotate : reverseMap.get(rotate)) {
        int index = prevRotate.getNumber();
        MinimalAction action = MinimalAction.create(newX - this.offsetsX[index], newY - offsetsY[index], prevRotate);
        actions.add(action);
    }
    return actions;
}
Also used : Action(common.datastore.action.Action) MinimalAction(common.datastore.action.MinimalAction) MinimalAction(common.datastore.action.MinimalAction) Rotate(core.srs.Rotate) ArrayList(java.util.ArrayList)

Example 23 with Rotate

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

the class LockedReachable 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))
                    return true;
        }
    }
    return false;
}
Also used : Rotate(core.srs.Rotate) Mino(core.mino.Mino)

Example 24 with Rotate

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

the class LockedReachable method check.

private boolean check(Field field, Mino mino, int x, int y, From from) {
    // 一番上までたどり着いたとき
    if (appearY <= y)
        return true;
    Rotate rotate = mino.getRotate();
    // すでに訪問済みのとき
    if (lockedCache.isVisit(x, y, rotate))
        // 訪問済みだがまだ探索中の場合は、他の探索でカバーできるためfalseを返却
        return false;
    lockedCache.visit(x, y, rotate);
    // harddropでたどりつけるとき
    if (field.canReachOnHarddrop(mino, x, y))
        return true;
    // 上に移動
    int upY = y + 1;
    if (upY < appearY && field.canPut(mino, x, upY))
        if (check(field, mino, x, upY, From.None))
            return true;
    // 左に移動
    int leftX = x - 1;
    if (from != From.Left && -mino.getMinX() <= leftX && field.canPut(mino, leftX, y))
        if (check(field, mino, leftX, y, From.Right))
            return true;
    // 右に移動
    int rightX = x + 1;
    if (from != From.Right && rightX < FIELD_WIDTH - mino.getMaxX() && field.canPut(mino, rightX, y))
        if (check(field, mino, rightX, y, From.Left))
            return true;
    // 右回転でくる可能性がある場所を移動
    if (checkRightRotation(field, mino, x, y))
        return true;
    // 左回転でくる可能性がある場所を移動
    if (checkLeftRotation(field, mino, x, y))
        return true;
    return false;
}
Also used : Rotate(core.srs.Rotate)

Example 25 with Rotate

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

the class ActionParserTest method parseToOperation.

@Test
void parseToOperation() throws Exception {
    for (Piece piece : Piece.values()) {
        for (Rotate rotate : Rotate.values()) {
            for (int y = 0; y < 24; y++) {
                for (int x = 0; x < 10; x++) {
                    int value = ActionParser.parseToInt(piece, rotate, x, y);
                    assertThat(ActionParser.parseToOperation(value)).isEqualTo(new SimpleOperation(piece, rotate, x, y));
                }
            }
        }
    }
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) Test(org.junit.jupiter.api.Test)

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