use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedCandidate method check.
private boolean check(Field field, Mino mino, int x, int y, From from) {
// 一番上までたどり着いたとき
if (appearY <= y)
return true;
Rotate rotate = mino.getRotate();
// すでに訪問済みのとき
if (lockedCache.isVisit(x, y, rotate))
// その時の結果を返却。訪問済みだが結果が出てないときは他の探索でカバーできるためfalseを返却
return lockedCache.isFound(x, y, rotate);
lockedCache.visit(x, y, rotate);
// harddropでたどりつけるとき
if (field.canReachOnHarddrop(mino, x, y)) {
lockedCache.found(x, y, rotate);
return true;
}
// 上に移動
int upY = y + 1;
if (upY < appearY && field.canPut(mino, x, upY)) {
if (check(field, mino, x, upY, From.None)) {
lockedCache.found(x, y, rotate);
return true;
}
}
// 左に移動
int leftX = x - 1;
if (from != From.Left && -mino.getMinX() <= leftX && field.canPut(mino, leftX, y)) {
if (check(field, mino, leftX, y, From.Right)) {
lockedCache.found(x, y, rotate);
return true;
}
}
// 右に移動
int rightX = x + 1;
if (from != From.Right && rightX < FIELD_WIDTH - mino.getMaxX() && field.canPut(mino, rightX, y)) {
if (check(field, mino, rightX, y, From.Left)) {
lockedCache.found(x, y, rotate);
return true;
}
}
// 右回転でくる可能性がある場所を移動
if (checkRightRotation(field, mino, x, y)) {
lockedCache.found(x, y, rotate);
return true;
}
// 左回転でくる可能性がある場所を移動
if (checkLeftRotation(field, mino, x, y)) {
lockedCache.found(x, y, rotate);
return true;
}
return false;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedNeighborCandidate method search.
@Override
public Set<Neighbor> search(Field field, Piece piece, int appearY) {
this.field = field;
HashSet<Neighbor> results = new HashSet<>();
cache.clear();
Set<Rotate> uniqueRotates = minoShifter.getUniqueRotates(piece);
for (Rotate rotate : uniqueRotates) {
Mino mino = minoFactory.create(piece, rotate);
for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
for (int y = -mino.getMinY(); y < appearY - mino.getMaxY(); y++) {
Neighbor neighbor = neighbors.get(piece, rotate, x, y);
if (field.canPut(neighbor.getPiece()) && field.isOnGround(mino, x, y)) {
loop(results, neighbor);
}
}
}
}
return results;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedNeighborReachable method checks.
@Override
public boolean checks(Field field, Mino mino, int x, int y, int appearY) {
assert field.canPut(mino, x, y);
this.field = field;
lockedCache.clear();
Piece piece = mino.getPiece();
Rotate rotate = mino.getRotate();
Neighbor neighbor = neighbors.get(piece, rotate, x, y);
if (checkFirst(neighbor))
return true;
List<Action> actions = minoShifter.enumerateSameOtherActions(piece, rotate, x, y);
for (Action action : actions) if (checkFirst(piece, action.getRotate(), action.getX(), action.getY()))
return true;
return false;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedNeighborReachable method check.
private boolean check(Neighbor neighbor) {
// harddropでたどりつけるとき
OriginalPiece originalPiece = neighbor.getPiece();
if (field.canReachOnHarddrop(originalPiece))
return true;
// すでに訪問済みのとき
int x = originalPiece.getX();
int y = originalPiece.getY();
Rotate rotate = originalPiece.getRotate();
if (lockedCache.isVisit(x, y, rotate))
// 訪問済みだがまだ探索中の場合は、他の探索でカバーできるためfalseを返却
return false;
lockedCache.visit(x, y, rotate);
// 上左右に移動
List<Neighbor> moves = neighbor.getNextMovesSources();
for (Neighbor move : moves) if (field.canPut(move.getPiece()) && check(move))
return true;
// 左回転でくる可能性がある場所を移動
if (checkLeftRotation(neighbor))
return true;
// 右回転でくる可能性がある場所を移動
if (checkRightRotation(neighbor))
return true;
return false;
}
use of core.srs.Rotate 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));
}
Aggregations