sort the all bots list
This commit is contained in:
parent
855b8518b8
commit
cd9bb45ddc
1
game.go
1
game.go
@ -160,6 +160,7 @@ func (g *game) tick(payload *Boardstate) int {
|
|||||||
func (g *game) send_update(payload *Boardstate) {
|
func (g *game) send_update(payload *Boardstate) {
|
||||||
// Ensure that the robots are always sent in a consistent order
|
// Ensure that the robots are always sent in a consistent order
|
||||||
sort.Sort(RobotSorter{Robots: payload.OtherRobots})
|
sort.Sort(RobotSorter{Robots: payload.OtherRobots})
|
||||||
|
sort.Sort(AllRobotSorter{Robots: payload.AllBots})
|
||||||
|
|
||||||
for p := range g.players {
|
for p := range g.players {
|
||||||
// Copy the payload but only add the robots in scanner range
|
// Copy the payload but only add the robots in scanner range
|
||||||
|
17
robot.go
17
robot.go
@ -56,6 +56,23 @@ func (s RobotSorter) Less(i, j int) bool {
|
|||||||
return s.Robots[i].Id < s.Robots[j].Id
|
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 {
|
type Stats struct {
|
||||||
Hp int `json:"-"`
|
Hp int `json:"-"`
|
||||||
Speed float32 `json:"-"`
|
Speed float32 `json:"-"`
|
||||||
|
Loading…
Reference in New Issue
Block a user