use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class PathSettings method setFieldWithReserved.
void setFieldWithReserved(ColoredField coloredField, int height) {
Field field = FieldFactory.createField(height);
BlockField blockField = new BlockField(height);
for (int y = 0; y < height; y++) {
for (int x = 0; x < 10; x++) {
ColorConverter colorConverter = new ColorConverter();
ColorType colorType = colorConverter.parseToColorType(coloredField.getBlockNumber(x, y));
switch(colorType) {
case Empty:
break;
case Gray:
field.setBlock(x, y);
break;
default:
Piece piece = colorConverter.parseToBlock(colorType);
blockField.setBlock(piece, x, y);
break;
}
}
}
setField(field);
setReservedBlock(blockField);
}
use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class FigUtilSettings method adjust.
void adjust() {
// Quizがない場合はホールドは使えない
boolean isUsingQuiz = tetfuPages.subList(0, startPage).stream().map(TetfuPage::getComment).anyMatch(s -> s.startsWith("#Q="));
if (!isUsingQuiz)
setUsingHold(false);
// 高さの指定がないときは最も高い場所 + 1とする
if (this.height == -1) {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
OptionalInt maxHeight = tetfuPages.subList(startPage - 1, endPage).stream().mapToInt(page -> {
ColoredField field = page.getField();
int fieldHeight = field.getUsingHeight();
ColorType colorType = page.getColorType();
if (ColorType.isMinoBlock(colorType)) {
Piece piece = colorConverter.parseToBlock(colorType);
Rotate rotate = page.getRotate();
Mino mino = minoFactory.create(piece, rotate);
int minoHeight = page.getY() + mino.getMaxY() + 1;
return fieldHeight < minoHeight ? minoHeight : fieldHeight;
} else {
return fieldHeight;
}
}).max();
this.height = maxHeight.orElse(0) + 1;
if (height <= 0)
this.height = 1;
else if (23 <= height)
this.height = 23;
}
// ホールドを使わない場合はRightに変更
if (!this.isUsingHold && frameType == FrameType.Basic) {
frameType = FrameType.Right;
}
// ネクストがない場合はチェックは必要がない
if (frameType == FrameType.NoFrame) {
return;
}
// フィールドの高さを計算し、その高さで置けるネクスト数を計算
int fieldHeight = 34 * this.height + 2;
int canPutCount = (fieldHeight - 5) / 52;
// ネクスト (& ホールド)で必要な個数を算出し、ネクストを置けるならチェック終了
int count = this.isUsingHold && frameType == FrameType.Right ? nextBoxCount + 1 : nextBoxCount;
if (count <= canPutCount)
return;
// ネクストを置けるようにフィールドの高さを調整
int needHeightPx = 52 * count + 5;
setHeight((int) Math.ceil((needHeightPx - 2) / 34.0));
}
use of common.tetfu.common.ColorConverter 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 common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class SetupSettingParser method encodeTetfu.
private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
String data = Tetfu.removePrefixData(encoded);
if (data == null)
throw new FinderParseException("Unsupported tetfu: data=" + encoded);
return tetfu.decode(data);
}
use of common.tetfu.common.ColorConverter in project solution-finder by knewjade.
the class FigUtilSettingParser method encodeTetfu.
private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
String data = Tetfu.removePrefixData(encoded);
if (data == null)
throw new FinderParseException("Unsupported tetfu: data=" + encoded);
return tetfu.decode(data);
}
Aggregations