{
  "schemaVersion": 1,
  "slug": "dnd-character-calculator",
  "category": "gaming",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "f44276f4b1e7ce3b11568451224dac015638369bc968b91137a5208172a9f8f0",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/dnd-character-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "HP = d + C + (L − 1)(int(d ÷ 2) + 1 + C); P = int((L − 1) ÷ 4) + 2; AC = 10 + X + A + S",
    "vars": [
      [
        "L",
        "character level, 1–20"
      ],
      [
        "d",
        "hit die"
      ],
      [
        "C",
        "constitution modifier"
      ],
      [
        "X",
        "dexterity modifier"
      ],
      [
        "A",
        "armor bonus"
      ],
      [
        "S",
        "shield bonus, 2 or 0"
      ],
      [
        "HP",
        "hit points"
      ],
      [
        "P",
        "proficiency bonus"
      ],
      [
        "AC",
        "armour class"
      ]
    ],
    "note": "HP uses average hit-die rolls; spell save DC = 8 + proficiency bonus + entered spell ability modifier; passive Perception = 10 + entered Wisdom modifier. Other features are not modeled."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const lv=Math.max(1,Math.min(20,Math.round(level)));const avg=Math.floor(hitDie/2)+1;const hp=hitDie+constitutionMod+(lv-1)*(avg+constitutionMod);const prof=Math.floor((lv-1)/4)+2;const ac=10+dexterityMod+armorBonus+(shield==='yes'?2:0);return {hitPoints:Math.max(1,hp),proficiencyBonus:prof,armorClass:ac,initiative:dexterityMod,spellSaveDC:8+prof+spellAbilityMod,passivePerception:10+wisdomMod,hitDicePool:lv+'d'+hitDie};",
    "inputs": [
      {
        "name": "level",
        "type": "number",
        "default": 5,
        "min": 1,
        "max": 20,
        "step": 1,
        "slider": true
      },
      {
        "name": "hitDie",
        "type": "select",
        "default": 10,
        "options": [
          {
            "value": 6
          },
          {
            "value": 8
          },
          {
            "value": 10
          },
          {
            "value": 12
          }
        ]
      },
      {
        "name": "constitutionMod",
        "type": "number",
        "default": 2,
        "min": -5,
        "max": 10,
        "step": 1,
        "slider": true
      },
      {
        "name": "dexterityMod",
        "type": "number",
        "default": 3,
        "min": -5,
        "max": 10,
        "step": 1,
        "slider": true
      },
      {
        "name": "armorBonus",
        "type": "number",
        "default": 4,
        "min": 0,
        "max": 20,
        "step": 1,
        "slider": true
      },
      {
        "name": "shield",
        "type": "select",
        "default": "no",
        "options": [
          {
            "value": "no"
          },
          {
            "value": "yes"
          }
        ]
      },
      {
        "name": "spellAbilityMod",
        "type": "number",
        "default": 2,
        "min": -5,
        "max": 10,
        "step": 1
      },
      {
        "name": "wisdomMod",
        "type": "number",
        "default": 2,
        "min": -5,
        "max": 10,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "hitPoints",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "proficiencyBonus",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "armorClass",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "initiative",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "spellSaveDC",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "passivePerception",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "hitDicePool",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
