reuse some slices

This commit is contained in:
Stephen McQuay 2013-09-07 19:13:12 -07:00
parent bf853880ca
commit b7087adb78
2 changed files with 5 additions and 5 deletions

View File

@ -44,6 +44,7 @@ func NewGame(id string, width, height float64) *game {
func (g *game) run() { func (g *game) run() {
started := false started := false
var t0, t1 time.Time var t0, t1 time.Time
payload := bot.NewBoardstate()
for { for {
select { select {
case <-g.kill: case <-g.kill:
@ -69,6 +70,8 @@ func (g *game) run() {
} }
g.turn++ g.turn++
payload.Turn = g.turn
t0 = time.Now() t0 = time.Now()
if *verbose { if *verbose {
@ -78,9 +81,6 @@ func (g *game) run() {
log.Printf("Explosions: %v", len(g.splosions)) log.Printf("Explosions: %v", len(g.splosions))
} }
// TODO: making one of these every iteration seems wasteful
payload := bot.NewBoardstate(g.turn)
robots_remaining := 0 robots_remaining := 0
for p := range g.players { for p := range g.players {
@ -140,6 +140,7 @@ func (g *game) run() {
log.Printf("Sent Payload %v\n", t1.Sub(t0)) log.Printf("Sent Payload %v\n", t1.Sub(t0))
} }
payload.EmptySlices()
} }
} }
} }

View File

@ -63,8 +63,7 @@ func (p *player) nudge() {
} }
func (p *player) scan(players map[*player]bool) { func (p *player) scan(players map[*player]bool) {
// TODO: perhaps keep the same one around? p.Robot.Scanners = p.Robot.Scanners[:0]
p.Robot.Scanners = make([]bot.Scanner, 0)
for player, _ := range players { for player, _ := range players {
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 { if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
continue continue