Model-Based Testing for Dungeons & Dragons
3 days ago
- #Dungeons & Dragons
- #Model-Based Testing
- #Formal Specification
- The article details the expansion of a formal model for Dungeons & Dragons from a single creature to combat interactions, focusing on complex mechanics like Counterspell chains, Shield spells, and Legendary Resistance.
- It explains the interrupt chain during attacks, which includes multiple phases (hit confirmation, damage application, spellcasting, saving throws) that can alter outcomes and branch the game state.
- The spec models deterministic mechanics while leaving non-deterministic aspects (like dice rolls, cover determination, opportunity attack triggers) as caller-provided inputs to accommodate different play styles.
- Model-based testing (MBT) has revealed bugs in both the spec and the implementation, such as argument swaps, invariant violations, and state sync issues, which unit tests often missed.
- The project uses a QA pipeline that scrapes community Q&A entries, translating them into assertions to test the spec against real-world rule interpretations and edge cases.
- The spec includes 62 safety invariants that are proven across all reachable states, not just tested with random inputs, ensuring properties like HP limits hold universally.
- Built on the SRD 5.2.1 (released under CC-BY-4.0), the architecture allows non-SRD content to be added without modifying the core spec, and the model can validate implementations in any language.
- The approach is applicable to other domains with formal rules and combinatorial interactions, such as financial regulations or protocol implementations.