# achrafmaz/tic-tac-toe architecture

> Architecture diagram of the GitHub repository achrafmaz/tic-tac-toe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/achrafmaz/tic-tac-toe
- Repository: https://github.com/achrafmaz/tic-tac-toe

## Overview

This repository contains two standalone Pygame Tic-Tac-Toe games: a two-human version and a version where the computer chooses random moves. In each, mouse events drive turns, moves update a NumPy board and draw marks, and the game loop checks for wins or a draw. The files are self-contained rather than sharing runtime modules. The README confirms the Pygame product; the detailed relationships below are supported by the sampled source.

Main entry points: [`tic_tac_toe.py`](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py) (Two-player loop), [`tic_tac_toe_AI.py`](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py) (AI game loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_human["Two-player game"]
  node_two_player_loop["Two-player loop<br/>[tic_tac_toe.py]"]
  node_two_player_moves["Player move handlers<br/>[tic_tac_toe.py]"]
end

subgraph group_computer["Random-AI game"]
  node_ai_loop["AI game loop<br/>[tic_tac_toe_AI.py]"]
  node_ai_moves["Human and AI moves<br/>[tic_tac_toe_AI.py]"]
end

subgraph group_shared["Game mechanics"]
  node_board["Board state<br/>[tic_tac_toe.py]"]
  node_drawing["Pygame drawing<br/>[tic_tac_toe.py]"]
  node_win_checks["Win and draw checks<br/>[tic_tac_toe.py]"]
  node_ai_board["AI board state<br/>[tic_tac_toe_AI.py]"]
  node_ai_drawing["AI game drawing<br/>[tic_tac_toe_AI.py]"]
  node_ai_checks["AI win and draw checks<br/>[tic_tac_toe_AI.py]"]
end

node_player(("Human player"))

node_player -->|"clicks cells"| node_two_player_loop
node_two_player_loop -->|"dispatches turns"| node_two_player_moves
node_two_player_moves -->|"updates"| node_board
node_two_player_moves -->|"draws marks"| node_drawing
node_two_player_loop -->|"checks outcomes"| node_win_checks
node_player -->|"clicks cells"| node_ai_loop
node_ai_loop -->|"dispatches moves"| node_ai_moves
node_ai_moves -->|"updates"| node_ai_board
node_ai_moves -->|"draws marks"| node_ai_drawing
node_ai_loop -->|"checks outcomes"| node_ai_checks

click node_two_player_loop "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py"
click node_two_player_moves "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py"
click node_ai_loop "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py"
click node_ai_moves "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py"
click node_board "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py"
click node_drawing "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py"
click node_win_checks "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py"
click node_ai_board "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py"
click node_ai_drawing "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py"
click node_ai_checks "https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py"

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_two_player_loop,node_two_player_moves toneBlue
class node_ai_loop,node_ai_moves toneAmber
class node_board,node_drawing,node_win_checks,node_ai_board,node_ai_drawing,node_ai_checks toneMint
class node_player toneIndigo
```

## Components

### Two-player game

- [Two-player loop](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py): `tic_tac_toe.py`
- [Player move handlers](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py): `tic_tac_toe.py`

### Random-AI game

- [AI game loop](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py): `tic_tac_toe_AI.py`
- [Human and AI moves](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py): `tic_tac_toe_AI.py`

### Game mechanics

- [Board state](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py): `tic_tac_toe.py`
- [Pygame drawing](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py): `tic_tac_toe.py`
- [Win and draw checks](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe.py): `tic_tac_toe.py`
- [AI board state](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py): `tic_tac_toe_AI.py`
- [AI game drawing](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py): `tic_tac_toe_AI.py`
- [AI win and draw checks](https://github.com/achrafmaz/tic-tac-toe/blob/master/tic_tac_toe_AI.py): `tic_tac_toe_AI.py`

### Other components

- **Human player**

## Connections

- Human player → Two-player loop: clicks cells (evidence: `tic_tac_toe.py`)
- Two-player loop → Player move handlers: dispatches turns (evidence: `tic_tac_toe.py`)
- Player move handlers → Board state: updates (evidence: `tic_tac_toe.py`)
- Player move handlers → Pygame drawing: draws marks (evidence: `tic_tac_toe.py`)
- Two-player loop → Win and draw checks: checks outcomes (evidence: `tic_tac_toe.py`)
- Human player → AI game loop: clicks cells (evidence: `tic_tac_toe_AI.py`)
- AI game loop → Human and AI moves: dispatches moves (evidence: `tic_tac_toe_AI.py`)
- Human and AI moves → AI board state: updates (evidence: `tic_tac_toe_AI.py`)
- Human and AI moves → AI game drawing: draws marks (evidence: `tic_tac_toe_AI.py`)
- AI game loop → AI win and draw checks: checks outcomes (evidence: `tic_tac_toe_AI.py`)
