adventofcode/2018/day24/army.go
2019-11-08 12:40:42 -06:00

45 lines
709 B
Go

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