use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class Tetfu method encode.
// コメント・フィールドは初期設定のみ設定可能
public String encode(List<TetfuElement> elements) {
ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
String prevComment = "";
for (int index = 0; index < elements.size(); index++) {
TetfuElement element = elements.get(index);
ColoredField field = element.getField().orElse(prevField);
// field settings
// prevFieldは、ひとつ前のミノを置いてできたフィールド
// fieldは次に表示させたいフィールド。今回は、最初をのぞいてひとつ前のミノを置いてできたフィールドをそのまま利用
encodeField(prevField, field);
String comment = element.getEscapedComment();
ActionFlags flags = new ActionFlags(comment, prevComment, index, element);
parseAction(element, flags);
ColorType colorType = element.getColorType();
if (flags.isLock) {
if (ColorType.isMinoBlock(colorType)) {
Piece piece = converter.parseToBlock(colorType);
Mino mino = minoFactory.create(piece, element.getRotate());
field.putMino(mino, element.getX(), element.getY());
}
field.clearLine();
if (flags.isBlockUp) {
throw new UnsupportedOperationException();
// currentField.blockUp();
// for (int x = 0; x < TETFU_FIELD_WIDTH; x++)
// currentField.setBlockNumber(x, 0, blockUp[x]);
}
if (flags.isMirror) {
throw new UnsupportedOperationException();
// currentField.mirror();
}
}
// next field
prevField = field;
prevComment = comment;
}
StringBuilder builder = new StringBuilder();
for (int index = 0; index < encodedValues.size(); index++) {
Integer value = encodedValues.get(index);
String encoded = TetfuTable.encodeData(value);
builder.append(encoded);
if (index % 47 == 41)
builder.append('?');
}
return builder.toString();
}
use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class MoveEntryPoint method parseColorElement.
private TetfuElement parseColorElement(Field initField, ColorConverter colorConverter, BlockField blockField, String comment) {
ColoredField coloredField = ColoredFieldFactory.createGrayField(initField);
for (Piece piece : Piece.values()) {
Field target = blockField.get(piece);
ColorType colorType = colorConverter.parseToColorType(piece);
fillInField(coloredField, colorType, target);
}
return new TetfuElement(coloredField, ColorType.Empty, Rotate.Reverse, 0, 0, comment);
}
use of common.tetfu.field.ColoredField 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.field.ColoredField in project solution-finder by knewjade.
the class MoveSettings method setField.
void setField(ColoredField coloredField) {
int usingHeight = coloredField.getUsingHeight();
int height = maxClearLine < usingHeight ? usingHeight : maxClearLine;
Field field = FieldFactory.createField(height);
for (int y = 0; y < height; y++) for (int x = 0; x < 10; x++) if (coloredField.getColorType(x, y) != ColorType.Empty)
field.setBlock(x, y);
setField(field);
setMaxClearLine(height);
}
use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class SetupSettingParser method parseField.
private void parseField(String fieldMarks, SetupSettings settings, int maxHeightForce) {
ColoredField coloredField = ColoredFieldFactory.createColoredField(fieldMarks);
int maxHeight = maxHeightForce != -1 ? maxHeightForce : coloredField.getUsingHeight();
// Load init field
String initFieldMarks = fieldMarks.replace(".", "_").replace("*", "_");
Field initField = FieldFactory.createField(initFieldMarks);
for (int y = maxHeight; y < initField.getMaxFieldHeight(); y++) for (int x = 0; x < 10; x++) initField.removeBlock(x, y);
// Load need filled field
String needFilledFieldMarks = filterString(fieldMarks, '*', '_');
Field needFilledField = FieldFactory.createField(needFilledFieldMarks);
for (int y = maxHeight; y < needFilledField.getMaxFieldHeight(); y++) for (int x = 0; x < 10; x++) needFilledField.removeBlock(x, y);
// Load not filled field
Field notFilledField = FieldFactory.createInverseField(fieldMarks.replace("X", "_"));
for (int y = maxHeight; y < notFilledField.getMaxFieldHeight(); y++) for (int x = 0; x < 10; x++) notFilledField.removeBlock(x, y);
if (settings.isReserved()) {
settings.setFieldWithReserved(initField, needFilledField, notFilledField, coloredField, maxHeight);
} else {
settings.setField(initField, needFilledField, notFilledField, maxHeight);
}
}
Aggregations