Question: Board.java public int getWidth(){ // returns the width of the board -- O(1) return board.size()>0?board.get(0).size():0; } public

Board.java
public int getWidth(){ // returns the width of the board -- O(1)

        return board.size()>0?board.get(0).size():0;

    }

    public int getHeight(){ // returns the height of the board -- O(1)

        return board.size();

    }

    public void setTile(int y, int x, Tile t){ // sets the tile at location y,x -- O(1)

        if (y >= 0 && y < board.size() && x >= 0 && x < board.get(y).size()) {

            board.get(y).set(x, t);

        }

    }

    public Tile getTile(int y, int x){ // gets the tile from location y,x -- O(1)

        // return board.get(y).get(x);

        if (y >= 0 && y < board.size() && x >= 0 && x < board.get(y).size()) {

            return board.get(y).get(x);

        } else {

            throw new RuntimeException("Invalid indices provided for getTile");

        }

    }


Block.java
public int getY() 

    {

        return y;

    }

    public int getX() 

    {

        return x;

    }

 public void setTile(int y, int x, Tile t)
    {
        block.get(y).set(x, t);
    }

    public Tile getTile(int y, int x) {
        if (isValidIndex(y, x)) {
            DynamicArray row = block.get(y);
            if (row != null && x < row.size()) {
                return row.get(x);
            } else {
                // Handle invalid column index
                throw new RuntimeException("Invalid column index provided for getTile");
            }
        } else {
            // Handle invalid row index
            throw new RuntimeException("Invalid row index provided for getTile");
        }
    }

When I have a block that has many null values, such as:
[x] [] []
[] [] []
[] [] []
since there are no tiles on the right side, the block can not move all the way to the right. however, I want the block reach to the edge on the right side, even if the block has many null values on the right edge.
Tetris.java
public static boolean canMoveRight(Board board, Block block) // O(board_size)

{
}


When I have a block that has many null values, such as:
[] [] [x]
[] [] []
[] [] []
since there are no tiles on the leftside, the block can not move all the way to the left. however, I want the block reach to the edge on the leftside, even if the block has many null values on the left edge.
Tetris.java
 public static boolean canMoveLeft(Board board, Block block) // O(board_size)

{
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To determine whether a block can move all the way to the right or left edge of the board you need to consider the positions of the blocks tiles and th... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!