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 with two difficulty levels:

Features Implemented:

  • Single-Player Mode: Play against computer AI
  • Difficulty Levels: Easy (random shots) and Standard (hunt-and-target strategy)
  • Legal Fleet Placement: Computer automatically places ships without overlaps or out-of-bounds
  • Smart Targeting: Computer avoids repeating shots and uses hunt-and-target algorithm

Requirements Met:

  1. Single-Player Mode: Computer places legal fleet (no overlaps/out-of-bounds, standard sizes)
  2. Valid Targeting: Computer selects valid untargeted coordinates and avoids repeats
  3. Difficulty Options: Easy (random shots) and Standard (hunt-and-target after hits)

Acceptance Criteria Verified:

  • Given Single-Player is chosen, when the match starts, then the computer's fleet exists and is legal but hidden
  • Given the computer took a turn, when the history is inspected, then its shot is at a previously untargeted coordinate
  • Given Standard difficulty and a computer hit, when subsequent computer turns occur, then at least one subsequent shot targets an adjacent cell until the ship is sunk

Technical Implementation:

  • ComputerPlayer Class: AI logic with difficulty-based targeting
  • Hunt-and-Target Algorithm: After hits, preferentially targets adjacent cells
  • Legal Placement: Systematic ship placement with fallback algorithms
  • Comprehensive Testing: Unit tests verify all acceptance criteria

Pipeline Status:

  • Pipeline #6062: SUCCESS
  • All tests passing: 100%
  • Code compilation: SUCCESS

Closes #4 (closed)

Merge request reports

Loading