[US-04] Playing alone against the computer
🎮 Single-Player Computer Opponent Implementation
This merge request implements the single-player mode for the Battleship game, allowing players to play against an automated computer opponent.
✅ Features Implemented
Computer Player AI:
- Easy Difficulty: Random shot selection
- Normal Difficulty: Smart targeting near hits with hunting strategy
- Automatic Ship Placement: Valid ship placement without overlaps
- Duplicate Shot Prevention: Computer avoids shooting at previously targeted coordinates
Game Flow:
- Single-player mode selection in main menu
- Alternating turns between human and computer
- Ship placement phase for both players
- Gameplay phase with hit/miss feedback
- Game end detection and winner announcement
Acceptance Criteria Met:
-
✅ When single-player mode starts, the computer's fleet exists, is valid and hidden -
✅ When the computer makes a move, its shot is at a coordinate not previously targeted -
✅ In Normal mode, if a shot hits, following shots target neighboring cells until ship is sunk
🔧 Technical Implementation
New Classes:
-
ComputerPlayer- AI opponent with difficulty levels -
GameService- Manages single-player game flow
Key Methods:
-
placeShipsAutomatically()- Valid ship placement -
generateShot()- AI shot generation based on difficulty -
recordShotResult()- Smart targeting for Normal difficulty -
startSinglePlayerGame()- Complete game flow
📊 Testing
Comprehensive test coverage including:
- Computer player creation and difficulty levels
- Automatic ship placement validation
- Shot generation without duplicates
- Smart targeting behavior
- Game service integration
Closes #4