User guide All lessons Cookbook Function reference Open playground

Open this document in the playground · Download source

Test natural-face exceptions before totals

Part F · L22 · Prerequisite: L21 · One modelling idea

Situation, question, and prediction

A D&D 2014 attack with +5 targets AC 15. A natural 1 automatically misses; a natural 20 is a critical hit. How do these exceptions differ from L21’s ability check? Predict what happens against impossibly high AC.

Build

if tests a condition; == compares equality, while >= means at least. Indentation controls each branch. return exits the function immediately, so test exceptions before ordinary success. Pass the function name, without calling it, to classify; it will receive each possible natural face.

bonus = 5
ac = 15
bands = scale().step("Miss").step("Hit").step("Critical")
def attack(face):
    if face == 1:
        return "Miss"
    if face == 20:
        return "Critical"
    if face + bonus >= ac:
        return "Hit"
    return "Miss"
result = classify(d(20), bands, attack)
output("Attack categories", result)
output("Hit including critical", result.p_at_least("Hit"))

Attack categories · Outcomes

outcome%fracX/20
Miss45.09/209
Hit50.01/210
Critical5.001/201

Hit including critical · Prob

outcome%fracX/20
Hit including critical55.011/2011

Run, read, and check

At defaults: miss 9/20, ordinary hit 10/20, critical 1/20. Total chance to hit is 11/20. No extra “fumble” effect is assumed. The die passed to classify is unmodified because its natural face matters.

Change one thing

Set AC to 100: only critical remains a hit, 1/20. Set AC to 1: natural 1 still misses, so hit including critical is 19/20.

Try it yourself

Use advantage by replacing d(20) with keep_highest(2, 20, 1). Answer: hit including critical 319/400 and critical 39/400 at defaults. Checkpoint: classify a new rule with explicit equality and exception boundaries before trusting the graph.

Rules and model notes

D&D Basic Rules 2014, Combat: Attack Rolls and Rolling 1 or 20. Ordinary attack categories only; no expanded critical range, damage, or house-rule fumbles.

What you now know / where next

Test natural-face exceptions before totals is the reusable idea. Follow the generated previous/next links below, or return to the course index. For a complete self-contained application, see dnd2014-attacks.

Content ID: L22 · Review status: pilot

Prerequisites: L21