How kh-returngame/rg2_tetro-mok works
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.