# rylinnm/mcts-in-pacman-capture-the-flag-environment architecture

> Architecture diagram of the GitHub repository rylinnm/mcts-in-pacman-capture-the-flag-environment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rylinnm/mcts-in-pacman-capture-the-flag-environment
- Repository: https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment

## Overview

##### Main Components
- Game Engine/Controller: This includes files like capture.py (which launches the game), game.py, and perhaps baselineTeam.py. These files control game flow, scoring, and team management.
- /Interface Modules: Files like captureGraphicsDisplay.py, graphicsDisplay.py, textDisplay.py, and keyboardAgents.py serve for rendering the game state, receiving user input, and providing visual feedback. A “Display/Interface Layer” should be a distinct component.
- Utility Modules: Several files (distanceCalculator.py, mazeGenerator.py, layout.py, graphicsUtils.py, util.py) provide supporting functions (e.g., calculating distances, generating maps and layouts). Represent these as auxiliary modules connected to both the game engine and agents.

##### Relationships and Interactions
- The Game Engine acts as the central controller. It initiates a match, sets up the environment, and communicates with the agents.
- The MCTS Agent, implemented in pathfinder.py, interacts with the game engine by receiving game state information and returning moves based on the MCTS algorithm.
- /Interface modules subscribe to game state updates and render the visuals or text based on updates from the game engine.
- Utility functions are used by both the game engine and agents (e.g., using distance calculations for pathfinding or maze generation for layouts).

##### Architectural Patterns and Design Principles
- Separation of Concerns: The design clearly separates game logic from display logic and agent decision-making.
- Modular Design: Each file or module has a specific responsibility (e.g., one file for agent logic, one for graphics, one for utility functions), suggesting a layered architecture.

- Branch out to show the MCTS Agent (pathfinder.py) along with a note on the algorithm it implements (MCTS via UCT variant).
- Separate branches for the visual elements, connecting relevant display files.
- Optionally, include an “Extended Agents” block for additional agent implementations like keyboardAgents.py or baselineTeam.py.
- Annotations where helpful, such as command-line parameters influencing game behavior or simulation parameters for MCTS iterations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Game Engine Subgraph
    subgraph "Game Engine"
        GE1["capture.py"]:::engine
        GE2["game.py"]:::engine
        GE3["baselineTeam.py"]:::engine
    end

    %% MCTS Agent Subgraph
    subgraph "MCTS Agent"
        MCTS["Pathfinder.py"]:::agent
    end

    %% Display/Interface Subgraph
    subgraph "Display/Interface"
        DGD["captureGraphicsDisplay.py"]:::display
        GD["graphicsDisplay.py"]:::display
        TD["textDisplay.py"]:::display
        KA["keyboardAgents.py"]:::display
    end

    %% Utilities & Helpers Subgraph
    subgraph "Utilities & Helpers"
        UD["distanceCalculator.py"]:::utility
        UM["mazeGenerator.py"]:::utility
        UL["layout.py"]:::utility
        UGU["graphicsUtils.py"]:::utility
        UU["util.py"]:::utility
    end

    %% Additional Scripts / Extended Agents Subgraph
    subgraph "Additional Scripts/Extended Agents"
        ASG["generateTournamentLayouts.py"]:::additional
        ASCA["captureAgents.py"]:::additional
    end

    %% Relationships
    %% MCTS Agent and Game Engine
    GE1 -->|"GameState"| MCTS
    MCTS -->|"AgentAction"| GE1

    %% Game Engine and Display Modules
    GE1 -->|"DisplayUpdate"| DGD
    GE1 -->|"DisplayUpdate"| GD
    GE1 -->|"DisplayUpdate"| TD
    KA -->|"UserInput"| GE1

    %% Game Engine and Additional Scripts
    GE1 -->|"ExtendedAgents"| ASG
    GE1 -->|"ExtendedAgents"| ASCA

    %% Utility Modules used by Game Engine and MCTS Agent
    UD ---|"Helper"| GE1
    UD ---|"Helper"| MCTS
    UM ---|"Helper"| GE1
    UM ---|"Helper"| MCTS
    UL ---|"Helper"| GE1
    UL ---|"Helper"| MCTS
    UGU ---|"Helper"| GE1
    UGU ---|"Helper"| MCTS
    UU ---|"Helper"| GE1
    UU ---|"Helper"| MCTS

    %% Styles
    classDef engine fill:#FFDDCC,stroke:#CC5500,stroke-width:2px;
    classDef agent fill:#CCE5FF,stroke:#004080,stroke-width:2px;
    classDef display fill:#CCFFCC,stroke:#009900,stroke-width:2px;
    classDef utility fill:#FFCCFF,stroke:#990099,stroke-width:2px;
    classDef additional fill:#FFFFCC,stroke:#999900,stroke-width:2px;

    %% Click Events for Game Engine Files
    click GE1 "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/capture.py"
    click GE2 "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/game.py"
    click GE3 "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/baselineTeam.py"

    %% Click Event for MCTS Agent
    click MCTS "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/Pathfinder.py"

    %% Click Events for Display/Interface Files
    click DGD "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/captureGraphicsDisplay.py"
    click GD "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/graphicsDisplay.py"
    click TD "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/textDisplay.py"
    click KA "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/keyboardAgents.py"

    %% Click Events for Utility Modules
    click UD "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/distanceCalculator.py"
    click UM "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/mazeGenerator.py"
    click UL "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/layout.py"
    click UGU "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/graphicsUtils.py"
    click UU "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/util.py"

    %% Click Events for Additional Scripts/Extended Agents
    click ASG "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/generateTournamentLayouts.py"
    click ASCA "https://github.com/rylinnm/mcts-in-pacman-capture-the-flag-environment/blob/main/Code/captureAgents.py"
```
