# royzilber123/konanerep architecture

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

- Interactive diagram: https://gitdiagram.com/royzilber123/konanerep
- Repository: https://github.com/royzilber123/konanerep

## Overview

1. This repository is a Python project for the board game Konane, with an AI agent built around neural-network models. The codebase is split between game logic, an application/controller layer, a view layer, and separate training/analysis assets.

2. The core domain is centered on `KonaneGame.py`. This is the rules engine boundary: it is where board state, legal moves, turn progression, and win/loss logic would live. All other subsystems depend on this module as the source of truth for game state.

3. `KonaneController.py` appears to be the orchestration layer. It likely mediates between the game engine, the AI/network layer, and the view, deciding when moves are taken by a human or by the agent and advancing the match accordingly.

4. `KonaneView.py` is the presentation boundary. Its role is to render the board and user-facing state, keeping display concerns separate from the game rules and the AI logic. `main.py` is the application entry point that likely wires these parts together.

5. `KonaneNetwork.py` is the AI/model boundary. Given the saved `.keras` files in the repo, this module likely loads trained Keras models, transforms board state into model inputs, and produces move/value predictions used by the controller during play.

6. The repository contains two model families: `ANN_MODELS_MULTI` and `CNN_MODELS`. This shows the project compares multiple neural architectures for the same game-playing task. The ANN directory includes variants named by activation function (`relu`, `gelu`, `elu`, `leaky_relu`, `mish`) and each has `best`, `final`, and `history` artifacts, which suggests an experiment pipeline with training checkpoints and recorded metrics.

7. `CNN_MODELS` contains at least one convolutional model checkpoint and a summary file. This implies a second model track for board-position learning, likely using the spatial structure of the Konane board more directly than the dense ANN variants.

8. `train_konane_ann.py` is the training subsystem for the ANN side. It is separated from runtime play, so training is an offline process that produces model artifacts consumed later by `KonaneNetwork.py` or the controller. The existence of history JSON files indicates training metrics are preserved for later comparison or plotting.

9. `KonanePlots.py` is the analysis/reporting layer. It likely reads the saved history and summary artifacts to generate training curves or comparisons across model variants. This is the main post-training inspection boundary rather than part of the gameplay loop.

10. The primary data flow is: game state is created by `KonaneGame`, displayed by `KonaneView`, and coordinated by `KonaneController`; for AI turns, state is passed into `KonaneNetwork`, which loads one of the saved Keras models from `ANN_MODELS_MULTI` or `CNN_MODELS` and returns a move decision. Training flows in the opposite direction: `train_konane_ann.py` produces model checkpoints and history files that are later analyzed by `KonanePlots.py` and reused by the runtime agent.

11. In architectural terms, the important boundaries are: rules engine vs. orchestration vs. presentation, and runtime play vs. offline model training. The saved model directories are not source code; they are deployable assets that make the agent behavior reproducible across runs.

12. The README is minimal and points to an external document, so the repository structure itself is the best source of architecture. From the file tree, this is best understood as a Konane game application with a reinforcement-learning or model-based opponent, plus an experiment pipeline for comparing neural network architectures.

