|
| 1 | +# Day 22: Wizard Simulator 20XX |
| 2 | +Little Henry Case decides that defeating bosses with [swords and stuff](https://adventofcode.com/2015/day/21) is |
| 3 | +boring. Now he's playing the game with a wizard. Of course, he gets stuck on another boss and needs your help again. |
| 4 | + |
| 5 | +In this version, combat still proceeds with the player and the boss taking alternating turns. The player still goes |
| 6 | +first. Now, however, you don't get any equipment; instead, you must choose one of your spells to cast. The first |
| 7 | +character at or below `0` hit points loses. |
| 8 | + |
| 9 | +Since you're a wizard, you don't get to wear armor, and you can't attack normally. However, since you do **magic |
| 10 | +damage**, your opponent's armor is ignored, and so the boss effectively has zero armor as well. As before, if armor |
| 11 | +(from a spell, in this case) would reduce damage below `1`, it becomes `1` instead - that is, the boss' attacks always |
| 12 | +deal at least `1` damage. |
| 13 | + |
| 14 | +On each of your turns, you must select one of your spells to cast. If you cannot afford to cast any spell, you lose. |
| 15 | +Spells cost **mana**; you start with **500** mana, but have no maximum limit. You must have enough mana to cast a spell, |
| 16 | +and its cost is immediately deducted when you cast it. Your spells are Magic Missile, Drain, Shield, Poison, and |
| 17 | +Recharge. |
| 18 | +* **Magic Missile** costs `53` mana. It instantly does `4` damage. |
| 19 | +* **Drain** costs `73` mana. It instantly does `2` damage and heals you for `2` hit points. |
| 20 | +* **Shield** costs `113` mana. It starts an **effect** that lasts for `6` turns. While it is active, your armor is |
| 21 | +increased by `7`. |
| 22 | +* **Poison** costs `173` mana. It starts an **effect** that lasts for `6` turns. At the start of each turn while it is |
| 23 | +active, it deals the boss `3` damage. |
| 24 | +* **Recharge** costs `229` mana. It starts an **effect** that lasts for `5` turns. At the start of each turn while it |
| 25 | +is active, it gives you `101` new mana. |
| 26 | + |
| 27 | +**Effects** all work the same way. Effects apply at the start of both the player's turns and the boss' turns. Effects |
| 28 | +are created with a timer (the number of turns they last); at the start of each turn, after they apply any effect they |
| 29 | +have, their timer is decreased by one. If this decreases the timer to zero, the effect ends. You cannot cast a spell |
| 30 | +that would start an effect which is already active. However, effects can be started on the same turn they end. |
| 31 | + |
| 32 | +For example, suppose the player has `10` hit points and `250` mana, and that the boss has `13` hit points and |
| 33 | +`8` damage: |
| 34 | +``` |
| 35 | +-- Player turn -- |
| 36 | +- Player has 10 hit points, 0 armor, 250 mana |
| 37 | +- Boss has 13 hit points |
| 38 | + Player casts Poison. |
| 39 | +
|
| 40 | +-- Boss turn -- |
| 41 | +- Player has 10 hit points, 0 armor, 77 mana |
| 42 | +- Boss has 13 hit points |
| 43 | + Poison deals 3 damage; its timer is now 5. |
| 44 | + Boss attacks for 8 damage. |
| 45 | +
|
| 46 | +-- Player turn -- |
| 47 | +- Player has 2 hit points, 0 armor, 77 mana |
| 48 | +- Boss has 10 hit points |
| 49 | + Poison deals 3 damage; its timer is now 4. |
| 50 | + Player casts Magic Missile, dealing 4 damage. |
| 51 | +
|
| 52 | +-- Boss turn -- |
| 53 | +- Player has 2 hit points, 0 armor, 24 mana |
| 54 | +- Boss has 3 hit points |
| 55 | + Poison deals 3 damage. This kills the boss, and the player wins. |
| 56 | +``` |
| 57 | +Now, suppose the same initial conditions, except that the boss has `14` hit points instead: |
| 58 | +``` |
| 59 | +-- Player turn -- |
| 60 | +- Player has 10 hit points, 0 armor, 250 mana |
| 61 | +- Boss has 14 hit points |
| 62 | + Player casts Recharge. |
| 63 | +
|
| 64 | +-- Boss turn -- |
| 65 | +- Player has 10 hit points, 0 armor, 21 mana |
| 66 | +- Boss has 14 hit points |
| 67 | + Recharge provides 101 mana; its timer is now 4. |
| 68 | + Boss attacks for 8 damage! |
| 69 | +
|
| 70 | +-- Player turn -- |
| 71 | +- Player has 2 hit points, 0 armor, 122 mana |
| 72 | +- Boss has 14 hit points |
| 73 | + Recharge provides 101 mana; its timer is now 3. |
| 74 | + Player casts Shield, increasing armor by 7. |
| 75 | +
|
| 76 | +-- Boss turn -- |
| 77 | +- Player has 2 hit points, 7 armor, 110 mana |
| 78 | +- Boss has 14 hit points |
| 79 | + Shield's timer is now 5. |
| 80 | + Recharge provides 101 mana; its timer is now 2. |
| 81 | + Boss attacks for 8 - 7 = 1 damage! |
| 82 | +
|
| 83 | +-- Player turn -- |
| 84 | +- Player has 1 hit point, 7 armor, 211 mana |
| 85 | +- Boss has 14 hit points |
| 86 | + Shield's timer is now 4. |
| 87 | + Recharge provides 101 mana; its timer is now 1. |
| 88 | + Player casts Drain, dealing 2 damage, and healing 2 hit points. |
| 89 | +
|
| 90 | +-- Boss turn -- |
| 91 | +- Player has 3 hit points, 7 armor, 239 mana |
| 92 | +- Boss has 12 hit points |
| 93 | + Shield's timer is now 3. |
| 94 | + Recharge provides 101 mana; its timer is now 0. |
| 95 | + Recharge wears off. |
| 96 | + Boss attacks for 8 - 7 = 1 damage! |
| 97 | +
|
| 98 | +-- Player turn -- |
| 99 | +- Player has 2 hit points, 7 armor, 340 mana |
| 100 | +- Boss has 12 hit points |
| 101 | + Shield's timer is now 2. |
| 102 | + Player casts Poison. |
| 103 | +
|
| 104 | +-- Boss turn -- |
| 105 | +- Player has 2 hit points, 7 armor, 167 mana |
| 106 | +- Boss has 12 hit points |
| 107 | + Shield's timer is now 1. |
| 108 | + Poison deals 3 damage; its timer is now 5. |
| 109 | + Boss attacks for 8 - 7 = 1 damage! |
| 110 | +
|
| 111 | +-- Player turn -- |
| 112 | +- Player has 1 hit point, 7 armor, 167 mana |
| 113 | +- Boss has 9 hit points |
| 114 | + Shield's timer is now 0. |
| 115 | + Shield wears off, decreasing armor by 7. |
| 116 | + Poison deals 3 damage; its timer is now 4. |
| 117 | + Player casts Magic Missile, dealing 4 damage. |
| 118 | +
|
| 119 | +-- Boss turn -- |
| 120 | +- Player has 1 hit point, 0 armor, 114 mana |
| 121 | +- Boss has 2 hit points |
| 122 | + Poison deals 3 damage. This kills the boss, and the player wins. |
| 123 | +``` |
| 124 | +You start with **50 hit points** and **500 mana points**. The boss's actual stats are in your puzzle input. What is the |
| 125 | +**least amount of mana** you can spend and still win the fight? (Do not include mana recharge effects as "spending" |
| 126 | +negative mana.) |
0 commit comments