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

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:

  1. AI Interface: Created AI interface defining contract for computer opponents
  2. Easy AI: EasyAI class that makes random moves and places ships randomly
  3. Normal AI: NormalAI class with targeting strategy that shoots around hits
  4. Comprehensive Tests: Acceptance criteria tests validating all requirements

Acceptance Criteria Validated:

When single-player mode starts, the computer's fleet exists, is valid and hidden

  • AI places ships correctly without overlaps
  • Ships are within board boundaries
  • Fleet configuration is hidden from player

When the computer makes a move, its shot is at a coordinate not previously targeted

  • Both EasyAI and NormalAI track shot history
  • No duplicate shots allowed
  • Valid coordinate selection

In Normal mode, if a shot hits, following shots should usually try neighboring cells until that ship is sunk

  • 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

Merge request reports

Loading