64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
Debug = true
|
|
)
|
|
|
|
func main() {
|
|
inp := StdinToStringSlice()
|
|
immune, infect := ParseInput(inp)
|
|
|
|
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, id int
|
|
for _, v := range inp {
|
|
if v == "" {
|
|
continue
|
|
}
|
|
if v == "Immune System:" {
|
|
tp, id = ArmyTypeImmune, 0
|
|
continue
|
|
} else if v == "Infection:" {
|
|
tp, id = ArmyTypeInfection, 0
|
|
continue
|
|
}
|
|
id++
|
|
switch tp {
|
|
case ArmyTypeImmune:
|
|
immune = append(immune, NewArmy(v, tp, id))
|
|
case ArmyTypeInfection:
|
|
infection = append(infection, NewArmy(v, tp, id))
|
|
}
|
|
}
|
|
return immune, infection
|
|
}
|
|
|
|
func StdinToStringSlice() []string {
|
|
var input []string
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
for scanner.Scan() {
|
|
input = append(input, scanner.Text())
|
|
}
|
|
return input
|
|
}
|