# mcgarity99/terminal_battleship architecture

> Architecture diagram of the GitHub repository mcgarity99/terminal_battleship, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mcgarity99/terminal_battleship
- Repository: https://github.com/mcgarity99/terminal_battleship

## Overview

Terminal_Battleship is a single-file C++ command-line Battleship game: the player plays against a basic computer opponent, with randomly placed ships and ASCII board output. The main function initializes the boards, sets up fleets and mines, then runs gameplay; presentation and computer targeting are separate responsibilities within the same source file. The excerpts show initialization and ship placement, but omit much of the turn loop, so gameplay-to-firing and AI dispatch links are not asserted.

Main entry points: [`BattleshipGame.cpp`](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp) (Game controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Game setup"]
  node_boards["Board initialization<br/>[BattleshipGame.cpp]"]
  node_fleet["Fleet placement<br/>[BattleshipGame.cpp]"]
  node_mines["Mine placement<br/>[BattleshipGame.cpp]"]
end

subgraph group_play["Battle and AI"]
  node_main["Game controller<br/>[BattleshipGame.cpp]"]
  node_fire["Player firing<br/>[BattleshipGame.cpp]"]
  node_computer["Computer opponent<br/>[BattleshipGame.cpp]"]
end

subgraph group_display["Terminal display"]
  node_boards_view["Board display<br/>[BattleshipGame.cpp]"]
end

node_player(("Player"))
node_terminal["Command-line terminal"]

node_player -->|"plays through"| node_main
node_main -->|"initializes"| node_boards
node_main -->|"places ships"| node_fleet
node_main -->|"places mines"| node_mines
node_main -.->|"runs turns"| node_fire
node_main -.->|"uses opponent"| node_computer
node_main -.->|"displays boards"| node_boards_view
node_boards_view -->|"prints ASCII"| node_terminal
node_player -.->|"fires at fleet"| node_fire
node_computer -.->|"fires at player"| node_fire

click node_main "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_boards "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_fleet "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_mines "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_fire "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_computer "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"
click node_boards_view "https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_boards,node_fleet,node_mines toneBlue
class node_main,node_fire,node_computer toneAmber
class node_boards_view toneMint
class node_player,node_terminal toneIndigo
```

## Components

### Game setup

- [Board initialization](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`
- [Fleet placement](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`
- [Mine placement](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`

### Battle and AI

- [Game controller](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`
- [Player firing](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`
- [Computer opponent](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`

### Terminal display

- [Board display](https://github.com/mcgarity99/terminal_battleship/blob/main/BattleshipGame.cpp): `BattleshipGame.cpp`

### Other components

- **Player**
- **Command-line terminal**

## Connections

- Player → Game controller: plays through (evidence: `README.md`)
- Game controller → Board initialization: initializes (evidence: `BattleshipGame.cpp`)
- Game controller → Fleet placement: places ships (evidence: `BattleshipGame.cpp`)
- Game controller → Mine placement: places mines (evidence: `BattleshipGame.cpp`)
- Game controller → Player firing: runs turns (evidence: `BattleshipGame.cpp`)
- Game controller → Computer opponent: uses opponent (evidence: `BattleshipGame.cpp`)
- Game controller → Board display: displays boards (evidence: `BattleshipGame.cpp`)
- Board display → Command-line terminal: prints ASCII (evidence: `README.md`)
- Player → Player firing: fires at fleet
- Computer opponent → Player firing: fires at player (evidence: `BattleshipGame.cpp`)
