adventofcode/2018/day24/army.go

45 lines
709 B
Go
Raw Normal View History

2019-11-08 03:30:41 +00:00
package main
2019-11-08 18:40:42 +00:00
type Army []*Group
2019-11-08 17:52:19 +00:00
const (
2019-11-08 18:40:42 +00:00
ArmyImmuneSystem = iota + 1
ArmyInfection
ArmyCount
2019-11-08 17:52:19 +00:00
)
2019-11-08 18:40:42 +00:00
var StringArmies = map[string]int{
"Immune System": ArmyImmuneSystem,
"Infection": ArmyInfection,
2019-11-08 03:30:41 +00:00
}
2019-11-08 18:40:42 +00:00
func (a Army) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
2019-11-08 03:30:41 +00:00
2019-11-08 18:40:42 +00:00
func (a Army) Len() int {
return len(a)
2019-11-08 03:30:41 +00:00
}
2019-11-08 18:40:42 +00:00
func (a Army) Less(i, j int) bool {
if a[i].EffectivePower() > a[j].EffectivePower() {
return true
2019-11-08 17:52:19 +00:00
}
2019-11-08 18:40:42 +00:00
return a[i].EffectivePower() == a[j].EffectivePower() && a[i].Initiative > a[j].Initiative
2019-11-08 17:52:19 +00:00
}
2019-11-08 18:40:42 +00:00
func (a Army) Alive() bool {
for _, g := range a {
if g.Units > 0 {
2019-11-08 17:52:19 +00:00
return true
}
}
return false
}
2019-11-08 18:40:42 +00:00
func (a Army) Boost(amount int) {
for _, g := range a {
g.AttackDamage += amount
2019-11-08 17:52:19 +00:00
}
}