fixed panic when printing snake out of bounds (#46)
Co-authored-by: Jiri Novotny <hello@jiricodes.com>
This commit is contained in:
parent
f65f6d65d7
commit
0331ea65f8
1 changed files with 7 additions and 4 deletions
|
|
@ -4,9 +4,6 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/BattlesnakeOfficial/rules"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cobra"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
|
@ -16,6 +13,10 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/BattlesnakeOfficial/rules"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Battlesnake struct {
|
||||
|
|
@ -496,7 +497,9 @@ func printMap(state *rules.BoardState, outOfBounds []rules.Point, gameTurn int32
|
|||
o.WriteString(fmt.Sprintf("Food ⚕: %v\n", state.Food))
|
||||
for _, s := range state.Snakes {
|
||||
for _, b := range s.Body {
|
||||
board[b.X][b.Y] = Battlesnakes[s.ID].Character
|
||||
if b.X >= 0 && b.X < state.Width && b.Y >= 0 && b.Y < state.Height {
|
||||
board[b.X][b.Y] = Battlesnakes[s.ID].Character
|
||||
}
|
||||
}
|
||||
o.WriteString(fmt.Sprintf("%v %c: %v\n", Battlesnakes[s.ID].Name, Battlesnakes[s.ID].Character, s))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue