use of core.srs.Rotate in project solution-finder by knewjade.
the class MinoTransform method refresh.
private void refresh() {
for (List<Rotate> reverse : reverseMap.values()) reverse.clear();
for (Rotate rotate : Rotate.values()) {
int index = rotate.getNumber();
Rotate newRotate = rotates[index];
if (newRotate != null && rotate != newRotate) {
// 変換後の回転が同じになる、他の回転とも関連づける
for (Rotate r : reverseMap.get(newRotate)) {
reverseMap.get(r).add(rotate);
reverseMap.get(rotate).add(r);
}
// 変換前と変換後を関連づける
reverseMap.get(newRotate).add(rotate);
reverseMap.get(rotate).add(newRotate);
}
}
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class MinoTransform method enumerateOthers.
List<Action> enumerateOthers(int x, int y, Rotate rotate) {
List<Action> actions = new ArrayList<>();
int currentRotateIndex = rotate.getNumber();
int newX = x + this.offsetsX[currentRotateIndex];
int newY = y + offsetsY[currentRotateIndex];
for (Rotate prevRotate : reverseMap.get(rotate)) {
int index = prevRotate.getNumber();
MinimalAction action = MinimalAction.create(newX - this.offsetsX[index], newY - offsetsY[index], prevRotate);
actions.add(action);
}
return actions;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedReachable method checkLeftRotation.
private boolean checkLeftRotation(Field field, Mino mino, int x, int y) {
Rotate currentRotate = mino.getRotate();
Mino minoBefore = minoFactory.create(mino.getPiece(), currentRotate.getRightRotate());
// 右回転前のテストパターンを取得
int[][] patterns = minoRotation.getLeftPatternsFrom(minoBefore);
for (int[] pattern : patterns) {
int fromX = x - pattern[0];
int fromY = y - pattern[1];
if (canPutMinoInField(field, minoBefore, fromX, fromY)) {
int[] kicks = minoRotation.getKicksWithLeftRotation(field, minoBefore, mino, fromX, fromY);
if (kicks != null && pattern[0] == kicks[0] && pattern[1] == kicks[1])
if (check(field, minoBefore, fromX, fromY, From.None))
return true;
}
}
return false;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class LockedReachable 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 false;
lockedCache.visit(x, y, rotate);
// harddropでたどりつけるとき
if (field.canReachOnHarddrop(mino, x, y))
return true;
// 上に移動
int upY = y + 1;
if (upY < appearY && field.canPut(mino, x, upY))
if (check(field, mino, x, upY, From.None))
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))
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))
return true;
// 右回転でくる可能性がある場所を移動
if (checkRightRotation(field, mino, x, y))
return true;
// 左回転でくる可能性がある場所を移動
if (checkLeftRotation(field, mino, x, y))
return true;
return false;
}
use of core.srs.Rotate in project solution-finder by knewjade.
the class ActionParserTest method parseToOperation.
@Test
void parseToOperation() throws Exception {
for (Piece piece : Piece.values()) {
for (Rotate rotate : Rotate.values()) {
for (int y = 0; y < 24; y++) {
for (int x = 0; x < 10; x++) {
int value = ActionParser.parseToInt(piece, rotate, x, y);
assertThat(ActionParser.parseToOperation(value)).isEqualTo(new SimpleOperation(piece, rotate, x, y));
}
}
}
}
}
Aggregations