use of common.tetfu.field.ColoredField in project solution-finder by knewjade.
the class PathSettings method setField.
void setField(ColoredField coloredField, int height) {
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);
setReservedBlock(null);
}
use of common.tetfu.field.ColoredField 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.field.ColoredField 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.field.ColoredField in project solution-finder by knewjade.
the class EasyTetfu method parseBlockFieldToTetfuElement.
private TetfuElement parseBlockFieldToTetfuElement(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 Tetfu method decodeMain.
private List<TetfuPage> decodeMain(String str) {
LinkedList<Integer> values = str.replace("?", "").chars().boxed().map(c -> decodeData((char) c.intValue())).collect(Collectors.toCollection(LinkedList::new));
ArrayList<TetfuPage> pages = new ArrayList<>();
ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
ColoredField currentField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
int[] blockUp = new int[FILED_WIDTH];
int repeatCount = -1;
while (!values.isEmpty()) {
if (repeatCount <= 0) {
int index = 0;
boolean isChange = false;
while (index < TETFU_FIELD_BLOCKS) {
int diffBlock = pollValues(values, 2);
int diff = diffBlock / TETFU_FIELD_BLOCKS;
int block = diffBlock % TETFU_FIELD_BLOCKS;
if (block != TETFU_FIELD_BLOCKS - 1)
isChange = true;
for (int b = 0; b < block + 1; b++) {
int x = index % 10;
int y = TETFU_FIELD_TOP - (index / 10) - 1;
if (0 <= y) {
int prevBlockNumber = prevField.getBlockNumber(x, y);
currentField.setBlockNumber(x, y, diff + prevBlockNumber - 8);
} else {
blockUp[x] += diff - 8;
}
index += 1;
}
}
if (!isChange)
repeatCount = pollValues(values, 1);
} else {
currentField = prevField;
repeatCount -= 1;
}
int action = pollValues(values, 3);
ActionDecoder actionDecoder = new ActionDecoder(action);
String escapedComment = "";
if (actionDecoder.isComment) {
List<Integer> commentValues = new ArrayList<>();
int commentLength = pollValues(values, 2);
for (int commentCounter = 0; commentCounter < (commentLength + 3) / 4; commentCounter++) {
int commentValue = pollValues(values, 5);
commentValues.add(commentValue);
}
CommentDecoder commentDecoder = new CommentDecoder(commentLength, commentValues);
escapedComment = commentDecoder.getEscapedComment();
}
TetfuPage tetfuPage = new DecodedTetfuPage(actionDecoder, escapedComment, currentField);
pages.add(tetfuPage);
ColorType colorType = actionDecoder.colorType;
if (actionDecoder.isLock) {
if (ColorType.isMinoBlock(colorType)) {
Rotate rotate = actionDecoder.rotate;
Coordinate coordinate = actionDecoder.coordinate;
Piece piece = converter.parseToBlock(colorType);
Mino mino = minoFactory.create(piece, rotate);
currentField.putMino(mino, coordinate.x, coordinate.y);
}
currentField.clearLine();
if (actionDecoder.isBlockUp) {
currentField.blockUp();
for (int x = 0; x < TETFU_FIELD_WIDTH; x++) currentField.setBlockNumber(x, 0, blockUp[x]);
}
if (actionDecoder.isMirror)
currentField.mirror();
}
prevField = currentField;
}
return pages;
}
Aggregations