Search in sources :

Example 6 with OriginalPiece

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));
    }
}
Also used : Randoms(lib.Randoms) Mino(core.mino.Mino) OriginalPiece(core.neighbor.OriginalPiece) Test(org.junit.jupiter.api.Test)

Example 7 with OriginalPiece

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;
}
Also used : Neighbor(core.neighbor.Neighbor) OriginalPiece(core.neighbor.OriginalPiece)

Example 8 with OriginalPiece

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;
}
Also used : Rotate(core.srs.Rotate) Neighbor(core.neighbor.Neighbor) OriginalPiece(core.neighbor.OriginalPiece)

Example 9 with OriginalPiece

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);
        }
    }
}
Also used : Action(common.datastore.action.Action) Piece(core.mino.Piece) OriginalPiece(core.neighbor.OriginalPiece) Neighbor(core.neighbor.Neighbor) Mino(core.mino.Mino) OriginalPiece(core.neighbor.OriginalPiece)

Example 10 with OriginalPiece

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);
        }
    }
}
Also used : Field(core.field.Field) Randoms(lib.Randoms) Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Mino(core.mino.Mino) OriginalPiece(core.neighbor.OriginalPiece) OriginalPieceFactory(core.neighbor.OriginalPieceFactory) Test(org.junit.jupiter.api.Test)

Aggregations

OriginalPiece (core.neighbor.OriginalPiece)10 Mino (core.mino.Mino)8 Test (org.junit.jupiter.api.Test)7 Randoms (lib.Randoms)5 Neighbor (core.neighbor.Neighbor)3 Injector (com.google.inject.Injector)1 Action (common.datastore.action.Action)1 Field (core.field.Field)1 Piece (core.mino.Piece)1 OriginalPieceFactory (core.neighbor.OriginalPieceFactory)1 Rotate (core.srs.Rotate)1 BasicModule (module.BasicModule)1