clash-royale-suite

Clash Royale Autonomous Intelligence & High-Performance Systems Suite

A research-oriented framework combining high-performance systems programming and deep learning to build a real-time autonomous decision agent.

### πŸ”¬ [**Interactive Telemetry Dashboard β†’**](https://clash-telemetry-web.vercel.app) *Watch the inference pipeline process real gameplay β€” frame-synced video with per-frame latency breakdown, slot-level classification, and gatekeeper state transitions across 7 matches.* [![Dashboard Demo](https://github.com/user-attachments/assets/2e93d051-486e-4029-9ecf-2856f89cd06d)](https://clash-telemetry-web.vercel.app)

πŸš€ Key Technical Pillars

See the Comparative Study for a survey of existing Clash Royale AI projects and related deterministic simulation systems, including positioning relative to OpenAI Five, AlphaStar, and Mortal

Real-Time Inference Pipeline β†’

β–Ά See it run β€” Interactive Telemetry Dashboard β€” 7 real gameplay recordings processed through both pipeline modes. Frame-synced video playback with real-time latency graphs, per-slot inference decisions, and cumulative performance stats. All telemetry captured from actual Rust pipeline runs on M-series silicon.

Pipeline Architecture

Two Rust binaries, same model β€” different strategies for when to run inference. Batch mode classifies all 5 card slots every frame. Gatekeeper mode tracks pixel-level changes per slot and skips inference on cards that haven’t changed.

Β  Batch Mode Gatekeeper Mode
Throughput 22.3 FPS 11.6 FPS
Inferences/frame 5 (fixed) 0–5 (variable)
Inferences skipped 0 21,304 (49%)
Overlay color White (all slots inferred) Green = locked (cached), White = unlocked
Live telemetry β–Ά Dashboard β–Ά Dashboard

Batch mode β€” all overlays white, every slot inferred every frame

Batch Track 1 Batch Track 2 Batch Track 3

Gatekeeper mode β€” green borders = inference skipped, white = inference running

Gatekeeper Track 1 Gatekeeper Track 2 Gatekeeper Track 3

Why is gatekeeper slower for offline video? CoreML compiles optimized execution plans for fixed tensor shapes. Batch mode sends a consistent [5, 3, 224, 224] every frame β€” compiled once, runs on the ANE. Gatekeeper varies the batch size dynamically, forcing recompilation. The gatekeeper targets live real-time streams where skipping 49% of inference calls saves compute, not batch processing.

πŸ“„ Full writeup β†’ β€” architecture details, model training history, systems optimizations (Python β†’ Rust), and build instructions.

Deterministic Multi-Agent Simulator

Simulator Architecture A tick-deterministic, integer-only combat simulation engine in Rust, modeling 125+ heterogeneous agent types from 8 data-driven JSON definitions. Exposes a Python API via PyO3 for AI agent integration, replay recording, and RL training pipelines.

Metric Value
Agent types modeled 178 characters, 89 buildings, 81 spells, 92 projectiles
Tick rate 20 tps (50ms budget), integer-only arithmetic
Stress test 3,000 concurrent agents at 29ms/tick (single M1 Pro core)
Parallel sims 10,000 instances at 23.7ms batch latency (1.5ΞΌs/instance)
Determinism 100Γ— identical runs, bit-identical after 9,600 ticks
Test coverage 28 batches, 1,900+ assertions, ~95% pass rate

Live Knowledge Graph β€” 1,054 nodes / 1,731 edges

Knowledge Graph

Watch it rotate

Built a hierarchical domain knowledge architecture (Global physics laws β†’ System mechanics β†’ Entity behaviors) layered on an AST-derived code graph, enabling systematic verification against ground-truth game data. This reduced debugging complexity by localizing faults to the correct abstraction layer (e.g., a system-level rule violation affecting 20+ entities identified once at L1 instead of repeated per-entity debugging), significantly accelerating root-cause analysis.

Complete function, struct, and call-edge graph over 38,000 lines of Rust β€” maintained via codebase-memory-mcp.

Engine subsystems tested: attack timing (windup/backswing state machine), splash damage, charge mechanics (Prince/Dark Prince/Battle Ram), shield absorption, death spawns (Golem→Golemites, Lava Hound→Pups), building spawners (Witch, Tombstone, Furnace), champion abilities (Skeleton King graveyard, Archer Queen rapid fire, Monk deflect, Golden Knight dash, Mighty Miner lane switch), evolution abilities (Evo Knight passive shield, Evo PEKKA heal-on-kill), spell interactions (Freeze, Rage, Poison DOT, Tornado pull, Lightning top-3 targeting), projectile mechanics (homing, multi-projectile Hunter/Princess, chain lightning E-Dragon), collision separation (mass-based N-body), bridge pathing, river jumping, and full match lifecycle (regular → double elixir → overtime → sudden death).

Deep-dive writeups

Writeup Focus
Charge & Poison Modeling β†’ Distance-triggered charge activation, pulsed DOT with movement debuff
Collision & Bridge Pathfinding β†’ Mass-based N-body collision separation, cost-based bridge selection
Simultaneous Hits & Convergence β†’ Tick-deterministic trade resolution, collision convergence proof
Performance & Observability β†’ Scaling to 3,000 agents, 10K parallel sims, 12ΞΌs state capture

πŸ“‚ Repository Structure

πŸ›  Roadmap