diff --git a/day22/day.go b/day22/day.go index 58c248d..e06a042 100644 --- a/day22/day.go +++ b/day22/day.go @@ -67,6 +67,31 @@ func applyEffects(player, boss Entity) { } } +func fightRound(player, boss Entity, spell Spell) (outcome int) { + // outcome will be -1 on boss win, 0 on both living and 1 on player win + + applyEffects(player, boss) + if player.mana < spell.cost { + return -1 + } + // cast spell + + if boss.hitpoints <= 0 { + return 1 + } + + applyEffects(player, boss) + if boss.hitpoints <= 0 { + return 1 + } + player.hitpoints -= tools.Max(1, boss.damage-player.armor) + if player.hitpoints <= 0 { + return -1 + } + + return 0 +} + func Part1(puzzle tools.AoCPuzzle) interface{} { player := Entity{50, 500, 0, 0, make(map[string]Effect)} boss := Entity{0, 0, 0, 0, make(map[string]Effect)}