* DEV-1761: Clean up Ruleset interface (#115) * remove legacy ruleset types and simplify ruleset interface * remove unnecessary settings argument from Ruleset interface * decouple rules.Settings from client API and store settings as strings * DEV 1761: Add new BoardState and Point fields (#117) * add Point.TTL, Point.Value, GameState and PointState to BoardState * allow maps to access BoardState.GameState,PointState * add PreUpdateBoard and refactor snail_mode with it * fix bug where an extra turn was printed to the console * fix formatting * fix lint errors Co-authored-by: JonathanArns <jonathan.arns@googlemail.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
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
|
|
}
|