Play a game of battleship against the AI in the repository's server with your own AI. Information (such as setup of the ships on your AI's board and shots being made towards the server AI's board) is parsed and serialized using Java's Jackson library when your computer and the server communicate with each other.
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. #2
Please note, Sherpa may occasionally provide incomplete or inaccurate information. Always verify critical details and double-check suggested changes before implementation.
Problem Summary
The issue requires updating the Battleship game to support a board size range of 6 to 25 cells, instead of the current range of 6 to 15 cells.
Relevant Files
BattleshipSalvo.java: This file is the main controller for the game, handling player interactions and board initialization.
AbstractPlayer.java: Manages player setup, including the placement of ships on the board.
Board.java: Represents the game board and includes methods for board initialization and dimension changes.
Guidance for Code Changes
BattleshipSalvo.java
Modify Board Initialization: Update the initBoard() method to allow board dimensions between 6 and 25.
Update Error Messages: Ensure that error messages reflect the new valid range.
view.displayString(
"\nInvalid dimensions. The height and width of the\n"
+ "game must be in the range (6, 25) inclusive. Try again:\n"
+ "-".repeat(66)
+ "\n");
AbstractPlayer.java
Update Setup Method: In the setup() method, adjust any logic that assumes a maximum board size of 15 to accommodate the new maximum of 25.
Ensure that ship placements and validations are correctly handled for larger board sizes.
Board.java
Adjust Board Dimensions: Ensure that the changeDimensions() method can handle the new maximum size.
Verify that initCoords() initializes a board correctly with the new dimensions.
Summary
To address the issue, you will need to adjust the board size validation logic in BattleshipSalvo.java to accommodate sizes up to 25. Ensure that all relevant methods in AbstractPlayer.java and Board.java are updated to handle larger board dimensions. This includes validating ship placements and ensuring the board is initialized correctly. The end goal is to support a wider range of board sizes while maintaining the integrity of the game logic.
Problem Summary
The issue requires updating the Battleship game to support a board size range of 6 to 25 cells, instead of the current range of 6 to 15 cells.
Relevant Files
BattleshipSalvo.java
: This file is the main controller for the game, handling player interactions and board initialization.AbstractPlayer.java
: Manages player setup, including the placement of ships on the board.Board.java
: Represents the game board and includes methods for board initialization and dimension changes.Guidance for Code Changes
BattleshipSalvo.java
Modify Board Initialization: Update the
initBoard()
method to allow board dimensions between 6 and 25.Update Error Messages: Ensure that error messages reflect the new valid range.
AbstractPlayer.java
Update Setup Method: In the
setup()
method, adjust any logic that assumes a maximum board size of 15 to accommodate the new maximum of 25.Ensure that ship placements and validations are correctly handled for larger board sizes.
Board.java
Adjust Board Dimensions: Ensure that the
changeDimensions()
method can handle the new maximum size.Verify that
initCoords()
initializes a board correctly with the new dimensions.Summary
To address the issue, you will need to adjust the board size validation logic in
BattleshipSalvo.java
to accommodate sizes up to 25. Ensure that all relevant methods inAbstractPlayer.java
andBoard.java
are updated to handle larger board dimensions. This includes validating ship placements and ensuring the board is initialized correctly. The end goal is to support a wider range of board sizes while maintaining the integrity of the game logic.