Main entry points: [`ANN_MODELS_MULTI`](https://github.com/royzilber123/konanerep/tree/main/ANN_MODELS_MULTI) (ANN models), [`KonaneController.py`](https://github.com/royzilber123/konanerep/blob/main/KonaneController.py) (Controller), [`main.py`](https://github.com/royzilber123/konanerep/blob/main/main.py) (Main), [`KonaneNetwork.py`](https://github.com/royzilber123/konanerep/blob/main/KonaneNetwork.py) (Network)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime app"]
  node_main["Main<br/>entrypoint<br/>[main.py]"]
  node_controller["Controller<br/>orchestrator"]
  node_game["Konane Game<br/>rules engine<br/>[KonaneGame.py]"]
  node_view["View<br/>presentation<br/>[KonaneView.py]"]
  node_network["Network<br/>ai model boundary<br/>[KonaneNetwork.py]"]
end

subgraph group_training["Model training"]
  node_train_ann["Train ANN<br/>training script"]
  node_ann_models[("ANN models<br/>model artifacts")]
  node_ann_relu["ReLU set<br/>ann variant"]
  node_ann_gelu["GELU set<br/>ann variant"]
  node_ann_elu["ELU set<br/>ann variant<br/>[ann_elu_best.keras]"]
  node_ann_leaky["Leaky ReLU set<br/>ann variant"]
  node_ann_mish["Mish set<br/>ann variant"]
end

subgraph group_analysis["Analysis assets"]
  node_cnn_models[("CNN models<br/>model artifacts")]
  node_cnn_model1["CNN ckpt<br/>cnn checkpoint"]
  node_plots["Plots<br/>analysis<br/>[KonanePlots.py]"]
  node_ann_summary["ANN summary<br/>summary asset<br/>[summary.json]"]
end

node_main -->|"starts"| node_controller
node_main -->|"renders"| node_view
node_main -->|"loads AI"| node_network
node_controller -->|"reads state"| node_game
node_controller -->|"updates UI"| node_view
node_controller -->|"asks move"| node_network
node_network -->|"encodes state"| node_game
node_train_ann -->|"writes"| node_ann_models
node_ann_models -->|"includes"| node_ann_relu
node_ann_models -->|"includes"| node_ann_gelu
node_ann_models -->|"includes"| node_ann_elu
node_ann_models -->|"includes"| node_ann_leaky
node_ann_models -->|"includes"| node_ann_mish
node_plots -->|"analyzes"| node_ann_models
node_plots -->|"analyzes"| node_cnn_models
node_cnn_models -->|"includes"| node_cnn_model1
node_ann_models -->|"summarizes"| node_ann_summary

click node_main "https://github.com/royzilber123/konanerep/blob/main/main.py"
click node_controller "https://github.com/royzilber123/konanerep/blob/main/KonaneController.py"
click node_game "https://github.com/royzilber123/konanerep/blob/main/KonaneGame.py"
click node_view "https://github.com/royzilber123/konanerep/blob/main/KonaneView.py"
click node_network "https://github.com/royzilber123/konanerep/blob/main/KonaneNetwork.py"
click node_train_ann "https://github.com/royzilber123/konanerep/blob/main/train_konane_ann.py"
click node_ann_models "https://github.com/royzilber123/konanerep/tree/main/ANN_MODELS_MULTI"
click node_ann_relu "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_relu_best.keras"
click node_ann_gelu "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_gelu_best.keras"
click node_ann_elu "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_elu_best.keras"
click node_ann_leaky "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_leaky_relu_best.keras"
click node_ann_mish "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_mish_best.keras"
click node_cnn_models "https://github.com/royzilber123/konanerep/tree/main/CNN_MODELS"
click node_cnn_model1 "https://github.com/royzilber123/konanerep/blob/main/CNN_MODELS/model_1_k3_best.keras"
click node_plots "https://github.com/royzilber123/konanerep/blob/main/KonanePlots.py"
click node_ann_summary "https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/summary.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_controller,node_game,node_view,node_network toneBlue
class node_train_ann,node_ann_models,node_ann_relu,node_ann_gelu,node_ann_elu,node_ann_leaky,node_ann_mish toneAmber
class node_cnn_models,node_cnn_model1,node_plots,node_ann_summary toneMint
```

## Components

### Runtime app

Interactive Konane gameplay stack.

- [Main](https://github.com/royzilber123/konanerep/blob/main/main.py): entrypoint · Application entry point that wires the game, controller, network, and view. · `main.py`
- [Controller](https://github.com/royzilber123/konanerep/blob/main/KonaneController.py): orchestrator · Coordinates turns, player input, and AI decisions. · `KonaneController.py`
- [Konane Game](https://github.com/royzilber123/konanerep/blob/main/KonaneGame.py): rules engine · Core board-state and move-validation source of truth. · `KonaneGame.py`
- [View](https://github.com/royzilber123/konanerep/blob/main/KonaneView.py): presentation · Renders the board and user-facing game state. · `KonaneView.py`
- [Network](https://github.com/royzilber123/konanerep/blob/main/KonaneNetwork.py): ai model boundary · Loads trained models and produces move or value predictions. · `KonaneNetwork.py`

### Model training

Offline ANN training and saved artifacts.

- [Train ANN](https://github.com/royzilber123/konanerep/blob/main/train_konane_ann.py): training script · Offline trainer for dense neural-network Konane agents. · `train_konane_ann.py`
- [ANN models](https://github.com/royzilber123/konanerep/tree/main/ANN_MODELS_MULTI): model artifacts · Dense-model checkpoints and training histories across activation variants. · `ANN_MODELS_MULTI`
- [ReLU set](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_relu_best.keras): ann variant · ReLU model checkpoints and history artifacts. · `ANN_MODELS_MULTI/ann_relu_best.keras`
- [GELU set](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_gelu_best.keras): ann variant · GELU model checkpoints and history artifacts. · `ANN_MODELS_MULTI/ann_gelu_best.keras`
- [ELU set](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_elu_best.keras): ann variant · ELU model checkpoints and history artifacts. · `ANN_MODELS_MULTI/ann_elu_best.keras`
- [Leaky ReLU set](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_leaky_relu_best.keras): ann variant · Leaky-ReLU model checkpoints and history artifacts. · `ANN_MODELS_MULTI/ann_leaky_relu_best.keras`
- [Mish set](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/ann_mish_best.keras): ann variant · Mish model checkpoints and history artifacts. · `ANN_MODELS_MULTI/ann_mish_best.keras`

### Analysis assets

Saved summaries and plotting inputs.

- [CNN models](https://github.com/royzilber123/konanerep/tree/main/CNN_MODELS): model artifacts · Convolutional model checkpoint and summary asset. · `CNN_MODELS`
- [CNN ckpt](https://github.com/royzilber123/konanerep/blob/main/CNN_MODELS/model_1_k3_best.keras): cnn checkpoint · Representative convolutional model artifact. · `CNN_MODELS/model_1_k3_best.keras`
- [Plots](https://github.com/royzilber123/konanerep/blob/main/KonanePlots.py): analysis · Reads histories and summaries to compare training runs. · `KonanePlots.py`
- [ANN summary](https://github.com/royzilber123/konanerep/blob/main/ANN_MODELS_MULTI/summary.json): summary asset · Aggregate metadata for ANN experiments. · `ANN_MODELS_MULTI/summary.json`

## Connections

- Main → Controller: starts · Bootstraps the application flow.
- Main → View: renders · Initializes or connects the presentation layer.
- Main → Network: loads AI · Creates the agent-facing model boundary.
- Controller → Konane Game: reads state · Uses the rules engine as the source of truth.
- Controller → View: updates UI · Pushes game progress to the presentation layer.
- Controller → Network: asks move · Requests AI decisions for computer turns.
- Network → Konane Game: encodes state · Transforms board state into model inputs and interprets outputs against legal state.
- Train ANN → ANN models: writes · Produces dense-model checkpoints and histories.
- ANN models → ReLU set: includes · Contains the ReLU experiment artifacts.
- ANN models → GELU set: includes · Contains the GELU experiment artifacts.
- ANN models → ELU set: includes · Contains the ELU experiment artifacts.
- ANN models → Leaky ReLU set: includes · Contains the Leaky-ReLU experiment artifacts.
- ANN models → Mish set: includes · Contains the Mish experiment artifacts.
- Plots → ANN models: analyzes · Consumes training histories and summaries for comparison.
- Plots → CNN models: analyzes · Reads CNN artifacts for reporting.
- CNN models → CNN ckpt: includes · Contains the representative CNN checkpoint.
- ANN models → ANN summary: summarizes · Aggregate metadata for ANN experiment family.
