[US-04] Single-player mode vs. computer opponent
Description
Implements single-player mode with computer AI opponent for the Battleship game.
Features
-
Computer Player AI: New
ComputerPlayerclass with two difficulty levels- Easy: Random valid shots
- Standard: Hunt/target strategy after hits
- Legal Fleet Placement: Computer automatically places legal fleet (no overlaps, within bounds)
-
Single-Player Game Mode: New constructor in
Gameclass for single-player games - AI Learning: Standard difficulty learns from hits and targets adjacent cells
- No Duplicate Shots: Computer never shoots at the same coordinate twice
Technical Implementation
- ComputerPlayer.java: Complete AI implementation with ship placement and targeting logic
- Game.java: Extended with single-player mode support and computer turn execution
- Comprehensive Tests: Full test coverage for all AI behaviors and acceptance criteria
Acceptance Criteria Verified
- Computer places all 5 ships legally (no overlaps, within bounds)
- Fleet remains hidden from human player
- Computer maintains list of available shots
- Never shoots at same coordinate twice
- Valid coordinates within board bounds
- Standard difficulty implements hunt/target strategy
- After hit, targets adjacent cells systematically
- Clears hit sequence after ship is sunk
Files Modified/Created
-
src/main/java/org/example/model/ComputerPlayer.java- New computer AI implementation -
src/main/java/org/example/controller/Game.java- Extended for single-player mode -
src/test/java/org/example/model/ComputerPlayerTest.java- Comprehensive AI tests -
src/test/java/org/example/controller/GameTest.java- Single-player mode integration tests
Testing
- All acceptance criteria covered by unit tests
- Integration tests for single-player game flow
- Edge case testing for AI behaviors
- 100% test coverage for new functionality
Closes #4