# c0b23158b7/yakuchaka architecture

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

- Interactive diagram: https://gitdiagram.com/c0b23158b7/yakuchaka
- Repository: https://github.com/c0b23158b7/yakuchaka

## Overview

##### Project Type and Purpose
- This is a standalone, monolithic Python 3.x command-line turn-based board‐game RPG.
- It has no web frontend or external services; everything runs in one process, orchestrated by `main.py`.

##### File-Structure Analysis
Top-level
- main.py / beta_main.py – game entry point and main loop
- README.md – documentation
Package “yakuchaka/” (game logic)
- constants.py – game and tile constants
- board.py – board‐generation functions (MakeBoard, MakeReverseBoard, MaskBoard)
- player.py – Player class (movement, dice, items, actions)
- enemy.py – Enemy class (position, AI, battle)
- game_utils.py – rendering (ShowBoard, ShowStatus), item/trap logic, teleport, win checker
- story.py – story and help text display
- pathfinding.py – A* pathfinder (planned integration)

##### Key Insights from README
- The game has two phases (surface & reverse) with different boards, traps, and enemy behaviors.
- The main loop cycles through player‐action phases, movement phases, post‐move processing, win/loss checks, phase switching, and enemy actions.
- There is a clear separation of concerns: generation (board), domain (player/enemy), utilities (rendering, traps), control (main loop).

##### Main Components
a. Controller Layer
- CLI Input/Output – reads WASD, ‘r’, ‘i’ commands; writes board & status to console.
- MainLoop (main.py) – orchestrates phase logic, initialization, and switching between surface/reverse phases.
b. Domain Layer
- Player – attributes (HP, position, items), methods (RollDice, Move, UseItem, Action).
- Enemy – attributes (HP, position, devilsdog), methods (Move, SearchBattle, Battle).
- BoardGenerator – MakeBoard, MakeReverseBoard, MaskBoard.
- StoryDisplayer – prints opening story and controls paging.
c. Utility Layer
- GameUtils – ShowBoard, ShowStatus, GetItem, Trap, WinChecker, Teleport, SummonEnemy.
- PathFinding (future) – find_path, get_next_move (currently unused in movement).
d. Data Objects
- Board (2D array of tile constants)
- Mask (2D array controls hidden items/traps)
- Constants (tile types, game‐state flags)

##### Relationships and Data Flows
- On startup: MainLoop → BoardGenerator → returns board1, board2, masks → MainLoop initializes Player & Enemy list via SummonEnemy.
- Story phase: MainLoop → StoryDisplayer → prints to console → waits for input.
- In-loop iteration:
1. Controller reads input → MainLoop calls Player.Action / Player.RollDice → updates Player state.
2. For movement: MainLoop loops Player.Move → GameUtils.ShowBoard / ShowStatus → Enemy.SearchBattle / Enemy.Battle if needed → SummonEnemy to respawn.
3. After move: MainLoop calls GameUtils.Trap → updates Player/board/mask.
4. Phase switch: MainLoop checks Player.chaka, toggles board & mask, clears enemies.
5. Enemy phase: MainLoop iterates enemies → Enemy.Move or PathFinding (future) → GameUtils.ShowBoard → Enemy.SearchBattle.
- All console outputs and inputs flow through the Controller block.

##### Architectural Patterns and Principles
- Module‐per‐concern (separation of generation, domain logic, utilities, control).
- Procedural orchestration in main loop.
- Future extensibility: PathFinding plug-in, GUI layer, save/load.
- Domain objects (Player/Enemy) encapsulate state and behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Controller Layer
    subgraph "Controller Layer"
        ML["MainLoop\n(init→PlayerPhase→MovementPhase→TrapPhase→EnemyPhase→loop)"]:::controller
        IO["CLI Input/Output"]:::controller
    end

    %% Domain Layer
    subgraph "Domain Layer"
        BG["BoardGenerator\n(MakeBoard, MakeReverseBoard, MaskBoard)"]:::domain
        PL["Player\n(RollDice, Move, UseItem, Action)"]:::domain
        EN["Enemy\n(Move, SearchBattle, Battle)"]:::domain
        SD["StoryDisplayer\n(show opening story)"]:::domain
    end

    %% Utility Layer
    subgraph "Utility Layer"
        GU["GameUtils\n(ShowBoard, ShowStatus, GetItem, Trap, WinChecker, Teleport, SummonEnemy)"]:::utils
        PF["PathFinding\n(find_path, get_next_move)"]:::utilsFuture
    end

    %% Data Objects
    subgraph "Data Objects"
        C["Constants"]:::data
        BM["Board & Mask"]:::data
    end

    %% Connections
    IO -->|"user input"| ML
    ML -->|"MakeBoard() / MaskBoard()"| BG
    BG -->|"board1/board2, mask1/mask2"| BM
    ML -->|"SummonEnemy() / init Player & Enemy"| GU
    ML -->|"show story"| SD
    ML -->|"PlayerPhase"| PL
    PL -->|"ShowBoard() / ShowStatus()"| GU
    ML -->|"TrapPhase"| GU
    ML -->|"EnemyPhase"| EN
    EN -->|"SearchBattle() / Battle()"| GU
    ML -.->|"future movement"| PF
    PF -.-> BM

    %% Click Events
    click ML "https://github.com/c0b23158b7/yakuchaka/blob/main/main.py"
    click IO "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/game_utils.py"
    click PL "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/player.py"
    click EN "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/enemy.py"
    click BG "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/board.py"
    click SD "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/story.py"
    click GU "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/game_utils.py"
    click PF "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/pathfinding.py"
    click C "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/constants.py"
    click BM "https://github.com/c0b23158b7/yakuchaka/blob/main/yakuchaka/board.py"

    %% Styles
    classDef controller fill:#D0E8FF,stroke:#0366d6,stroke-width:1px;
    classDef domain fill:#DFFFD0,stroke:#228B22,stroke-width:1px;
    classDef utils fill:#FFE8B0,stroke:#d2691e,stroke-width:1px;
    classDef utilsFuture fill:#FFE8B0,stroke:#d2691e,stroke-width:1px,stroke-dasharray: 5 5;
    classDef data fill:#E8E8E8,stroke:#808080,stroke-width:1px;
    class PF utilsFuture
```
