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);
}
}
}
}
}
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");
}
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;
}
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++;
}
}
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);
}
Aggregations