reuse some slices
This commit is contained in:
parent
bf853880ca
commit
b7087adb78
7
game.go
7
game.go
@ -44,6 +44,7 @@ func NewGame(id string, width, height float64) *game {
|
||||
func (g *game) run() {
|
||||
started := false
|
||||
var t0, t1 time.Time
|
||||
payload := bot.NewBoardstate()
|
||||
for {
|
||||
select {
|
||||
case <-g.kill:
|
||||
@ -69,6 +70,8 @@ func (g *game) run() {
|
||||
}
|
||||
|
||||
g.turn++
|
||||
payload.Turn = g.turn
|
||||
|
||||
t0 = time.Now()
|
||||
|
||||
if *verbose {
|
||||
@ -78,9 +81,6 @@ func (g *game) run() {
|
||||
log.Printf("Explosions: %v", len(g.splosions))
|
||||
}
|
||||
|
||||
// TODO: making one of these every iteration seems wasteful
|
||||
payload := bot.NewBoardstate(g.turn)
|
||||
|
||||
robots_remaining := 0
|
||||
|
||||
for p := range g.players {
|
||||
@ -140,6 +140,7 @@ func (g *game) run() {
|
||||
log.Printf("Sent Payload %v\n", t1.Sub(t0))
|
||||
}
|
||||
|
||||
payload.EmptySlices()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,7 @@ func (p *player) nudge() {
|
||||
}
|
||||
|
||||
func (p *player) scan(players map[*player]bool) {
|
||||
// TODO: perhaps keep the same one around?
|
||||
p.Robot.Scanners = make([]bot.Scanner, 0)
|
||||
p.Robot.Scanners = p.Robot.Scanners[:0]
|
||||
for player, _ := range players {
|
||||
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user