Here's the rule that governs everything we build:
If it has a number, code handles it. If it has a narrative, AI handles it.
The AI never touches dice. It never calculates HP. It never decides whether a spell slot is expended or whether an attack of opportunity triggers. That's all code — pure Python, fully deterministic given a fixed seed, tested to the point of paranoia.
Why This Matters
Go use any AI Dungeon Master product on the market right now. Play for 30 minutes. I guarantee you'll catch it making a rules mistake. It'll let you cast two leveled spells in a turn. It'll forget that your AC should include your shield. It'll invent a "surprise round" that doesn't exist in 5e.
AI language models are extraordinary at narration. They're terrible at bookkeeping. So we don't let them do bookkeeping.
Our rules engine is a standalone Python library with zero AI dependencies. You could rip out every Claude API call and the combat system would still work perfectly, printing plain text instead of narrated prose. The AI is the voice. The code is the brain.
Architecture
The engine is organized into focused modules, each responsible for one slice of the rules:
- Dice: every roll type in the system — advantage, disadvantage, ability checks, saves, damage
- Abilities: the six ability scores, modifiers, and ability checks
- Skills: proficiency, expertise, skill checks with proper modifier calculation
- Initiative: roll-offs, dexterity tiebreaking, join-mid-combat support
- Attacks: attack rolls, damage rolls, critical hits, AC comparison, melee vs. ranged
- Actions: the action economy — action, bonus action, reaction, movement, free object interaction
- Conditions: all SRD conditions with proper mechanical effects (blinded, frightened, prone, etc.)
- Death Saves: the full death save system including auto-crit rules at close range
- Movement: speed, difficult terrain, opportunity attacks on leaving reach
- Spellcasting: spell slots, concentration, components, spell save DCs, known/prepared spells
- Character Creation: race, class, ability score generation, starting equipment, hit points
- Encounter Building: CR-based encounter balancing, XP thresholds, monster selection
- State Management: serialization, state transitions, turn tracking, combat lifecycle
Every module has a clean API. Every module is independently testable. No module calls the AI.
The 18 Edge Cases Every AI DM Gets Wrong
We maintain an internal list. Every time we find a rule that AI DMs consistently botch — from our own testing, from Reddit threads, from player reports — it becomes a permanent test case. Here are all 18:
1. Bonus Action Spell Restriction
If you cast a leveled spell as a bonus action (like Healing Word), the only other spell you can cast that turn is a cantrip with a casting time of one action. AI DMs almost always let you cast Fireball + Healing Word in the same turn. Our engine won't.
2. No Surprise Round
There is no "surprise round" in D&D 5e. There is a surprised condition that affects specific creatures on the first round of combat. AI DMs love inventing a full extra round of combat that doesn't exist.
3. Advantage/Disadvantage Cancellation
If you have both advantage and disadvantage from any number of sources, they cancel out entirely — you roll straight. It doesn't matter if you have three sources of advantage and one of disadvantage. One of each = straight roll. AI DMs try to do math on this. There is no math.
4. Readied Spells Require Concentration
When you Ready a spell, you're holding the magic. That requires concentration. If you're already concentrating on something, readying a spell drops your existing concentration. This one catches even experienced human DMs.
5. Opportunity Attacks Only on Leaving Reach
You only provoke an opportunity attack when you leave a creature's reach. Moving within their reach is fine. Moving closer is fine. Moving laterally at the same distance is fine. Only leaving. AI DMs trigger these on any adjacent movement.
6. No Delay Action
You cannot delay your turn in 5e. You can Ready an action, but you can't say "I want to go later in initiative." Your turn happens when it happens. This is a holdover from 3.5e that AI DMs constantly hallucinate into existence.
7. One Free Object Interaction Per Turn
You get one free object interaction per turn — draw a sword, open a door, pick up an item. The second one costs your action. AI DMs give unlimited free object interactions.
8. AC Calculations Don't Stack
Mage Armor and a shield? Yes, because Mage Armor sets your base AC and a shield adds to it. Mage Armor and Unarmored Defense? No — you pick one base calculation. AI DMs stack everything.
9. Concentration Check Per Damage Source
Magic Missile fires three darts. Each dart is a separate damage source. That's three concentration checks, not one. This is one of the most commonly botched rules in the entire game, and the AI gets it wrong almost every time.
10. Counterspell on Counterspell Is Legal
You can Counterspell a Counterspell. It uses your reaction, and you can only do it if you haven't used your reaction already. But it's completely legal and it's a core part of high-level spellcaster duels. AI DMs sometimes refuse to allow it.
11. Blinded vs. Invisible = Straight Roll
If you're blinded and attacking an invisible creature, the disadvantage from being blinded and the advantage from the target being unseen cancel out. But AI DMs often apply double disadvantage, which isn't a thing.
12. Melee on Unconscious Within 5ft = Auto-Crit = 2 Death Save Failures
A melee attack against an unconscious creature within 5 feet automatically hits and is a critical hit. A critical hit against a creature at 0 HP counts as two death save failures. This means a single sword swing on a downed ally is devastating. AI DMs almost never apply this correctly as a complete chain.
13. Healing at 0 HP Resets Death Saves
When you receive healing while at 0 HP, all your death save successes and failures reset. You start fresh. AI DMs sometimes carry over failed death saves after healing, which can lead to a character dying from phantom failures on a later knockdown.
14. Allies Provide Half Cover
Your ally standing between you and a target provides half cover (+2 AC). Most tables ignore this rule. AI DMs don't even know it exists.
15. Two-Weapon Fighting: No Ability Mod on Off-Hand
When you make an off-hand attack with two-weapon fighting, you don't add your ability modifier to the damage (unless the modifier is negative). You need the Two-Weapon Fighting fighting style to add it. AI DMs add the full modifier every time.
16. Cantrip Scaling Uses Total Character Level
A Wizard 1/Fighter 4 casts Fire Bolt as a 5th-level character, not a 1st-level caster. Cantrips scale with total character level, not class level. This is specifically designed to keep cantrips relevant for multiclass characters, and AI DMs get it wrong with remarkable consistency.
17. Warlock Pact Magic Slots Separate from Multiclass Table
Warlock spell slots from Pact Magic don't combine with the multiclass spellcasting table. They're tracked separately. They recharge on a short rest while multiclass slots recharge on a long rest. AI DMs merge them into one pool.
18. Temp HP Don't Stack
If you have 8 temporary hit points and receive 5 more, you choose which to keep. You don't have 13 temp HP. You pick 8 or 5. AI DMs add them together.
Every single one of these is a test case in our suite. Several of them are multiple test cases covering different permutations.
Testing Strategy
We don't just have unit tests. We have layers:
Unit tests cover individual functions — does the dice roller produce values in the correct range? Does the AC calculator handle every armor type? Coverage sits above 95%.
Integration tests run full combat scenarios from initiative through death or victory. A party of four against a group of goblins, resolved turn by turn, asserting correct state at every step.
Property-based tests using Hypothesis verify invariants that should hold across random inputs. "No matter what ability scores you generate with 4d6-drop-lowest, every score should be between 3 and 18." "No matter what sequence of attacks and heals, HP should never exceed max HP."
Regression tests are the crown jewel. Every bug we've ever fixed has a test. Every Reddit thread where someone complains about an AI DM getting a rule wrong becomes a test. The suite only grows. It never shrinks.
By the Numbers
- 500+ tests and growing
- 26 SRD monsters fully statted and validated
- Full SRD 5.1 content — races, classes, spells, equipment, monsters
- Zero AI dependencies — the engine runs with or without an LLM
- Deterministic given a fixed random seed — every combat is reproducible
The rules engine is the foundation everything else sits on. The AI narration, the shared world, the economy — all of it depends on having a mechanical layer that is correct. Not "usually correct." Not "close enough." Correct.
That's not negotiable.