use of core.mino.Mino 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 core.mino.Mino 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;
}
use of core.mino.Mino 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 core.mino.Mino in project solution-finder by knewjade.
the class Neighbors method createNeighbors.
private Neighbor[][][][] createNeighbors(OriginalPieceFactory pieceFactory, int maxHeight) {
int maxBlock = Piece.values().length;
int maxRotate = Rotate.values().length;
Neighbor[][][][] neighbors = new Neighbor[maxBlock][maxRotate][maxHeight][FIELD_WIDTH];
Collection<OriginalPiece> pieces = pieceFactory.create();
for (OriginalPiece piece : pieces) {
Mino mino = piece.getMino();
Piece block = mino.getPiece();
Rotate rotate = mino.getRotate();
int x = piece.getX();
int y = piece.getY();
Neighbor neighbor = new Neighbor(piece);
neighbors[block.getNumber()][rotate.getNumber()][y][x] = neighbor;
}
return neighbors;
}
use of core.mino.Mino in project solution-finder by knewjade.
the class Neighbors method updateNeighbor.
private void updateNeighbor(MinoFactory minoFactory, MinoRotation minoRotation, Neighbor current) {
OriginalPiece piece = current.getPiece();
Mino mino = piece.getMino();
int x = piece.getX();
int y = piece.getY();
// 上と左右を更新
current.updateUp(getNeighbor(mino, x, y + 1));
current.updateLeft(getNeighbor(mino, x - 1, y));
current.updateRight(getNeighbor(mino, x + 1, y));
// 左回転でジャンプする先を更新
int[][] patternsLeftDest = minoRotation.getLeftPatternsFrom(mino);
Mino afterLeft = minoFactory.create(mino.getPiece(), mino.getRotate().getLeftRotate());
ArrayList<Neighbor> neighborsLeftDest = createDestinations(afterLeft, x, y, patternsLeftDest);
current.updateLeftRotateDestination(neighborsLeftDest);
// 右回転でジャンプする先を更新
int[][] patternsRightDest = minoRotation.getRightPatternsFrom(mino);
Mino afterRight = minoFactory.create(mino.getPiece(), mino.getRotate().getRightRotate());
ArrayList<Neighbor> neighborsRightDest = createDestinations(afterRight, x, y, patternsRightDest);
current.updateRightRotateDestination(neighborsRightDest);
// 左回転でここにジャンプしてくる元を更新
Mino beforeLeft = minoFactory.create(mino.getPiece(), mino.getRotate().getRightRotate());
int[][] patternsLeftSrc = minoRotation.getLeftPatternsFrom(beforeLeft);
ArrayList<Neighbor> neighborsLeftSrc = createSources(beforeLeft, x, y, patternsLeftSrc);
current.updateLeftRotateSource(neighborsLeftSrc);
// 右回転でここにジャンプしてくる元を更新
Mino beforeRight = minoFactory.create(mino.getPiece(), mino.getRotate().getLeftRotate());
int[][] patternsRightSrc = minoRotation.getRightPatternsFrom(beforeRight);
ArrayList<Neighbor> neighborsRightSrc = createSources(beforeRight, x, y, patternsRightSrc);
current.updateRightRotateSource(neighborsRightSrc);
}
Aggregations