# coding-pelican/tic-tac-toe-c architecture

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

- Interactive diagram: https://gitdiagram.com/coding-pelican/tic-tac-toe-c
- Repository: https://github.com/coding-pelican/tic-tac-toe-c

## Overview

##### Main Components

A. User Interface Layer:
- Command-line Interface (CLI)
- Input Handler
- Manager

B. Game Logic Layer:
- Game State Manager
- Board Manager
- Turn Controller
- Win Condition Checker

C. AI System:
- Minimax Algorithm Implementation
- Move Evaluator
- Decision Engine

##### Component Relationships

**[User Interface Layer]**
- ↕
**[Game Logic Layer]**
- ↕
- [AI System]

##### Specific Implementation Details

- Rectangles: Core modules
- Rounded rectangles: Interface components
- Hexagons: Algorithm implementations

- Blue: User interface components
- Green: Game logic components
- Orange: AI components
- Gray: External systems/inputs

##### Detailed Component Breakdown

User Interface Layer:
**┌─────────────────────┐**
- CLI Interface       │←→ User Input/Output
- ┤
- Menu System      │
- Board Display    │
- Input Validation │
- ┘

Game Logic Layer:
**┌─────────────────────┐**
- Game Controller     │
- ┤
- Game State       │
- Board State      │
- Player Manager   │
- Move Validator   │
- ┘

AI System:
**┌─────────────────────┐**
- AI Engine           │
- ┤
- Minimax Algorithm│
- Move Evaluation  │
- State Analysis   │
- ┘

- User Input → Input Validation → Game State Update → Board Update → AI Move (if applicable) → Display Update

##### Technical Details

- File organization (tic_tac_toe.c as the main entry point)
- Configuration files (.clang-format, .clang-tidy)
- Build system integration

##### Notes for Implementation

- The simplicity of the single-file architecture (tic_tac_toe.c)
- The separation between game logic and AI
- The modularity of the design allowing for future improvements
- The interaction points between different components

Remember to include version information and any relevant notes about future improvements as mentioned in the README, such as AI difficulty selection and board size options, as potential extension points in the architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#a8d1f0,stroke:#2c3e50
    classDef logic fill:#a8e6cf,stroke:#2c3e50
    classDef ai fill:#ffd3b6,stroke:#2c3e50
    classDef config fill:#ddd,stroke:#2c3e50
    classDef file fill:#fff,stroke:#2c3e50

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        CLI["Command-line Interface"]:::ui
        InputHandler["Input Handler"]:::ui
        DisplayManager["Display Manager"]:::ui
    end

    %% Game Logic Layer
    subgraph Logic["Game Logic Layer"]
        GameState["Game State Manager"]:::logic
        BoardManager["Board Manager"]:::logic
        TurnController["Turn Controller"]:::logic
        WinChecker["Win Condition Checker"]:::logic
    end

    %% AI System Layer
    subgraph AI["AI System"]
        Minimax["Minimax Algorithm"]:::ai
        MoveEval["Move Evaluator"]:::ai
        DecisionEngine["Decision Engine"]:::ai
    end

    %% Configuration Components
    Config["Configuration Files"]:::config
    NewVersion["New Version Entry Point"]:::file
    MainGame["Main Game Implementation"]:::file

    %% Relationships
    CLI --> InputHandler
    InputHandler --> GameState
    DisplayManager --> CLI
    GameState --> DisplayManager
    GameState --> BoardManager
    BoardManager --> TurnController
    TurnController --> WinChecker
    TurnController --> DecisionEngine
    DecisionEngine --> Minimax
    Minimax --> MoveEval
    MoveEval --> GameState

    %% Click Events
    click MainGame "https://github.com/coding-pelican/tic-tac-toe-c/blob/main/src/tic_tac_toe.c"
    click NewVersion "https://github.com/coding-pelican/tic-tac-toe-c/blob/main/src/new_version/main.c"
    click Config "https://github.com/coding-pelican/tic-tac-toe-c/blob/main/.clang-format"

    %% Legend
    subgraph Legend
        UI_Legend["UI Component"]:::ui
        Logic_Legend["Logic Component"]:::logic
        AI_Legend["AI Component"]:::ai
        Config_Legend["Configuration"]:::config
    end
```
