use of core.neighbor.OriginalPiece in project solution-finder by knewjade.
the class SmallFieldTest method testCanPutPiece.
@Test
void testCanPutPiece() {
Randoms randoms = new Randoms();
SmallField field = createRandomSmallField(randoms);
int maxFieldHeight = field.getMaxFieldHeight();
ArrayList<OriginalPiece> pieces = createAllPieces(maxFieldHeight);
for (OriginalPiece piece : pieces) {
Mino mino = piece.getMino();
int x = piece.getX();
int y = piece.getY();
assertThat(field.canPut(piece)).as("%s (%d, %d)", mino, x, y).isEqualTo(field.canPut(mino, x, y));
}
}
use of core.neighbor.OriginalPiece in project solution-finder by knewjade.
the class LockedNeighborCandidate method check.
private boolean check(Neighbor current) {
OriginalPiece piece = current.getPiece();
// ハードドロップで到達できるとき
if (field.canReachOnHarddrop(piece))
return true;
if (cache.isFound(current))
return true;
// すでに訪問済みのとき
if (cache.isVisited(current))
// 訪問済みだが結果が出てないときは他の探索でカバーできるためfalseを返却
return false;
// 訪問済みにする
cache.visit(current);
// 上と左右に移動
List<Neighbor> nextMovesSources = current.getNextMovesSources();
for (Neighbor next : nextMovesSources) {
OriginalPiece nextPiece = next.getPiece();
if (field.canPut(nextPiece) && check(next)) {
cache.found(current);
return true;
}
}
// 左回転でくる可能性がある場所を移動
if (checkLeftRotation(current))
return true;
// 右回転でくる可能性がある場所を移動
if (checkRightRotation(current))
return true;
return false;
}
use of core.neighbor.OriginalPiece 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.neighbor.OriginalPiece in project solution-finder by knewjade.
the class LockedNeighborCandidate method loop.
private void loop(HashSet<Neighbor> results, Neighbor neighbor) {
cache.resetTrail();
if (check(neighbor)) {
results.add(neighbor);
} else {
OriginalPiece piece = neighbor.getPiece();
Mino mino = piece.getMino();
Piece block = mino.getPiece();
List<Action> actions = minoShifter.enumerateSameOtherActions(block, mino.getRotate(), piece.getX(), piece.getY());
for (Action action : actions) {
Neighbor similar = neighbors.get(block, action.getRotate(), action.getX(), action.getY());
if (check(similar))
results.add(similar);
}
}
}
use of core.neighbor.OriginalPiece in project solution-finder by knewjade.
the class LockedNeighborReachableTest method randoms.
@Test
void randoms() {
int maxClearLine = 4;
Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
LockedReachable reachable1 = createLockedReachable(injector, maxClearLine);
LockedNeighborReachable reachable2 = createLockedNeighborReachable(injector, maxClearLine);
OriginalPieceFactory pieceFactory = injector.getInstance(OriginalPieceFactory.class);
Set<OriginalPiece> pieces = pieceFactory.create();
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
Field field = randoms.field(4, 5);
for (OriginalPiece piece : pieces) {
// フィールドにそもそも置けないときは前提条件が合わないためスキップ
if (!field.canPut(piece))
continue;
Mino mino = piece.getMino();
int x = piece.getX();
int y = piece.getY();
boolean checks1 = reachable1.checks(field, mino, x, y, maxClearLine);
boolean checks2 = reachable2.checks(field, mino, x, y, maxClearLine);
assertThat(checks2).as(piece.toString()).isEqualTo(checks1);
}
}
}
Aggregations