# imadtg/domino-ai architecture

> Architecture diagram of the GitHub repository imadtg/domino-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imadtg/domino-ai
- Repository: https://github.com/imadtg/domino-ai

## Overview

- A representation of the domino pieces, game state, and players’ hands.
- A game loop and logic that control the flow of the game.
- An artificial intelligence engine using minimax (and possibly heuristic techniques aided by a heap structure) to decide on moves.

##### Main Components
- Game Controller/Entry Point: Represented by main.c, this is where the program starts and orchestrates the game.
- Game Logic:
- game.c/game.h: Handles overall game rules, state transitions, and game progress.
- domino.c/domino.h, block.c/block.h, and snake.c/snake.h: Likely manage the creation and representation of domino pieces and the playing field (the “snake” of dominoes) as well as possibly grouping “blocks” or pieces.
- hands.c/hands.h: Manages the players’ hands or sets of dominoes.
- move.c/move.h: Responsible for representing and processing player moves.
- cst.h: Likely contains central constants used across the game.
- AI Engine:
- minimax.c/minimax.h: Implements the minimax algorithm, the core of the AI decision making.
- Utility Structures:
- heap.c/heap.h: Possibly used as a support data structure for the AI, such as managing move ordering or heuristics within the minimax algorithm.
- Build & Automation:
- Makefile: Supports building the project.
- .github/workflows: Provides CI/CD setups.

##### Relationships and Interactions
- How “Game Logic” relies on board / piece representation modules (domino, block, snake) and “Hands” management.
- “AI Engine” to utility support like the “Heap” module, if it’s used to optimize move ordering or evaluation processes.

##### Architectural Patterns
- The design is modularized into distinct components for game state management, AI decision making, and utility functions.
- This separation is similar to a layered or modular design where the “Core Game Engine” is clearly isolated from the “AI/Decision Module.”
- Role of minimax as an algorithmic pattern in game tree search and decision-making.

##### Incorporate Relevant Technologies and Frameworks
- The project is written in C using procedural programming.
- The CI/CD is managed via GitHub workflows (see folder .github/workflows), so you might indicate integration points for automated builds/tests.
- The Makefile is used for build automation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Initialization Layer
    subgraph "Initialization"
        mainController["Game Controller (main.c)"]:::controller
    end

    %% Game State Management Layer
    subgraph "Game State Management"
        gameLogic["Game Logic (game.c)"]:::gameComponents
        dominoRep["Domino Pieces (domino.c)"]:::gameComponents
        snakeRep["Game Board / Snake (snake.c)"]:::gameComponents
        blockGrouping["Block Grouping (block.c)"]:::gameComponents
        handsMgmt["Players' Hands (hands.c)"]:::gameComponents
        constants["Constants (cst.h)"]:::gameComponents
    end

    %% Move Processing and AI Decision Making Layer
    subgraph "Move & AI Decision Making"
        moveProcessing["Move Processing (move.c)"]:::gameComponents
        aiMinimax["Minimax AI (minimax.c)"]:::aiComponents
        aiHeap["Heap Utility (heap.c)"]:::aiComponents
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        makefile["Makefile"]:::infraComponents
        cicd["CI/CD Workflows (.github/workflows)"]:::infraComponents
    end

    %% Connections Between Layers
    mainController -->|"initiate"| gameLogic

    gameLogic -->|"manages"| dominoRep
    gameLogic -->|"manages"| snakeRep
    gameLogic -->|"manages"| blockGrouping
    gameLogic -->|"manages"| handsMgmt
    gameLogic -->|"uses"| constants

    gameLogic -->|"generates"| moveProcessing
    moveProcessing -->|"evaluates"| aiMinimax
    aiMinimax -->|"utilizes"| aiHeap
    aiMinimax -->|"returns-move"| gameLogic

    mainController ---|"build-trigger"| makefile
    mainController ---|"CI/CD-integrated"| cicd

    %% Click Events
    click mainController "https://github.com/imadtg/domino-ai/blob/main/main.c"
    click gameLogic "https://github.com/imadtg/domino-ai/blob/main/game.c"
    click dominoRep "https://github.com/imadtg/domino-ai/blob/main/domino.c"
    click snakeRep "https://github.com/imadtg/domino-ai/blob/main/snake.c"
    click blockGrouping "https://github.com/imadtg/domino-ai/blob/main/block.c"
    click handsMgmt "https://github.com/imadtg/domino-ai/blob/main/hands.c"
    click constants "https://github.com/imadtg/domino-ai/blob/main/cst.h"
    click moveProcessing "https://github.com/imadtg/domino-ai/blob/main/move.c"
    click aiMinimax "https://github.com/imadtg/domino-ai/blob/main/minimax.c"
    click aiHeap "https://github.com/imadtg/domino-ai/blob/main/heap.c"
    click makefile "https://github.com/imadtg/domino-ai/tree/main/Makefile"
    click cicd "https://github.com/imadtg/domino-ai/tree/main/.github/workflows"

    %% Styles
    classDef controller fill:#CCE5FF,stroke:#3399FF,stroke-width:2px;
    classDef gameComponents fill:#C3FDB8,stroke:#1E5631,stroke-width:2px;
    classDef aiComponents fill:#F9D162,stroke:#B0413E,stroke-width:2px;
    classDef infraComponents fill:#AFE9FF,stroke:#009BDC,stroke-width:2px;
```
