Search in sources :

Example 26 with Rotate

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

the class ActionParserTest method parseToInt.

@Test
void parseToInt() 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 expected = ActionParser.parseToInt(piece, MinimalAction.create(x, y, rotate));
                    assertThat(ActionParser.parseToInt(piece, rotate, x, y)).isEqualTo(expected);
                }
            }
        }
    }
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Test(org.junit.jupiter.api.Test)

Example 27 with Rotate

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

the class ActionEncoder method parseRotate.

private int parseRotate(TetfuElement element) {
    ColorType type = element.getColorType();
    Rotate rotate = element.getRotate();
    if (!ColorType.isMinoBlock(type))
        return 0;
    switch(rotate) {
        case Reverse:
            return 0;
        case Right:
            return type != ColorType.I ? 1 : 3;
        case Spawn:
            return 2;
        case Left:
            return type != ColorType.I ? 3 : 1;
    }
    throw new IllegalStateException("No reachable");
}
Also used : Rotate(core.srs.Rotate) ColorType(common.tetfu.common.ColorType)

Example 28 with Rotate

use of core.srs.Rotate 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 29 with Rotate

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

the class PngWriter method write.

@Override
public void write(List<TetfuPage> tetfuPages) throws IOException {
    int page = startPageIndex + 1;
    for (TetfuPage tetfuPage : tetfuPages) {
        String path = String.format("%s_%03d.png", prefix, page);
        // リセット
        figGenerator.reset();
        // 現在のミノを取得
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        Mino mino = ColorType.isMinoBlock(colorType) ? minoFactory.create(colorConverter.parseToBlock(colorType), rotate) : null;
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        // フィールドの更新
        ColoredField field = tetfuPage.getField();
        figGenerator.updateField(field, mino, x, y);
        // ミノを置くかチェック
        if (ColorType.isMinoBlock(colorType)) {
            // 現在のミノの更新
            figGenerator.updateMino(colorType, rotate, x, y);
            // bagの更新
            Piece piece = colorConverter.parseToBlock(colorType);
            bag.use(piece);
        }
        // ネクストの更新
        figGenerator.updateNext(bag.getNext(nextBoxCount));
        // ホールドの更新
        figGenerator.updateHold(bag.getHold());
        // 画像の生成
        BufferedImage image = figGenerator.fix();
        // 画像の出力
        ImageIO.write(image, "png", new File(path));
        page++;
    }
}
Also used : TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 30 with Rotate

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

the class OperationsTest method createRandomOperation.

private Operation createRandomOperation(Randoms randoms) {
    Piece piece = randoms.block();
    Rotate rotate = randoms.rotate();
    int x = randoms.nextInt(10);
    int y = randoms.nextInt(20);
    return new SimpleOperation(piece, rotate, x, y);
}
Also used : 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