[US-04] Playing alone against the computer
Implementation Summary
This merge request implements the single-player mode for the Battleship game, allowing players to play against computer opponents with different difficulty levels.
Features Implemented:
-
AI Interface: Created
AIinterface defining contract for computer opponents -
Easy AI:
EasyAIclass that makes random moves and places ships randomly -
Normal AI:
NormalAIclass with targeting strategy that shoots around hits - Comprehensive Tests: Acceptance criteria tests validating all requirements
Acceptance Criteria Validated:
- AI places ships correctly without overlaps
- Ships are within board boundaries
- Fleet configuration is hidden from player
- Both EasyAI and NormalAI track shot history
- No duplicate shots allowed
- Valid coordinate selection
- NormalAI uses targeting queue for adjacent coordinates
- Prioritizes shots around successful hits
- Falls back to random when targeting exhausted
Technical Implementation:
- AI Interface: Standardized contract for all AI implementations
- EasyAI: Random ship placement and shooting
- NormalAI: Advanced targeting with hit tracking
- Test Coverage: Comprehensive acceptance tests for all criteria
Files Modified:
-
src/main/java/org/example/ai/AI.java- AI interface -
src/main/java/org/example/ai/EasyAI.java- Easy difficulty implementation -
src/main/java/org/example/ai/NormalAI.java- Normal difficulty with targeting -
src/test/java/org/example/ai/AIAcceptanceTest.java- Acceptance criteria tests -
src/test/java/org/example/ai/EasyAITest.java- Unit tests for EasyAI -
src/test/java/org/example/ai/NormalAITest.java- Unit tests for NormalAI
Closes #4