# kh-returngame/rg2_tetro-mok architecture

> Architecture diagram of the GitHub repository kh-returngame/rg2_tetro-mok, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kh-returngame/rg2_tetro-mok
- Repository: https://github.com/kh-returngame/rg2_tetro-mok

## Overview

##### Project type and purpose
- This is a Unity‐based 2D board game (“트리미노목”) that fuses Tetris pieces with Omok rules.
- Written in C# for Unity 6, it supports single‐player (AI vs. human) and multiplayer (human vs. human) modes.
- The AI uses an ONNX model (Assets/CNNModel/model_output.onnx).

##### File structure
- Top‐level Unity folders:
- Assets – all game assets (models, fonts, graphics, sounds, scripts, prefabs, scenes)
- Packages – Unity package manifests
- ProjectSettings – engine & pipeline configs
- Key subfolders under Assets:
- CNNModel – ONNX model and metadata for AI
- Scripts/Global – scene & board initialization, input/resolution, sound, scene transitions
- Scripts/SinglePlay and Scripts/MultiPlay – each implements GameManager + State subfolder using the State Pattern (IState interface, GameStartState, Black/White/EndGame states)
- Prefabs & Scenes – visual/game‐object definitions and Unity scenes (Title, HowToPlay, SingleGame, MultiGame)
- Misc – Input System actions, render pipeline settings, scene templates
- TextMesh Pro – typography resources
- Sounds – BGM and effects

##### README insights
- Detailed game rules, turn management via State Pattern, board represented as a 19×19 int array.
- Connection‐checking flow: scan grid in four directions, collect groups, animate removals, apply scoring.
- SinglePlay AI “under development” section implies CNN inference in Simulation.cs/CNN.cs.

a. Main components
- Unity Engine Host (Universal Render Pipeline, Input System)
- UI Layer & Scene Flow (TitleScene, HowToPlayScene, SingleGameScene, MultiGameScene)
- Game Logic Layer
– Global Controllers (SceneHandler, InitBoard, SoundManager, CameraResolution)
– State Machine Module (IState + concrete states under SinglePlay/MultiPlay)
– Board Data Model (19×19 grid)
– Connection Checker & Scoring Module
- AI Inference Service (ONNX Runtime invoked by CNN.cs in SinglePlay)
- Asset Layer (Prefabs, TextMesh Pro, Sounds, Graphics)
b. Relationships & interactions
- Input System → SceneHandler → loads Scene
- Scene’s GameManager → initializes board via InitBoard
- GameManager ↔ State Machine (push/pop states, delegate update & handle input)
- In SinglePlay: GameManager/Simulation → CNN inference service → AI move decision → GameManager applies move to board
- After each move: Connection Checker reads Board Data → identifies groups → notifies Animation Controller → triggers Prefab/Graphic updates and SoundManager
- Final scoring & end‐game popup/UI
c. Architectural patterns & design principles
- State Pattern for turn management
- Separation of Concerns:
– Global scripts vs. mode‐specific scripts
– Rendering & assets decoupled from game logic
- Data‐driven AI via ONNX model
- Unity’s component‐based architecture (MonoBehaviours on GameObjects defined in Prefabs)
d. Key technologies/frameworks
- Unity 6 (Universal Render Pipeline)
- C# MonoBehaviour scripts
- Unity Input System
- TextMesh Pro for text rendering
- ONNX Runtime embedded in Unity (for CNN inference)

