Search in sources :

Example 46 with Mino

use of core.mino.Mino in project solution-finder by knewjade.

the class OriginalPieceFactory method createPieces.

private Set<OriginalPiece> createPieces(int fieldHeight) {
    Set<OriginalPiece> pieces = new HashSet<>();
    for (Piece block : Piece.values()) {
        for (Rotate rotate : Rotate.values()) {
            Mino mino = new Mino(block, rotate);
            for (int y = -mino.getMinY(); y < fieldHeight - mino.getMaxY(); y++) {
                for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
                    OriginalPiece piece = new OriginalPiece(mino, x, y, fieldHeight);
                    pieces.add(piece);
                }
            }
        }
    }
    return pieces;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 47 with Mino

use of core.mino.Mino 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 48 with Mino

use of core.mino.Mino in project solution-finder by knewjade.

the class OperationTransform method parseToOperationWithKeys.

// List<OperationWithKey>に変換する。正しく組み立てられるかはチェックしない
public static List<MinoOperationWithKey> parseToOperationWithKeys(Field fieldOrigin, Operations operations, MinoFactory minoFactory, int height) {
    ArrayList<MinoOperationWithKey> keys = new ArrayList<>();
    Field field = fieldOrigin.freeze(height);
    for (Operation op : operations.getOperations()) {
        Mino mino = minoFactory.create(op.getPiece(), op.getRotate());
        int x = op.getX();
        int y = op.getY();
        long deleteKey = field.clearLineReturnKey();
        // 一番上と一番下のy座標を抽出
        Field vanilla = FieldFactory.createField(height);
        vanilla.put(mino, x, y);
        vanilla.insertWhiteLineWithKey(deleteKey);
        int lowerY = vanilla.getLowerY();
        int upperY = vanilla.getUpperYWith4Blocks();
        // 接着に必ず消去されている必要がある行を抽出
        long aboveLowerY = KeyOperators.getMaskForKeyAboveY(lowerY);
        long belowUpperY = KeyOperators.getMaskForKeyBelowY(upperY + 1);
        long keyLine = aboveLowerY & belowUpperY;
        long needDeletedKey = deleteKey & keyLine;
        long usingKey = keyLine & ~needDeletedKey;
        // 操作・消去されている必要がある行をセットで記録
        MinoOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, needDeletedKey, usingKey, lowerY);
        keys.add(operationWithKey);
        // 次のフィールドを作成
        field.put(mino, x, y);
        field.insertBlackLineWithKey(deleteKey);
    }
    return keys;
}
Also used : Field(core.field.Field) ArrayList(java.util.ArrayList) Mino(core.mino.Mino)

Example 49 with Mino

use of core.mino.Mino in project solution-finder by knewjade.

the class MoveSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, MoveSettings settings) throws FinderParseException {
    // テト譜面のエンコード
    List<TetfuPage> decoded = encodeTetfu(data);
    // 指定されたページを抽出
    int page = wrapper.getIntegerOption("page").orElse(1);
    TetfuPage tetfuPage = extractTetfuPage(decoded, page);
    // コメントの抽出
    // 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
    // データ取得時にOptional.emptyがかえるだけ
    String comment = "--clear-line " + tetfuPage.getComment();
    List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    // コマンド引数を配列に変換
    String[] commentArgs = new String[splitComment.size()];
    splitComment.toArray(commentArgs);
    // オプションとして読み込む
    try {
        CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
        CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
        // 削除ラインが読み取れればOK
        newWrapper.getIntegerOption("clear-line");
        wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
    } catch (FinderParseException ignore) {
    }
    // 最大削除ラインの設定
    Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
    maxClearLineOption.ifPresent(settings::setMaxClearLine);
    // フィールドを設定
    ColoredField coloredField = tetfuPage.getField();
    if (tetfuPage.isPutMino()) {
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        ColorConverter colorConverter = new ColorConverter();
        Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
        coloredField.putMino(mino, x, y);
    }
    settings.setField(coloredField);
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) org.apache.commons.cli(org.apache.commons.cli) IOException(java.io.IOException) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper) ColorType(common.tetfu.common.ColorType) ColorConverter(common.tetfu.common.ColorConverter) Mino(core.mino.Mino) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper)

Example 50 with Mino

use of core.mino.Mino in project solution-finder by knewjade.

the class PathCore method createField.

private Field createField(MinoOperationWithKey key, int maxClearLine) {
    Mino mino = key.getMino();
    Field test = FieldFactory.createField(maxClearLine);
    test.put(mino, key.getX(), key.getY());
    test.insertWhiteLineWithKey(key.getNeedDeletedKey());
    return test;
}
Also used : BlockField(common.datastore.BlockField) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) Mino(core.mino.Mino)

Aggregations

Mino (core.mino.Mino)103 Test (org.junit.jupiter.api.Test)46 Rotate (core.srs.Rotate)27 Field (core.field.Field)24 Piece (core.mino.Piece)20 Randoms (lib.Randoms)16 MinoFactory (core.mino.MinoFactory)14 ColorType (common.tetfu.common.ColorType)12 ColoredField (common.tetfu.field.ColoredField)12 ArrayList (java.util.ArrayList)12 FullOperationWithKey (common.datastore.FullOperationWithKey)9 HashSet (java.util.HashSet)9 ColorConverter (common.tetfu.common.ColorConverter)8 OriginalPiece (core.neighbor.OriginalPiece)8 List (java.util.List)8 MinoOperationWithKey (common.datastore.MinoOperationWithKey)7 OperationWithKey (common.datastore.OperationWithKey)7 TetfuPage (common.tetfu.TetfuPage)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7