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"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/BattlesnakeOfficial/rules"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
@ -16,6 +13,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/BattlesnakeOfficial/rules"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Battlesnake struct {
|
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))
|
o.WriteString(fmt.Sprintf("Food ⚕: %v\n", state.Food))
|
||||||
for _, s := range state.Snakes {
|
for _, s := range state.Snakes {
|
||||||
for _, b := range s.Body {
|
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))
|
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