[US-04] Single-player mode vs. computer opponent
Implementation Summary
This merge request implements the single-player mode with computer opponent functionality for the Battleship game as specified in issue #4.
Requirements Implemented
-
ComputerPlayer.placeFleetAutomatically()method handles automatic ship placement - Validates all placements to ensure no overlaps and within bounds
- Uses standard fleet sizes: Carrier (5), Battleship (4), Destroyer (3), Submarine (3), Patrol Boat (2)
-
ComputerPlayer.generateShotPosition()ensures all shots are at untargeted positions - Both Easy and Standard difficulty levels avoid duplicate shots
- Comprehensive test coverage for shot validation
-
Difficultyenum with EASY and STANDARD levels - Easy: Pure random shot selection
- Standard: Hunting strategy that targets adjacent cells after hits
- Smart targeting logic with potential target tracking
Acceptance Criteria Validated
- Tested in
testPlaceFleetAutomatically() - Computer fleet placement validated for legality
- Fleet remains hidden from human player
- Tested in
testNoDuplicateShots()andtestEasyDifficultyRandomShots() - Both difficulty levels verified to avoid duplicate shots
- Shot history tracking validated
- Tested in
testStandardDifficultyAdjacentTargeting() - Hunting mode activation after hits verified
- Adjacent cell targeting strategy validated
Technical Implementation
Core Classes:
-
ComputerPlayer: Extends Player with AI logic for ship placement and targeting -
Difficulty: Enum defining EASY and STANDARD difficulty levels -
Game: Enhanced with single-player mode constructor and computer turn execution
Key Features:
- Automatic legal fleet placement for computer
- Difficulty-based shot generation
- Hunting strategy for Standard difficulty
- Turn-based gameplay with computer opponent
- Comprehensive test coverage for all acceptance criteria
AI Strategy:
- Easy: Pure random selection from untargeted positions
- Standard: Random initially, switches to hunting mode after hits
- Hunting mode targets adjacent cells systematically
- Potential target tracking for efficient ship sinking
Test Coverage:
- Unit tests for ComputerPlayer AI logic
- Integration tests for single-player game flow
- Acceptance criteria validation tests
- Edge case handling (corner positions, duplicate shots)
Closes #4