# gavin-heaver/knighthacks_ix_syntax_error architecture

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

- Interactive diagram: https://gitdiagram.com/gavin-heaver/knighthacks_ix_syntax_error
- Repository: https://github.com/gavin-heaver/knighthacks_ix_syntax_error

## Overview

KnightHacks_IX_Syntax_Error is a Pygame tower-defense game in which players place defenses on a grid, defend a CPU from enemies, and program turrets with restricted Python scripts. The main loop coordinates the menu, board, combat entities, game state, and rendering; enemies follow weighted flow fields while tools run scripts and fire projectiles. The tree also includes wave, shop, HUD, and AI-planning modules, but their behavior was not sampled. Edges reflect visible calls, imports listed in the source index, or documented event behavior; unsampled subsystem links are omitted.

Main entry points: [`main.py`](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/main.py) (Game Loop), [`entities/tools.py`](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/tools.py) (Defense Tools), [`entities/enemy.py`](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/enemy.py) (Enemy Behavior), [`config.py`](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/config.py) (Game Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game Runtime"]
  node_main["Game Loop<br/>[main.py]"]
  node_board["Board Grid<br/>[board.py]"]
  node_waves["Wave System<br/>[waves.py]"]
end

subgraph group_combat["Combat and AI"]
  node_enemy["Enemy Behavior<br/>[enemy.py]"]
  node_projectile["Projectiles<br/>[projectile.py]"]
  node_tools["Defense Tools<br/>[tools.py]"]
  node_flow["Flow Fields<br/>[flowField.py]"]
  node_steering["Enemy Steering<br/>[steering.py]"]
  node_costlayers["AI Cost Layers<br/>[costLayers.py]"]
  node_director["AI Director<br/>[director.py]"]
  node_pheromone["Pheromone AI<br/>[pheromone.py]"]
end

subgraph group_scripting["Tower Scripting"]
  node_runner["Script Runner<br/>[runner.py]"]
  node_api["Script API<br/>[api.py]"]
  node_defaults["Default Scripts<br/>[defaults.py]"]
  node_corruption["Script Corruption<br/>[corruption.py]"]
end

subgraph group_interface["Player Interface"]
  node_menu["Menu and Scores<br/>[menu.py]"]
  node_scoreboard[("Local Scoreboard<br/>[scoreboard.json]")]
  node_editor["Code Editor<br/>[editor.py]"]
  node_overlay["Debug Overlay<br/>[debugOverlay.py]"]
  node_hud["Game HUD<br/>[hud.py]"]
  node_shop["Defense Shop<br/>[shop.py]"]
end

subgraph group_state["Game State"]
  node_events["Event Bus<br/>[events.py]"]
  node_gamestate["Game State<br/>[gameState.py]"]
  node_config["Game Configuration<br/>[config.py]"]
end

node_player(("Player"))

node_player -->|"plays"| node_main
node_main -->|"creates and queries"| node_board
node_main -->|"handles and draws"| node_menu
node_main -->|"handles editor"| node_editor
node_main -->|"uses game state"| node_gamestate
node_main -->|"creates enemies"| node_enemy
node_main -->|"updates tools"| node_tools
node_main -->|"builds field"| node_flow
node_main -->|"draws arrows"| node_overlay
node_main -->|"imports event bus"| node_events
node_main -->|"reads settings"| node_config
node_menu -->|"reads and writes"| node_scoreboard
node_enemy -->|"gets next step"| node_flow
node_enemy -->|"uses separation"| node_steering
node_enemy -->|"emits combat events"| node_events
node_gamestate -->|"subscribes to events"| node_events
node_tools -->|"runs turret scripts"| node_runner
node_tools -->|"loads default script"| node_defaults
node_tools -->|"creates projectiles"| node_projectile
node_runner -->|"imports sandbox API"| node_api
node_editor -.->|"compiles tool script"| node_runner
node_board -->|"uses grid settings"| node_config
node_gamestate -->|"uses game rules"| node_config
node_tools -->|"loads tool stats"| node_config
node_overlay -->|"reads next steps"| node_flow

click node_main "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/main.py"
click node_board "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/board.py"
click node_waves "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/waves.py"
click node_events "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/events.py"
click node_gamestate "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/gameState.py"
click node_config "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/config.py"
click node_enemy "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/enemy.py"
click node_projectile "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/projectile.py"
click node_tools "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/tools.py"
click node_flow "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/flowField.py"
click node_steering "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/steering.py"
click node_costlayers "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/costLayers.py"
click node_director "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/director.py"
click node_pheromone "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/pheromone.py"
click node_runner "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/runner.py"
click node_api "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/api.py"
click node_defaults "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/defaults.py"
click node_corruption "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/corruption.py"
click node_menu "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/menu.py"
click node_scoreboard "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scoreboard.json"
click node_editor "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/editor.py"
click node_overlay "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/debugOverlay.py"
click node_hud "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/hud.py"
click node_shop "https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/shop.py"

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_board,node_waves toneBlue
class node_enemy,node_projectile,node_tools,node_flow,node_steering,node_costlayers,node_director,node_pheromone toneAmber
class node_runner,node_api,node_defaults,node_corruption toneMint
class node_menu,node_scoreboard,node_editor,node_overlay,node_hud,node_shop toneRose
class node_events,node_gamestate,node_config,node_player toneIndigo
```

## Components

### Game Runtime

- [Game Loop](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/main.py): `main.py`
- [Board Grid](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/board.py): `game/board.py`
- [Wave System](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/waves.py): `game/waves.py`

### Combat and AI

- [Enemy Behavior](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/enemy.py): `entities/enemy.py`
- [Projectiles](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/projectile.py): `entities/projectile.py`
- [Defense Tools](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/entities/tools.py): `entities/tools.py`
- [Flow Fields](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/flowField.py): `ai/flowField.py`
- [Enemy Steering](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/steering.py): `ai/steering.py`
- [AI Cost Layers](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/costLayers.py): `ai/costLayers.py`
- [AI Director](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/director.py): `ai/director.py`
- [Pheromone AI](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ai/pheromone.py): `ai/pheromone.py`

### Tower Scripting

- [Script Runner](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/runner.py): `scripting/runner.py`
- [Script API](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/api.py): `scripting/api.py`
- [Default Scripts](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/defaults.py): `scripting/defaults.py`
- [Script Corruption](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scripting/corruption.py): `scripting/corruption.py`

### Player Interface

- [Menu and Scores](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/menu.py): `ui/menu.py`
- [Local Scoreboard](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/scoreboard.json): `scoreboard.json`
- [Code Editor](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/editor.py): `ui/editor.py`
- [Debug Overlay](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/debugOverlay.py): `ui/debugOverlay.py`
- [Game HUD](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/hud.py): `ui/hud.py`
- [Defense Shop](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/ui/shop.py): `ui/shop.py`

### Game State

- [Event Bus](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/events.py): `game/events.py`
- [Game State](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/game/gameState.py): `game/gameState.py`
- [Game Configuration](https://github.com/gavin-heaver/knighthacks_ix_syntax_error/blob/main/config.py): `config.py`

### Other components

- **Player**

## Connections

- Player → Game Loop: plays
- Game Loop → Board Grid: creates and queries (evidence: `main.py`)
- Game Loop → Menu and Scores: handles and draws (evidence: `main.py`)
- Game Loop → Code Editor: handles editor (evidence: `main.py`)
- Game Loop → Game State: uses game state (evidence: `main.py`)
- Game Loop → Enemy Behavior: creates enemies (evidence: `main.py`)
- Game Loop → Defense Tools: updates tools (evidence: `main.py`)
- Game Loop → Flow Fields: builds field (evidence: `main.py`)
- Game Loop → Debug Overlay: draws arrows (evidence: `main.py`)
- Game Loop → Event Bus: imports event bus (evidence: `main.py`)
- Game Loop → Game Configuration: reads settings (evidence: `main.py`)
- Menu and Scores → Local Scoreboard: reads and writes (evidence: `ui/menu.py`)
- Enemy Behavior → Flow Fields: gets next step (evidence: `entities/enemy.py`)
- Enemy Behavior → Enemy Steering: uses separation (evidence: `entities/enemy.py`)
- Enemy Behavior → Event Bus: emits combat events (evidence: `entities/enemy.py`)
- Game State → Event Bus: subscribes to events (evidence: `game/gameState.py`)
- Defense Tools → Script Runner: runs turret scripts (evidence: `entities/tools.py`)
- Defense Tools → Default Scripts: loads default script (evidence: `entities/tools.py`)
- Defense Tools → Projectiles: creates projectiles (evidence: `entities/tools.py`)
- Script Runner → Script API: imports sandbox API (evidence: `scripting/runner.py`)
- Code Editor → Script Runner: compiles tool script
- Board Grid → Game Configuration: uses grid settings (evidence: `game/board.py`)
- Game State → Game Configuration: uses game rules (evidence: `game/gameState.py`)
- Defense Tools → Game Configuration: loads tool stats (evidence: `entities/tools.py`)
- Debug Overlay → Flow Fields: reads next steps (evidence: `ui/debugOverlay.py`)
