From cd9bb45ddc950d1571cfb2ccb14628b583310275 Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Wed, 6 Nov 2013 21:12:19 -0800 Subject: [PATCH] sort the all bots list --- game.go | 1 + robot.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/game.go b/game.go index 1c28829..e3b7ee6 100644 --- a/game.go +++ b/game.go @@ -160,6 +160,7 @@ func (g *game) tick(payload *Boardstate) int { func (g *game) send_update(payload *Boardstate) { // Ensure that the robots are always sent in a consistent order sort.Sort(RobotSorter{Robots: payload.OtherRobots}) + sort.Sort(AllRobotSorter{Robots: payload.AllBots}) for p := range g.players { // Copy the payload but only add the robots in scanner range diff --git a/robot.go b/robot.go index a19fda6..b468507 100644 --- a/robot.go +++ b/robot.go @@ -56,6 +56,23 @@ func (s RobotSorter) Less(i, j int) bool { return s.Robots[i].Id < s.Robots[j].Id } +// TODO - how do I not duplicate this code??? +type AllRobotSorter struct { + Robots []BotHealth +} + +func (s AllRobotSorter) Len() int { + return len(s.Robots) +} + +func (s AllRobotSorter) Swap(i, j int) { + s.Robots[i], s.Robots[j] = s.Robots[j], s.Robots[i] +} + +func (s AllRobotSorter) Less(i, j int) bool { + return s.Robots[i].RobotId < s.Robots[j].RobotId +} + type Stats struct { Hp int `json:"-"` Speed float32 `json:"-"`