Skip to content

[US-04] Playing alone against the computer

Ivan Esau requested to merge feature/issue-4-us-04-playing-alone-against-th into master

Description

Implements single-player mode with AI opponent for Battleship game.

Changes

  • Added AI player interface with Easy and Normal difficulty levels
  • Easy AI makes random valid moves
  • Normal AI uses hunt mode strategy (targets neighboring cells after hits)
  • Comprehensive test coverage for both AI implementations
  • Follows layered architecture pattern from planning documents

Requirements Implemented

Single-player mode with automated opponent
Computer places ships in valid positions (no overlaps, within boundaries)
Computer shoots at coordinates not previously targeted
Easy difficulty: Random shooting behavior
Normal difficulty: Hunt mode strategy (targets neighbors after hits)

Acceptance Criteria Validated

When single-player mode starts, computer's fleet exists, is valid and hidden
When computer makes a move, its shot is at coordinate not previously targeted
In Normal mode, if shot hits, following shots try neighboring cells until ship is sunk

Technical Details

  • Package: org.example.ai
  • Classes: AIPlayer (interface), EasyAI, NormalAI
  • Testing: Comprehensive unit tests with JUnit 5
  • Architecture: Follows layered pattern with clear separation of concerns

Closes #4

Merge request reports

Loading