screeps-ai
an autonomous colony AI under a hard CPU budget
- ~76K lines TypeScript
- Dinic min-cut base defense
- 27 managers · 26 roles
- hard per-tick CPU budget
An autonomous Screeps AI, roughly 76,000 lines of TypeScript, that runs a colony from bootstrap economy to multi-room empire with no human at the wheel, inside the hard per-tick CPU budget the game enforces.
Its most substantial component solves base defense as a graph problem. A 2,657-line weighted minimum-cut solver (a Dinic max-flow adaptation) node-splits every tile into in/out nodes and runs max-flow from the room exits to the protected core. It then prunes the result into a compact, gap-free rampart perimeter, while a two-pass distance transform auto-places the base in the largest open area.
The colony runs as a pipeline of 27 managers and 26 enum-dispatched creep roles across 10 room-planning modules. Together they drive static and remote mining, multi-room expansion, link logistics, lab boost chains, and an inter-room terminal network with a distance-based transfer-cost model.
Because of that budget, performance is a first-class concern: a profiler-instrumented main loop, bucket-aware throttling that backs off only when the colony is CPU-negative, and a compressed, TTL-evicted path cache keep every tick inside budget. A live operator console with namespaced commands and a toggleable visualization layer makes the running colony inspectable. It's compiled with Rollup, typed against @types/screeps, and linted with typescript-eslint.