Skip to content

Instantly share code, notes, and snippets.

View planetis-m's full-sized avatar
πŸ‘‘
I've left OS Dev. If you need it, fork it and fix it yourself.

Antonis Geralis planetis-m

πŸ‘‘
I've left OS Dev. If you need it, fork it and fix it yourself.
View GitHub Profile

Game System Design Protocol for AI Agents (Nim)

Directive

When asked to architect, implement, or review a game system in Nim, follow this protocol sequentially. Do not skip steps. Do not introduce abstractions not prescribed here unless the user explicitly requests them.


Phase 1: Classify the Subsystem

@planetis-m
planetis-m / game_arch_nim.md
Last active July 3, 2026 18:44
Architecting Games in Nim: A Pragmatic Guide

Architecting Games in Nim: A Pragmatic Guide

1. The Core Recommendation

Start simple. Stay simple. Most games never need ECS.

The game we just built β€” a survival arena with hundreds of agents, projectiles, particles, spatial queries, and camera-following β€” runs in a fraction of a millisecond using nothing more exotic than seq[Agent] and seq[Color]. The entire architecture is plain Nim: types, arrays, and procs. There is no framework, no query layer, no entity manager, no component registration, no archetype migration.

This is not a compromise. It is the optimal answer for the vast majority of games.

Results are stable across 3 runs. The pattern holds:

System ECS-Arch MI-AoS Consistency
ai_update ~2.13 ~1.71-2.93 Noisy β€” genuine tie (data fits L2)
move ~0.76 ~1.19 Stable β€” Arch wins 1.6x
combat ~0.27 ~0.45 Stable β€” Arch wins 1.6x
projectile ~1.12 ~0.74 Stable β€” AoS wins 1.5x
cull ~2.8 ~0.55 Rock solid β€” AoS wins 5x
despawn ~0.002 ~0.001 Stable β€” AoS wins 2x
## Archetype ECS vs MI-AoS Benchmark
## ==================================
## Two approaches for a mixin-based entity simulation with cross-entity refs:
##
## 1. ECS-Archetype β€” SoA columns within archetype buckets, no signature scan
## 2. MI-AoS β€” per-archetype value arrays (composition), direct field access
##
## Scenario: Tactical field simulation
## Building {pos, sprite} β€” static, can be a parent
## Unit {pos, worldPos, vel, hp, sprite,
## MI vs ECS Benchmark v3 β€” Grouped SoA + Archetype ECS
## ====================================================
## Addresses v2 feedback: fragmented single-field columns waste cache.
##
## Four approaches:
## 1. ECS-Frag β€” 8 separate SoA columns (baseline, from v2)
## 2. ECS-Grouped β€” 5 grouped columns based on system access patterns
## 3. ECS-Archetype β€” archetype buckets with DenseVec columns (from paste)
## 4. MI-AoS β€” per-archetype value arrays (baseline winner)
##
## MI vs ECS Benchmark v2 β€” Cross-Entity References
## ==================================================
## Real-world complexity: entities reference each other (targeting,
## parent hierarchy), dynamic spawn/despawn of projectiles.
##
## Three approaches:
## ECS β€” SoA columns, flat entity indices as references, signature scan
## MI-AoS β€” per-archetype value arrays, typed indices as references
## MI-Ref β€” per-archetype heap ref objects, pointers as references
##
## MI vs ECS Benchmark
## ===================
## Compares three approaches for a mixin-based entity simulation:
##
## 1. ECS-SoA β€” type-erased columns, signature queries (adapted from paste)
## 2. MI-AoS β€” composition, per-archetype value arrays, direct field access
## 3. MI-vtable β€” role interfaces with per-type vtables, virtual dispatch
##
## Scenario: Swarm simulation with 3 archetypes (mixin composition):
## Decoration: {pos, render} β€” static visual element
## Extended validation: diamond inheritance + heterogeneous polymorphism
# ============================================================
# Shared base (top of diamond)
# ============================================================
type
Positioned = ref object of RootObj
x, y: int

You are a deterministic game engine simulating the board game Diplomacy.

Your role:

  • Act as the game master, world simulator, and all non-player countries.
  • I am the player controlling one country.
  • You must strictly follow official Diplomacy rules (movement, support, convoys, supply centers, builds).
  • No randomness. All outcomes must be logically derived from orders.

Game setup:

  • Standard Diplomacy map (1901 start).

name: nim-error-handling description: Design clear Nim error-handling flows. Use when reviewing failure behavior, exception boundaries, or batch processing.

Nim Error Handling

Use this skill when deciding where code should raise, catch, translate, retry, or return structured failure data.

Rules