2018 day 24 More work
This commit is contained in:
@@ -4,43 +4,50 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
ArmyTypeImmune = 1 << iota
|
||||
ArmyTypeInfection
|
||||
Debug = true
|
||||
)
|
||||
|
||||
func main() {
|
||||
inp := StdinToStringSlice()
|
||||
immune, infect := ParseInput(inp)
|
||||
for _, v := range immune {
|
||||
fmt.Println("++ ", v.immunities)
|
||||
fmt.Println("-- ", v.weaknesses)
|
||||
}
|
||||
_, _ = immune, infect
|
||||
|
||||
b := NewBattle(immune, infect)
|
||||
//for !b.IsOver() {
|
||||
if Debug {
|
||||
b.PrintStatus()
|
||||
fmt.Println("")
|
||||
}
|
||||
b.Fight()
|
||||
//}
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Println("The battle is over!")
|
||||
b.PrintStatus()
|
||||
}
|
||||
|
||||
func ParseInput(inp []string) ([]Army, []Army) {
|
||||
var immune, infection []Army
|
||||
var tp int
|
||||
func ParseInput(inp []string) ([]*Army, []*Army) {
|
||||
var immune, infection []*Army
|
||||
var tp, id int
|
||||
for _, v := range inp {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if v == "Immune System:" {
|
||||
tp = ArmyTypeImmune
|
||||
tp, id = ArmyTypeImmune, 0
|
||||
continue
|
||||
} else if v == "Infection:" {
|
||||
tp = ArmyTypeInfection
|
||||
tp, id = ArmyTypeInfection, 0
|
||||
continue
|
||||
}
|
||||
id++
|
||||
switch tp {
|
||||
case ArmyTypeImmune:
|
||||
immune = append(immune, *NewArmy(v, tp))
|
||||
immune = append(immune, NewArmy(v, tp, id))
|
||||
case ArmyTypeInfection:
|
||||
infection = append(infection, *NewArmy(v, tp))
|
||||
infection = append(infection, NewArmy(v, tp, id))
|
||||
}
|
||||
}
|
||||
return immune, infection
|
||||
|
||||
Reference in New Issue
Block a user