day22 - unfinished
This commit is contained in:
parent
3d2f91644c
commit
f67d5f141c
25
day22/day.go
25
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{} {
|
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||||
player := Entity{50, 500, 0, 0, make(map[string]Effect)}
|
player := Entity{50, 500, 0, 0, make(map[string]Effect)}
|
||||||
boss := Entity{0, 0, 0, 0, make(map[string]Effect)}
|
boss := Entity{0, 0, 0, 0, make(map[string]Effect)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user