##### Essential details
- Every major script/module and asset type that participates at runtime.
- Make dependencies explicit (e.g., Simulation.cs depends on CNNModel).
- Don’t over‐fragment—group similar states or assets under cohesive containers.
- Board data structure and connection‐checking algorithm are represented as a distinct “logic” component with incoming moves and outgoing events to the animation/sound layer.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Unity Engine Host
    subgraph "Unity Engine Host" 
        direction TB
        InputSystem["Input System"]:::engine
        URP1["Renderer2D.asset"]:::engine
        URP2["UniversalRP.asset"]:::engine
    end
    click InputSystem "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Misc/InputSystem_Actions.inputactions"
    click URP1 "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Misc/Settings/Renderer2D.asset"
    click URP2 "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Misc/Settings/UniversalRP.asset"

    %% UI Layer & Scenes
    subgraph "UI Layer & Scenes"
        direction TB
        Title["TitleScene"]:::ui
        HowTo["HowToPlayScene"]:::ui
        SingleScene["SingleGameScene"]:::ui
        MultiScene["MultiGameScene"]:::ui
    end
    click Title "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scenes/TitleScene.unity"
    click HowTo "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scenes/HowToPlayScene.unity"
    click SingleScene "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scenes/SingleGameScene.unity"
    click MultiScene "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scenes/MultiGameScene.unity"

    %% Global Controllers
    subgraph "Global Controllers"
        direction TB
        SceneHandler["SceneHandler"]:::logic
        InitBoard["InitBoard"]:::logic
        SoundManager["SoundManager"]:::logic
        CameraRes["CameraResolution"]:::logic
        BGHandler["BGHandler"]:::logic
        TitleMgr["TitleManager"]:::logic
        StoneType["StoneType"]:::logic
    end
    click SceneHandler "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/SceneHandler.cs"
    click InitBoard "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/InitBoard.cs"
    click SoundManager "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/SoundManager.cs"
    click CameraRes "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/CameraResolution.cs"
    click BGHandler "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/BGHandler.cs"
    click TitleMgr "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/TitleManager.cs"
    click StoneType "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/Global/StoneType.cs"

    %% SinglePlay Module
    subgraph "SinglePlay Module"
        direction TB
        SPGM["GameManager"]:::logic
        Sim["Simulation"]:::logic
        subgraph "AI Inference Service"
            direction TB
            CNN["CNN Wrapper"]:::ai
            ONNX["ONNX Model"]:::ai
        end
        subgraph "State Machine"
            direction TB
            IStateSP["IState"]:::logic
            GStartSP["GameStartState"]:::logic
            InitBlackSP["InitialBlackState"]:::logic
            BlackSP["BlackState"]:::logic
            WhiteSP["WhiteState"]:::logic
            EndSP["EndGameState"]:::logic
        end
    end
    click SPGM "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/GameManager.cs"
    click Sim "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/Simulation.cs"
    click CNN "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/CNN.cs"
    click ONNX "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/CNNModel/model_output.onnx"
    click IStateSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/IState.cs"
    click GStartSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/GameStartState.cs"
    click InitBlackSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/InitialBlackState.cs"
    click BlackSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/BlackState.cs"
    click WhiteSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/WhiteState.cs"
    click EndSP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/SinglePlay/State/EndGameState.cs"

    %% MultiPlay Module
    subgraph "MultiPlay Module"
        direction TB
        MPGM["GameManager"]:::logic
        subgraph "State Machine"
            direction TB
            IStateMP["IState"]:::logic
            GStartMP["GameStartState"]:::logic
            InitBlackMP["InitialBlackState"]:::logic
            BlackMP["BlackState"]:::logic
            WhiteMP["WhiteState"]:::logic
            EndMP["EndGameState"]:::logic
        end
    end
    click MPGM "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/GameManager.cs"
    click IStateMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/IState.cs"
    click GStartMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/GameStartState.cs"
    click InitBlackMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/InitialBlackState.cs"
    click BlackMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/BlackState.cs"
    click WhiteMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/WhiteState.cs"
    click EndMP "https://github.com/kh-returngame/rg2_tetro-mok/blob/main/Assets/Scripts/MultiPlay/State/EndGameState.cs"

    %% Connection Checker & Scoring
    ConnectionChecker["Connection Checker & Scoring"]:::logic
    AnimationCtrl["Animation Controller"]:::logic

    %% Asset Layer
    subgraph "Asset Layer"
        direction TB
        Prefabs["Prefabs"]:::asset
        Sounds["Sounds"]:::asset
        Graphics["Graphics"]:::asset
        Fonts["Fonts & TextMesh Pro"]:::asset
    end
    click Prefabs "https://github.com/kh-returngame/rg2_tetro-mok/tree/main/Assets/Prefabs/"
    click Sounds "https://github.com/kh-returngame/rg2_tetro-mok/tree/main/Assets/Sounds/"
    click Graphics "https://github.com/kh-returngame/rg2_tetro-mok/tree/main/Assets/Graphics/"
    click Fonts "https://github.com/kh-returngame/rg2_tetro-mok/tree/main/Assets/Fonts/"

    %% Flow
    InputSystem -->|"PlayerInput"| SceneHandler
    SceneHandler -->|"loads Scene"| Title
    SceneHandler --> HowTo
    SceneHandler --> SingleScene
    SceneHandler --> MultiScene

    SingleScene --> SPGM
    MultiScene --> MPGM

    SPGM -->|"Init Board"| InitBoard
    SPGM -->|"manage states"| IStateSP
    IStateSP --> GStartSP --> InitBlackSP --> BlackSP --> WhiteSP --> EndSP

    MPGM -->|"Init Board"| InitBoard
    MPGM -->|"manage states"| IStateMP
    IStateMP --> GStartMP --> InitBlackMP --> BlackMP --> WhiteMP --> EndMP

    SPGM --> Sim
    Sim --> CNN
    CNN --> ONNX
    ONNX --> Simulation

    SPGM --> ConnectionChecker
    ConnectionChecker --> AnimationCtrl
    AnimationCtrl --> Prefabs
    AnimationCtrl --> Sounds
    ConnectionChecker --> SoundManager

    %% Styles
    classDef engine fill:#cce5ff,stroke:#66b2ff;
    classDef ui fill:#fff3b0,stroke:#ffe066;
    classDef logic fill:#d4edda,stroke:#28a745;
    classDef ai fill:#ffe5b4,stroke:#ff9800;
    classDef asset fill:#fff3b0,stroke:#ffca28;
```
