Skip to content

[US-04] Single-player mode vs. computer opponent

Ivan Esau requested to merge feature/issue-4-us-04-single-player-mode-vs-co into master

Implementation Summary

This merge request implements single-player mode against a computer opponent for the Battleship game, as specified in issue #4.

Features Implemented

  1. Computer Player Class (ComputerPlayer.java)

    • Automatic legal fleet placement (no overlaps/out-of-bounds)
    • Difficulty levels: Easy (random shots) and Standard (hunt-and-target strategy)
    • Smart targeting that avoids repeat shots
    • Hunting mode that targets adjacent cells after hits
  2. Game Integration

    • Single-player game initialization in GameController
    • Computer turn execution in GameService
    • Difficulty selection support
  3. Acceptance Criteria Validation

    • Computer fleet exists and is legal but hidden
    • Computer never targets same coordinate twice
    • Standard difficulty targets adjacent cells after hits

Technical Implementation

  • Computer AI: Strategy pattern for different difficulty levels
  • Fleet Placement: Random placement with fallback systematic placement
  • Targeting: Efficient untargeted position tracking
  • Hunting Mode: Adjacent cell targeting after successful hits

Testing Coverage

  • Unit Tests: ComputerPlayerTest.java covers all acceptance criteria
  • Integration Tests: GameServiceTest.java validates single-player mode integration
  • Test Coverage: All acceptance criteria verified with specific test methods

Pipeline Status

Pipeline #6858: SUCCESS

  • Compile job: Success
  • Test job: Success
  • All tests passing: Verified

Closes #4

Edited by Ivan Esau

Merge request reports

Loading