-
Notifications
You must be signed in to change notification settings - Fork 52
/
empty.go
62 lines (49 loc) · 1.51 KB
/
empty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package maps
import (
"github.com/BattlesnakeOfficial/rules"
)
type EmptyMap struct{}
func init() {
globalRegistry.RegisterMap("empty", EmptyMap{})
}
func (m EmptyMap) ID() string {
return "empty"
}
func (m EmptyMap) Meta() Metadata {
return Metadata{
Name: "Empty",
Description: "Default snake placement with no food",
Author: "Battlesnake",
Version: 2,
MinPlayers: 1,
MaxPlayers: 16,
BoardSizes: OddSizes(rules.BoardSizeSmall, rules.BoardSizeXXLarge),
Tags: []string{},
}
}
func (m EmptyMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
rand := settings.GetRand(0)
if len(initialBoardState.Snakes) > int(m.Meta().MaxPlayers) {
return rules.ErrorTooManySnakes
}
snakeIDs := make([]string, 0, len(initialBoardState.Snakes))
for _, snake := range initialBoardState.Snakes {
snakeIDs = append(snakeIDs, snake.ID)
}
tempBoardState := rules.NewBoardState(initialBoardState.Width, initialBoardState.Height)
err := rules.PlaceSnakesAutomatically(rand, tempBoardState, snakeIDs)
if err != nil {
return err
}
// Copy snakes from temp board state
for _, snake := range tempBoardState.Snakes {
editor.PlaceSnake(snake.ID, snake.Body, snake.Health)
}
return nil
}
func (m EmptyMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
return nil
}
func (m EmptyMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error {
return nil
}