[US-04] Single-player mode vs. computer opponent
Description
Implements single-player mode with computer opponent for the Battleship game.
Requirements Implemented
1) Single-Player Mode with Legal Fleet Placement
- Computer places a legal fleet with standard ship sizes (Carrier: 5, Battleship: 4, Destroyer: 3, Submarine: 3, Patrol Boat: 2)
- No overlaps or out-of-bounds placements
- Fleet remains hidden from human player
2) Computer Turn Logic
- Computer selects valid untargeted coordinates
- Avoids repeat shots
- Implements difficulty-based targeting strategies
3) Difficulty Options
- Easy: Random valid shots
- Standard: Hunt-and-target algorithm after hits (preferentially targets adjacent cells)
Acceptance Criteria Verified
- ComputerPlayer class implements automatic fleet placement
- Fleet validation ensures legal placement
- Hidden board implementation
- Shot history tracking
- Coordinate validation prevents repeats
- Hunt-and-target algorithm implementation
- Adjacent cell targeting logic
- Ship sinking detection
Technical Implementation
Core Components
-
ComputerPlayer.java- AI player implementation with difficulty levels -
Difficulty.java- Enum for difficulty levels (EASY, STANDARD) -
GameService.java- Game logic integration -
Board.java- Enhanced with computer fleet placement
Testing
-
ComputerPlayerTest.java- Unit tests for AI logic -
DifficultyTest.java- Difficulty level validation -
GameServiceTest.java- Integration tests -
AcceptanceCriteriaTest.java- Acceptance criteria validation
Files Modified/Created
src/main/java/org/example/model/ComputerPlayer.javasrc/main/java/org/example/model/Difficulty.javasrc/main/java/org/example/model/Game.javasrc/main/java/org/example/service/GameService.javasrc/test/java/org/example/model/ComputerPlayerTest.javasrc/test/java/org/example/model/DifficultyTest.javasrc/test/java/org/example/service/GameServiceTest.javasrc/test/java/org/example/AcceptanceCriteriaTest.java
Pipeline Status
- Pipeline #6676:
✅ SUCCESS (compile + test jobs passed) - Latest pipeline #6687:
⏳ PENDING
Closes #4