diff --git a/day22/day.go b/day22/day.go new file mode 100644 index 0000000..58c248d --- /dev/null +++ b/day22/day.go @@ -0,0 +1,88 @@ +package day22 + +import ( + "strconv" + "strings" + "tools" +) + +type Effect struct { + damage int + armor int + mana int + timer int +} + +func (e Effect) copy() Effect { + return Effect{e.damage, e.armor, e.mana, e.timer} +} + +type Spell struct { + cost int + damage int + heal int + applyEffect Effect +} + +type Entity struct { + hitpoints int + mana int + damage int + armor int + currentEffects map[string]Effect +} + +func (e Entity) copy() Entity { + return Entity{e.hitpoints, e.mana, e.damage, e.armor, e.currentEffects} +} + +var spells = map[string]Spell{ + "Magic Missile": {53, 4, 0, nil}, + "Drain": {73, 2, 2, nil}, + "Shield": {113, 0, 0, Effect{0, 7, 0, 6}}, + "Poison": {173, 0, 0, Effect{3, 0, 0, 6}}, + "Recharge": {229, 0, 0, Effect{0, 0, 101, 5}}, +} + +func applyEffects(player, boss Entity) { + for eName, eData := range player.currentEffects { + switch eName { + case "Shield": + if eData.timer == spells["Shield"].applyEffect.timer { + player.armor += eData.armor + } else if eData.timer == 1 { + player.armor -= eData.armor + } + case "Recharge": + player.mana += eData.mana + } + eData.timer-- + } + for eName, eData := range boss.currentEffects { + switch eName { + case "Poison": + boss.hitpoints -= eData.damage + } + eData.timer-- + } +} + +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)} + bossdata := puzzle.GetInputArray() + for _, line := range bossdata { + parts := strings.Split(line, ": ") + switch parts[0] { + case "Hit Points": + boss.hitpoints, _ = strconv.Atoi(parts[1]) + case "Damage": + boss.damage, _ = strconv.Atoi(parts[0]) + } + } + return 0 +} + +func Part2(puzzle tools.AoCPuzzle) interface{} { + return 0 +} diff --git a/main.go b/main.go index 08e5ae4..28cd575 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ import ( "aoc2015/day19" "aoc2015/day20" "aoc2015/day21" + "aoc2015/day22" "flag" "fmt" "os" @@ -60,6 +61,7 @@ func initDayFunctions() { 19: {1: day19.Part1, 2: day19.Part2}, 20: {1: day20.Part1, 2: day20.Part2}, 21: {1: day21.Part1, 2: day21.Part2}, + 22: {1: day22.Part1, 2: day22.Part2}, } }