giovabattelli / terminal-battleship

Play a game of battleship (with modified game rules) against a basic AI in the terminal.
0 stars 0 forks source link

Add support for a battleship board of size 25 cells; instead of board size being between 6-15, it can be between 6-25 cells. #60

Open giovabattelli opened 1 month ago

ghost commented 1 month ago

Please note, Sherpa may occasionally provide incomplete or inaccurate information. Always verify critical details and double-check suggested changes before implementation.

Summary of the Problem

The issue at hand is to modify the battleship game to support a board size ranging from 6 to 25 cells, instead of the current limitation of 6 to 15 cells. This involves updating the relevant code to accommodate the new board size constraints.

Relevant Files

Guidance on Required Changes

1. AbstractPlayer.java

@Override
public List<Ship> setup(int height, int width, Map<ShipType, Integer> specifications) {
    // Update validation logic here
}

2. BattleshipSalvo.java

if (height < 6 || height > 25 || width < 6 || width > 25 || inputs.length > 2) {
    throw new Exception();
}

3. Board.java

public Board(int height, int width) {
    this.coords = new Coord[height][width];
    initCoords();
}

4. Player.java

/**
 * @param height         the height of the board, range: [6, 25] inclusive
 * @param width          the width of the board, range: [6, 25] inclusive
 */

5. ViewImpl.java

view.displayString("Please enter a valid board height and width below:\n" +
                   "Height and width must be in the range (6, 25) inclusive.\n");

Summary of Approach

To implement the changes, you will need to adjust the relevant files to remove the constraints on board size and replace them with the new limits of 6 to 25 cells. Focus on validating the inputs in the BattleshipSalvo controller and ensure that the AbstractPlayer and Board classes can handle the new dimensions properly. After making these changes, thoroughly test the application to confirm that it behaves correctly with the expanded board size.