# zaxhutchinson/microworld2 architecture

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

- Interactive diagram: https://gitdiagram.com/zaxhutchinson/microworld2
- Repository: https://github.com/zaxhutchinson/microworld2

## Overview

Microworld 2 is a turn-based grid simulation in which configured agents explore a map, perceive nearby cells and hazards, choose AI commands, and earn or lose points as they act. The main loop coordinates world queries, agent decisions, action resolution, and the SFML display; the world tracks mines, treasure, and teleporters. The graph reflects the shown loop and world implementation. Other world files and unsampled modules are represented only where their role is supported by the tree or source index.

Main entry points: [`src/main.cpp`](https://github.com/zaxhutchinson/microworld2/blob/main/src/main.cpp) (Simulation loop), [`src/world.cpp`](https://github.com/zaxhutchinson/microworld2/blob/main/src/world.cpp) (World state and rules), [`src/agent.cpp`](https://github.com/zaxhutchinson/microworld2/blob/main/src/agent.cpp) (Agent state), [`src/ai.cpp`](https://github.com/zaxhutchinson/microworld2/blob/main/src/ai.cpp) (Agent AI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation runtime"]
  node_loop["Simulation loop<br/>[main.cpp]"]
end

subgraph group_world["World and rules"]
  node_world[("World state and rules<br/>[world.cpp]")]
  node_worldfiles["World maps and configs"]
  node_json["JSON parser<br/>[json.hpp]"]
end

subgraph group_agent["Agents and decisions"]
  node_agent["Agent state<br/>[agent.cpp]"]
  node_ai["Agent AI<br/>[ai.cpp]"]
  node_percepts["Percepts and symbols<br/>[percepts.hpp]"]
  node_commands["Agent commands<br/>[ai.hpp]"]
  node_comm["Agent signals<br/>[comm.hpp]"]
end

subgraph group_support["Rendering and shared types"]
  node_display["SFML display<br/>[display.cpp]"]
  node_defs["World configuration types<br/>[defs.hpp]"]
  node_vec["Grid coordinates<br/>[vec2.cpp]"]
end

node_user(("Operator"))

node_user -->|"starts"| node_loop
node_loop -->|"loads and queries"| node_world
node_world -->|"reads"| node_worldfiles
node_world -->|"parses config"| node_json
node_loop -->|"creates and updates"| node_agent
node_agent -->|"delegates decisions"| node_ai
node_loop -->|"builds percepts"| node_world
node_loop -->|"passes percepts"| node_percepts
node_agent -->|"accepts percepts"| node_percepts
node_ai -->|"returns commands"| node_commands
node_loop -->|"resolves actions"| node_world
node_loop -->|"draws simulation"| node_display
node_loop -->|"polls events"| node_display
node_world -->|"uses configuration"| node_defs
node_world -->|"tracks locations"| node_vec
node_ai -->|"accepts signals"| node_comm
node_loop -->|"passes signals"| node_comm

click node_loop "https://github.com/zaxhutchinson/microworld2/blob/main/src/main.cpp"
click node_world "https://github.com/zaxhutchinson/microworld2/blob/main/src/world.cpp"
click node_worldfiles "https://github.com/zaxhutchinson/microworld2/tree/main/worlds"
click node_json "https://github.com/zaxhutchinson/microworld2/blob/main/src/json.hpp"
click node_agent "https://github.com/zaxhutchinson/microworld2/blob/main/src/agent.cpp"
click node_ai "https://github.com/zaxhutchinson/microworld2/blob/main/src/ai.cpp"
click node_percepts "https://github.com/zaxhutchinson/microworld2/blob/main/src/percepts.hpp"
click node_commands "https://github.com/zaxhutchinson/microworld2/blob/main/src/ai.hpp"
click node_comm "https://github.com/zaxhutchinson/microworld2/blob/main/src/comm.hpp"
click node_display "https://github.com/zaxhutchinson/microworld2/blob/main/src/display.cpp"
click node_defs "https://github.com/zaxhutchinson/microworld2/blob/main/src/defs.hpp"
click node_vec "https://github.com/zaxhutchinson/microworld2/blob/main/src/vec2.cpp"

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_loop toneBlue
class node_world,node_worldfiles,node_json toneAmber
class node_agent,node_ai,node_percepts,node_commands,node_comm toneMint
class node_display,node_defs,node_vec toneRose
class node_user toneIndigo
```

## Components

### Simulation runtime

- [Simulation loop](https://github.com/zaxhutchinson/microworld2/blob/main/src/main.cpp): `src/main.cpp`

### World and rules

- [World state and rules](https://github.com/zaxhutchinson/microworld2/blob/main/src/world.cpp): `src/world.cpp`
- [World maps and configs](https://github.com/zaxhutchinson/microworld2/tree/main/worlds): `worlds`
- [JSON parser](https://github.com/zaxhutchinson/microworld2/blob/main/src/json.hpp): `src/json.hpp`

### Agents and decisions

- [Agent state](https://github.com/zaxhutchinson/microworld2/blob/main/src/agent.cpp): `src/agent.cpp`
- [Agent AI](https://github.com/zaxhutchinson/microworld2/blob/main/src/ai.cpp): `src/ai.cpp`
- [Percepts and symbols](https://github.com/zaxhutchinson/microworld2/blob/main/src/percepts.hpp): `src/percepts.hpp`
- [Agent commands](https://github.com/zaxhutchinson/microworld2/blob/main/src/ai.hpp): `src/ai.hpp`
- [Agent signals](https://github.com/zaxhutchinson/microworld2/blob/main/src/comm.hpp): `src/comm.hpp`

### Rendering and shared types

- [SFML display](https://github.com/zaxhutchinson/microworld2/blob/main/src/display.cpp): `src/display.cpp`
- [World configuration types](https://github.com/zaxhutchinson/microworld2/blob/main/src/defs.hpp): `src/defs.hpp`
- [Grid coordinates](https://github.com/zaxhutchinson/microworld2/blob/main/src/vec2.cpp): `src/vec2.cpp`

### Other components

- **Operator**

## Connections

- Operator → Simulation loop: starts (evidence: `src/main.cpp`)
- Simulation loop → World state and rules: loads and queries (evidence: `src/main.cpp`)
- World state and rules → World maps and configs: reads (evidence: `src/world.cpp`)
- World state and rules → JSON parser: parses config (evidence: `src/world.cpp`)
- Simulation loop → Agent state: creates and updates (evidence: `src/main.cpp`)
- Agent state → Agent AI: delegates decisions (evidence: `src/agent.cpp`)
- Simulation loop → World state and rules: builds percepts (evidence: `src/main.cpp`)
- Simulation loop → Percepts and symbols: passes percepts (evidence: `src/main.cpp`)
- Agent state → Percepts and symbols: accepts percepts (evidence: `src/agent.cpp`)
- Agent AI → Agent commands: returns commands (evidence: `src/ai.cpp`)
- Simulation loop → World state and rules: resolves actions (evidence: `src/main.cpp`)
- Simulation loop → SFML display: draws simulation (evidence: `src/main.cpp`)
- Simulation loop → SFML display: polls events (evidence: `src/main.cpp`)
- World state and rules → World configuration types: uses configuration (evidence: `src/world.cpp`)
- World state and rules → Grid coordinates: tracks locations
- Agent AI → Agent signals: accepts signals
- Simulation loop → Agent signals: passes signals (evidence: `src/main.cpp`)
