This commit is contained in:
Luke Meyers 2020-02-08 23:04:09 -08:00
parent 241028934b
commit abe3f3d688
1 changed files with 11 additions and 2 deletions

View File

@ -46,15 +46,24 @@ func UpdateState(s State, sOld State, cmds []Command) State {
s = doCommand(cmd, s, i) s = doCommand(cmd, s, i)
} }
var winners []int
for _, t := range s.Teams { for _, t := range s.Teams {
if r := ActiveRacer(t); r != nil { if r := ActiveRacer(t); r != nil {
if won(*r, s) { if won(*r, s) {
log.Printf("team %d won", t.id) winners = append(winners, t.id)
s.GameOver = true
} }
} }
} }
switch n := len(winners); {
case n == 1:
log.Printf("team %d won", winners[0])
s.GameOver = true
case n > 1:
log.Printf("%d-way tie between teams: %v", len(winners), winners)
s.GameOver = true
}
return s return s
} }