Model-Based Testing for Dungeons & Dragons
What was built
It has been reported that a developer expanded a Quint model of a single D&D creature into a full combat spec, moving from a lone “character sheet” model to a system that simulates interrupt-driven battles. The original single-creature spec ran to about 6,000 lines; the new battle logic, the author says, is less than half the size of the creature code — but not less than half the complexity. The blog post, discussed on Hacker News and hosted at loskutoff.com, walks through modeling all 12 classes, 14 conditions, Legendary Resistance, opportunity attacks, and both player characters and monsters with stat blocks and character lists.
Why interrupts matter
The key insight: combat isn’t a sequence of independent events. When one creature acts, the rules open multiple interrupt windows where reactions, counters, and legendary traits can flip outcomes mid-resolution. Think Counterspell chains, Shield turning a hit into a miss, Uncanny Dodge halving damage after a hit, and Legendary Resistance rescuing a failed save. The spec even models Counterspell as a literal stack — var bSpellStack: List[SpellStackEntry] — pushing spells as they’re cast and popping them as they resolve. The result is a deeply nested state space where every interaction can spawn more interactions. Sounds fun? It’s also where most projects fall over.
Demo and implications
A demo reportedly replays an arcane battle step-by-step — Fireball, Counterspell chains, AoE damage, death saves — letting you step forward, step back, or hit play and watch interrupt windows open and resolve. The author argues that tackling the hard cases first prevents building three more layers on a fragile foundation; a spec that only covers simple cases is “a Todo App project,” useful for demos but meaningless for real play. Allegedly, the framework is ready to accept new spells and feats from SRD1 and published books, making it a practical platform for further formal testing and for anyone who’s ever thought, “Is this what my DM sees under the hood?”
Sources: loskutoff.com, Hacker News
Comments