maps

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

README

Game Maps

Game maps are a way to customize the game board independently of the pipeline of game rules, including snake positions, food and hazard spawning. More advanced mechanics, such as snake bots generated by the map, may be available in the future.

Anyone can write a new game map and submit a PR! Currently there are a few additional changes needed behind the scenes for it to appear in the production Battlesnake engine and on play.battlesnake.com, but you'll be able to use your own map right away with the battlesnake CLI.

How to write a map

You'll need to create a new Go type that implements maps.GameMap, and register it under a unique identifier. The methods your game map will need to implement are:

ID

Returns the unique ID this game map will be registered under. This method exists mostly to guard against typos while registering maps.

Meta

Returns some optional metadata about the map, currently name, author, and description. At some point we hope to expose this through the UI to give credit to community map authors.

SetupBoard

Called to generate a new board. The map is responsible for placing all snakes, food, and hazards. An initial rules.BoardState is passed in that will be initialized with the width, height, and snakes with IDs but no bodies. SetupBoard should not modify this BoardState, but instead call methods on the maps.Editor to place snakes and optionally food/hazards.

UpdateBoard

Called to update an existing board every turn. For a map that doesn't spawn food or hazards after initial creation, this method can be a no-op! For maps that just do standard random food spawning, delegating to one of the existing maps is a good way to handle that.

Registering your map

Your map will need to be registered with its own ID using maps.RegisterMap. There are a few automated tests that will be run automatically on any registered map to ensure it appears to work correctly. You can run those tests yourself with:

go test ./maps

Things to watch out for

  • SetupBoard is called before any turns are run and before the game rules are applied. UpdateBoard is called at the end of each turn, after snakes have moved, been eliminated, etc.
  • There's no protection against placing duplicate food/hazards on the same location on the board. Maps need to account for this, especially when generating random food/hazard spawns.
  • All maps that make use of random behaviour should use the GetRand method on the settings object passed in to get a random number generator seeded with the game's seed and current turn. This will ensure the map generates in a reliable way, and will allow reproducing games based on the seed at some point in the near future.

How to test your map

  • You can trigger a game locally using the new map with:
battlesnake play --width 11 --height 11 --name mysnake --url http://example.com/snake --name othersnake --url http://example.com/snake --map MAP_ID  --viewmap

Documentation

Index

Constants

View Source
const (
	TAG_EXPERIMENTAL     = "experimental"     // experimental map, only available via CLI
	TAG_SNAKE_PLACEMENT  = "snake-placement"  // map overrides default snake placement
	TAG_HAZARD_PLACEMENT = "hazard-placement" // map places hazards
	TAG_FOOD_PLACEMENT   = "food-placement"   // map overrides or adds to default food placement
)
View Source
const DEBUG_MAZE_GENERATION = false

When this is flipped to `true` TWO things happen

  1. More println style debugging is done
  2. We print out the current game board in between each room sub-division, and wait for the CLI User to hit enter to sub-divide the next room. This allows you to see the maze get generated in realtime, which was super useful while debugging issues in the maze generation
View Source
const EVIL_MODE_DISTANCE_TO_FOOD = 5
View Source
const INITIAL_MAZE_SIZE = 7
View Source
const MAX_TRIES = 100
View Source
const TURNS_AT_MAX_SIZE = 5

Variables

View Source
var ArcadeMazeHazards []rules.Point = []rules.Point{}/* 187 elements not displayed */

Functions

func AnySize added in v1.1.10

func AnySize() sizes

AnySize creates sizes for a board that has no fixed sizes (supports unlimited sizes).

func FixedSizes added in v1.1.10

func FixedSizes(a Dimensions, b ...Dimensions) sizes

FixedSizes creates dimensions for a board that has 1 or more fixed sizes. Examples: - FixedSizes(Dimension{9,11}) supports only a width of 9 and a height of 11. - FixedSizes(Dimensions{11,11},Dimensions{19,19}) supports sizes 11x11 and 19x19

func List added in v1.1.15

func List() []string

List returns a list of maps registered to the global registry.

func OddSizes added in v1.1.13

func OddSizes(min, max int) sizes

OddSizes generates square (width = height) board sizes with an odd number of positions in the vertical and horizontal directions. Examples:

  • OddSizes(11,21) produces [(11,11), (13,13), (15,15), (17,17), (19,19), (21,21)]

func PlaceFoodFixed added in v1.1.20

func PlaceFoodFixed(rand rules.Rand, initialBoardState *rules.BoardState, editor Editor) error

func PlaceSnakesInQuadrants added in v1.1.20

func PlaceSnakesInQuadrants(rand rules.Rand, editor Editor, snakes []rules.Snake, quadrants [][]rules.Point) error

func PostUpdateBoard added in v1.2.0

func PostUpdateBoard(gameMap GameMap, previousBoardState *rules.BoardState, settings rules.Settings) (*rules.BoardState, error)

func PreUpdateBoard added in v1.2.0

func PreUpdateBoard(gameMap GameMap, previousBoardState *rules.BoardState, settings rules.Settings) (*rules.BoardState, error)

PreUpdateBoard updates a board state with a map.

func RegisterMap

func RegisterMap(id string, m GameMap)

RegisterMap adds a map to the global registry.

func SetupBoard

func SetupBoard(mapID string, settings rules.Settings, width, height int, snakeIDs []string) (*rules.BoardState, error)

SetupBoard is a shortcut for looking up a map by ID and initializing a new board state with it.

func TestMap added in v1.1.4

func TestMap(id string, m GameMap, callback func())

Types

type ArcadeMazeMap added in v1.1.5

type ArcadeMazeMap struct{}

func (ArcadeMazeMap) ID added in v1.1.5

func (m ArcadeMazeMap) ID() string

func (ArcadeMazeMap) Meta added in v1.1.5

func (m ArcadeMazeMap) Meta() Metadata

func (ArcadeMazeMap) PostUpdateBoard added in v1.2.0

func (m ArcadeMazeMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ArcadeMazeMap) PreUpdateBoard added in v1.2.0

func (m ArcadeMazeMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ArcadeMazeMap) SetupBoard added in v1.1.5

func (m ArcadeMazeMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type BoardStateEditor

type BoardStateEditor struct {
	// contains filtered or unexported fields
}

An Editor backed by a BoardState.

func NewBoardStateEditor

func NewBoardStateEditor(boardState *rules.BoardState) *BoardStateEditor

func (*BoardStateEditor) AddFood

func (editor *BoardStateEditor) AddFood(p rules.Point)

func (*BoardStateEditor) AddHazard

func (editor *BoardStateEditor) AddHazard(p rules.Point)

func (*BoardStateEditor) ClearFood

func (editor *BoardStateEditor) ClearFood()

func (*BoardStateEditor) ClearHazards

func (editor *BoardStateEditor) ClearHazards()

func (*BoardStateEditor) FilterUnoccupiedPoints added in v1.1.20

func (editor *BoardStateEditor) FilterUnoccupiedPoints(targets []rules.Point, snakes, hazards, food bool) []rules.Point

Given a list of points, return only those that are unoccupied by snake bodies, food, and/or hazards.

func (*BoardStateEditor) Food added in v1.1.20

func (editor *BoardStateEditor) Food() []rules.Point

Get the locations of food currently on the board. Note: the return value is read-only.

func (*BoardStateEditor) GameState added in v1.2.0

func (editor *BoardStateEditor) GameState() map[string]string

Get an editable reference to the BoardState's GameState field

func (*BoardStateEditor) Hazards added in v1.1.20

func (editor *BoardStateEditor) Hazards() []rules.Point

Get the locations of hazards currently on the board. Note: the return value is read-only.

func (*BoardStateEditor) IsOccupied added in v1.1.20

func (editor *BoardStateEditor) IsOccupied(point rules.Point, snakes, hazards, food bool) bool

Returns true if the provided point on the board is occupied by a snake body, food, and/or hazard.

func (*BoardStateEditor) OccupiedPoints added in v1.1.20

func (editor *BoardStateEditor) OccupiedPoints(snakes, hazards, food bool) map[rules.Point]bool

Get a set of all points on the board the are occupied by snake bodies, food, and/or hazards. The value for each point will be set to true in the return value if that point is occupied by one of the selected objects.

func (*BoardStateEditor) PlaceSnake

func (editor *BoardStateEditor) PlaceSnake(id string, body []rules.Point, health int)

func (*BoardStateEditor) PlaceSnakesRandomlyAtPositions added in v1.1.20

func (editor *BoardStateEditor) PlaceSnakesRandomlyAtPositions(rand rules.Rand, snakes []rules.Snake, heads []rules.Point, bodyLength int) error

Given a list of Snakes and a list of head coordinates, randomly place the snakes on those coordinates, or return an error if placement of all Snakes is impossible.

func (*BoardStateEditor) PointState added in v1.2.0

func (editor *BoardStateEditor) PointState() map[rules.Point]int

Get an editable reference to the BoardState's PointState field

func (*BoardStateEditor) RemoveFood

func (editor *BoardStateEditor) RemoveFood(p rules.Point)

func (*BoardStateEditor) RemoveHazard

func (editor *BoardStateEditor) RemoveHazard(p rules.Point)

func (*BoardStateEditor) ShufflePoints added in v1.1.20

func (editor *BoardStateEditor) ShufflePoints(rand rules.Rand, points []rules.Point)

func (*BoardStateEditor) SnakeBodies added in v1.1.20

func (editor *BoardStateEditor) SnakeBodies() map[string][]rules.Point

Get the bodies of all non-eliminated snakes currently on the board. Note: the return value is read-only.

type CastleWallExtraLargeHazardsMap added in v1.1.17

type CastleWallExtraLargeHazardsMap struct{}

func (CastleWallExtraLargeHazardsMap) ID added in v1.1.17

func (CastleWallExtraLargeHazardsMap) Meta added in v1.1.17

func (CastleWallExtraLargeHazardsMap) PostUpdateBoard added in v1.2.0

func (m CastleWallExtraLargeHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallExtraLargeHazardsMap) PreUpdateBoard added in v1.2.0

func (m CastleWallExtraLargeHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallExtraLargeHazardsMap) SetupBoard added in v1.1.17

func (m CastleWallExtraLargeHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type CastleWallLargeHazardsMap added in v1.1.17

type CastleWallLargeHazardsMap struct{}

func (CastleWallLargeHazardsMap) ID added in v1.1.17

func (CastleWallLargeHazardsMap) Meta added in v1.1.17

func (CastleWallLargeHazardsMap) PostUpdateBoard added in v1.2.0

func (m CastleWallLargeHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallLargeHazardsMap) PreUpdateBoard added in v1.2.0

func (m CastleWallLargeHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallLargeHazardsMap) SetupBoard added in v1.1.17

func (m CastleWallLargeHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type CastleWallMediumHazardsMap added in v1.1.17

type CastleWallMediumHazardsMap struct{}

func (CastleWallMediumHazardsMap) ID added in v1.1.17

func (CastleWallMediumHazardsMap) Meta added in v1.1.17

func (CastleWallMediumHazardsMap) PostUpdateBoard added in v1.2.0

func (m CastleWallMediumHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallMediumHazardsMap) PreUpdateBoard added in v1.2.0

func (m CastleWallMediumHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (CastleWallMediumHazardsMap) SetupBoard added in v1.1.17

func (m CastleWallMediumHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type ColumnsHazardsMap added in v1.1.6

type ColumnsHazardsMap struct{}

func (ColumnsHazardsMap) ID added in v1.1.6

func (m ColumnsHazardsMap) ID() string

func (ColumnsHazardsMap) Meta added in v1.1.6

func (m ColumnsHazardsMap) Meta() Metadata

func (ColumnsHazardsMap) PostUpdateBoard added in v1.2.0

func (m ColumnsHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ColumnsHazardsMap) PreUpdateBoard added in v1.2.0

func (m ColumnsHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ColumnsHazardsMap) SetupBoard added in v1.1.6

func (m ColumnsHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type ConcentricRingsHazardsMap added in v1.1.6

type ConcentricRingsHazardsMap struct{}

func (ConcentricRingsHazardsMap) ID added in v1.1.6

func (ConcentricRingsHazardsMap) Meta added in v1.1.6

func (ConcentricRingsHazardsMap) PostUpdateBoard added in v1.2.0

func (m ConcentricRingsHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ConcentricRingsHazardsMap) PreUpdateBoard added in v1.2.0

func (m ConcentricRingsHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ConcentricRingsHazardsMap) SetupBoard added in v1.1.6

func (m ConcentricRingsHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type Dimensions added in v1.1.10

type Dimensions struct {
	// Width is the width, in number of board squares, of the board.
	// The value 0 has a special meaning to mean unlimited.
	Width int
	// Height is the height, in number of board squares, of the board.
	// The value 0 has a special meaning to mean unlimited.
	Height int
}

Dimensions describes the size of a Battlesnake board.

type DirectionalExpandingBoxMap added in v1.1.6

type DirectionalExpandingBoxMap struct{}

func (DirectionalExpandingBoxMap) ID added in v1.1.6

func (DirectionalExpandingBoxMap) Meta added in v1.1.6

func (DirectionalExpandingBoxMap) PostUpdateBoard added in v1.2.0

func (m DirectionalExpandingBoxMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (DirectionalExpandingBoxMap) PreUpdateBoard added in v1.2.0

func (m DirectionalExpandingBoxMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (DirectionalExpandingBoxMap) SetupBoard added in v1.1.6

func (m DirectionalExpandingBoxMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type Editor

type Editor interface {
	// Clears all food from the board.
	ClearFood()

	// Adds a food to the board. Does not check for duplicates.
	AddFood(rules.Point)

	// Removes all food from a specific tile on the board.
	RemoveFood(rules.Point)

	// Get the locations of food currently on the board.
	// Note: the return value is a copy and modifying it won't affect the board.
	Food() []rules.Point

	// Clears all hazards from the board.
	ClearHazards()

	// Adds a hazard to the board. Does not check for duplicates.
	AddHazard(rules.Point)

	// Removes all hazards from a specific tile on the board.
	RemoveHazard(rules.Point)

	// Get the locations of hazards currently on the board.
	// Note: the return value is a copy and modifying it won't affect the board.
	Hazards() []rules.Point

	// Updates the body and health of a snake.
	PlaceSnake(id string, body []rules.Point, health int)

	// Get the bodies of all non-eliminated snakes currently on the board, keyed by Snake ID
	// Note: the body values in the return value are a copy and modifying them won't affect the board.
	SnakeBodies() map[string][]rules.Point

	// Get an editable reference to the BoardState's GameState field
	GameState() map[string]string

	// Get an editable reference to the BoardState's PointState field
	PointState() map[rules.Point]int

	// Given a list of Snakes and a list of head coordinates, randomly place
	// the snakes on those coordinates, or return an error if placement of all
	// Snakes is impossible.
	PlaceSnakesRandomlyAtPositions(rand rules.Rand, snakes []rules.Snake, heads []rules.Point, bodyLength int) error

	// Returns true if the provided point on the board is occupied by a snake body, food, and/or hazard.
	IsOccupied(point rules.Point, snakes, hazards, food bool) bool

	// Get a set of all points on the board the are occupied by snake bodies, food, and/or hazards.
	// The value for each point will be set to true in the return value if that point is occupied by one of the selected objects.
	OccupiedPoints(snakes, hazards, food bool) map[rules.Point]bool

	// Given a list of points, return only those that are unoccupied by snake bodies, food, and/or hazards.
	FilterUnoccupiedPoints(targets []rules.Point, snakes, hazards, food bool) []rules.Point

	// Shuffle the provided slice of points randomly using the provided rules.Rand
	ShufflePoints(rules.Rand, []rules.Point)
}

Editor is used by GameMap implementations to modify the board state.

type EmptyMap added in v1.1.2

type EmptyMap struct{}

func (EmptyMap) ID added in v1.1.2

func (m EmptyMap) ID() string

func (EmptyMap) Meta added in v1.1.2

func (m EmptyMap) Meta() Metadata

func (EmptyMap) PostUpdateBoard added in v1.2.0

func (m EmptyMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (EmptyMap) PreUpdateBoard added in v1.2.0

func (m EmptyMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (EmptyMap) SetupBoard added in v1.1.2

func (m EmptyMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type ExpandingBoxMap added in v1.1.6

type ExpandingBoxMap struct{}

func (ExpandingBoxMap) ID added in v1.1.6

func (m ExpandingBoxMap) ID() string

func (ExpandingBoxMap) Meta added in v1.1.6

func (m ExpandingBoxMap) Meta() Metadata

func (ExpandingBoxMap) PostUpdateBoard added in v1.2.0

func (m ExpandingBoxMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ExpandingBoxMap) PreUpdateBoard added in v1.2.0

func (m ExpandingBoxMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ExpandingBoxMap) SetupBoard added in v1.1.6

func (m ExpandingBoxMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type ExpandingScatterMap added in v1.1.6

type ExpandingScatterMap struct{}

func (ExpandingScatterMap) ID added in v1.1.6

func (m ExpandingScatterMap) ID() string

func (ExpandingScatterMap) Meta added in v1.1.6

func (m ExpandingScatterMap) Meta() Metadata

func (ExpandingScatterMap) PostUpdateBoard added in v1.2.0

func (m ExpandingScatterMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ExpandingScatterMap) PreUpdateBoard added in v1.2.0

func (m ExpandingScatterMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ExpandingScatterMap) SetupBoard added in v1.1.6

func (m ExpandingScatterMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type GameMap

type GameMap interface {
	// Return a unique identifier for this map.
	ID() string

	// Return non-functional metadata about this map.
	Meta() Metadata

	// Called to generate a new board. The map is responsible for placing all snakes, food, and hazards.
	SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

	// Called every turn to optionally update the board before the board is sent to snakes to get their moves.
	// Changes made here will be seen by snakes before before making their moves, but users in the
	// browser will see the changes at the same time as the snakes' moves.
	//
	// State that is stored in the map by this method will be visible to the PostUpdateBoard method
	// later in the same turn, but will not nessecarily be available when processing later turns.
	//
	// Disclaimer: Unless you have a specific usecase like moving hazards or storing intermediate state,
	// PostUpdateBoard is probably the better function to use.
	PreUpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

	// Called every turn to optionally update the board after all other rules have been applied.
	// Changes made here will be seen by both snakes and users in the browser, before before snakes
	// make their next moves.
	PostUpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error
}

func GetMap

func GetMap(id string) (GameMap, error)

GetMap returns the map associated with the given ID from the global registry.

type HazardPitsMap added in v1.1.17

type HazardPitsMap struct{}

func (HazardPitsMap) AddHazardPits added in v1.1.17

func (m HazardPitsMap) AddHazardPits(board *rules.BoardState, settings rules.Settings, editor Editor)

func (HazardPitsMap) ID added in v1.1.17

func (m HazardPitsMap) ID() string

func (HazardPitsMap) Meta added in v1.1.17

func (m HazardPitsMap) Meta() Metadata

func (HazardPitsMap) PostUpdateBoard added in v1.2.0

func (m HazardPitsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (HazardPitsMap) PreUpdateBoard added in v1.2.0

func (m HazardPitsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (HazardPitsMap) SetupBoard added in v1.1.17

func (m HazardPitsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type HealingPoolsMap added in v1.1.14

type HealingPoolsMap struct{}

func (HealingPoolsMap) ID added in v1.1.14

func (m HealingPoolsMap) ID() string

func (HealingPoolsMap) Meta added in v1.1.14

func (m HealingPoolsMap) Meta() Metadata

func (HealingPoolsMap) PostUpdateBoard added in v1.2.0

func (m HealingPoolsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (HealingPoolsMap) PreUpdateBoard added in v1.2.0

func (m HealingPoolsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (HealingPoolsMap) SetupBoard added in v1.1.14

func (m HealingPoolsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type InnerBorderHazardsMap added in v1.1.6

type InnerBorderHazardsMap struct{}

func (InnerBorderHazardsMap) ID added in v1.1.6

func (InnerBorderHazardsMap) Meta added in v1.1.6

func (InnerBorderHazardsMap) PostUpdateBoard added in v1.2.0

func (m InnerBorderHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (InnerBorderHazardsMap) PreUpdateBoard added in v1.2.0

func (m InnerBorderHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (InnerBorderHazardsMap) SetupBoard added in v1.1.6

func (m InnerBorderHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type IslandsAndBridgesLargeHazardsMap added in v1.1.17

type IslandsAndBridgesLargeHazardsMap struct{}

func (IslandsAndBridgesLargeHazardsMap) ID added in v1.1.17

func (IslandsAndBridgesLargeHazardsMap) Meta added in v1.1.17

func (IslandsAndBridgesLargeHazardsMap) PostUpdateBoard added in v1.2.0

func (m IslandsAndBridgesLargeHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (IslandsAndBridgesLargeHazardsMap) PreUpdateBoard added in v1.2.0

func (m IslandsAndBridgesLargeHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (IslandsAndBridgesLargeHazardsMap) SetupBoard added in v1.1.17

func (m IslandsAndBridgesLargeHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type IslandsAndBridgesMediumHazardsMap added in v1.1.17

type IslandsAndBridgesMediumHazardsMap struct{}

func (IslandsAndBridgesMediumHazardsMap) ID added in v1.1.17

func (IslandsAndBridgesMediumHazardsMap) Meta added in v1.1.17

func (IslandsAndBridgesMediumHazardsMap) PostUpdateBoard added in v1.2.0

func (m IslandsAndBridgesMediumHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (IslandsAndBridgesMediumHazardsMap) PreUpdateBoard added in v1.2.0

func (m IslandsAndBridgesMediumHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (IslandsAndBridgesMediumHazardsMap) SetupBoard added in v1.1.17

func (m IslandsAndBridgesMediumHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type MapRegistry

type MapRegistry map[string]GameMap

MapRegistry is a mapping of map names to game maps.

func (MapRegistry) GetMap

func (registry MapRegistry) GetMap(id string) (GameMap, error)

GetMap returns the map associated with the given ID.

func (MapRegistry) List added in v1.1.15

func (registry MapRegistry) List() []string

List returns all registered map IDs in alphabetical order

func (MapRegistry) RegisterMap

func (registry MapRegistry) RegisterMap(id string, m GameMap)

RegisterMap adds a stage to the registry. If a map has already been registered this will panic.

type Metadata

type Metadata struct {
	Name        string
	Author      string
	Description string
	// Version is the current version of the game map.
	// Each time a map is changed, the version number should be incremented by 1.
	Version int
	// MinPlayers is the minimum number of players that the map supports.
	MinPlayers int
	// MaxPlayers is the maximum number of players that the map supports.
	MaxPlayers int
	// BoardSizes is a list of supported board sizes. Board sizes can fall into one of 3 categories:
	//   1. one fixed size (i.e. [11x11])
	//   2. multiple, fixed sizes (i.e. [11x11, 19x19, 25x25])
	//   3. "unlimited" sizes (the board is not fixed and can scale to any reasonable size)
	BoardSizes sizes
	// Tags is a list of strings use to categorize the map.
	Tags []string
}

func (Metadata) Validate added in v1.1.20

func (meta Metadata) Validate(boardState *rules.BoardState) error

type RiverAndBridgesExtraLargeHazardsMap added in v1.1.16

type RiverAndBridgesExtraLargeHazardsMap struct{}

func (RiverAndBridgesExtraLargeHazardsMap) ID added in v1.1.16

func (RiverAndBridgesExtraLargeHazardsMap) Meta added in v1.1.16

func (RiverAndBridgesExtraLargeHazardsMap) PostUpdateBoard added in v1.2.0

func (m RiverAndBridgesExtraLargeHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesExtraLargeHazardsMap) PreUpdateBoard added in v1.2.0

func (m RiverAndBridgesExtraLargeHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesExtraLargeHazardsMap) SetupBoard added in v1.1.16

func (m RiverAndBridgesExtraLargeHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type RiverAndBridgesLargeHazardsMap added in v1.1.16

type RiverAndBridgesLargeHazardsMap struct{}

func (RiverAndBridgesLargeHazardsMap) ID added in v1.1.16

func (RiverAndBridgesLargeHazardsMap) Meta added in v1.1.16

func (RiverAndBridgesLargeHazardsMap) PostUpdateBoard added in v1.2.0

func (m RiverAndBridgesLargeHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesLargeHazardsMap) PreUpdateBoard added in v1.2.0

func (m RiverAndBridgesLargeHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesLargeHazardsMap) SetupBoard added in v1.1.16

func (m RiverAndBridgesLargeHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type RiverAndBridgesMediumHazardsMap added in v1.1.16

type RiverAndBridgesMediumHazardsMap struct{}

func (RiverAndBridgesMediumHazardsMap) ID added in v1.1.16

func (RiverAndBridgesMediumHazardsMap) Meta added in v1.1.16

func (RiverAndBridgesMediumHazardsMap) PostUpdateBoard added in v1.2.0

func (m RiverAndBridgesMediumHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesMediumHazardsMap) PreUpdateBoard added in v1.2.0

func (m RiverAndBridgesMediumHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RiverAndBridgesMediumHazardsMap) SetupBoard added in v1.1.16

func (m RiverAndBridgesMediumHazardsMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type RoyaleHazardsMap added in v1.1.2

type RoyaleHazardsMap struct{}

func (RoyaleHazardsMap) ID added in v1.1.2

func (m RoyaleHazardsMap) ID() string

func (RoyaleHazardsMap) Meta added in v1.1.2

func (m RoyaleHazardsMap) Meta() Metadata

func (RoyaleHazardsMap) PostUpdateBoard added in v1.2.0

func (m RoyaleHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RoyaleHazardsMap) PreUpdateBoard added in v1.2.0

func (m RoyaleHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (RoyaleHazardsMap) SetupBoard added in v1.1.2

func (m RoyaleHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type ScatterFillMap added in v1.1.6

type ScatterFillMap struct{}

func (ScatterFillMap) ID added in v1.1.6

func (m ScatterFillMap) ID() string

func (ScatterFillMap) Meta added in v1.1.6

func (m ScatterFillMap) Meta() Metadata

func (ScatterFillMap) PostUpdateBoard added in v1.2.0

func (m ScatterFillMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ScatterFillMap) PreUpdateBoard added in v1.2.0

func (m ScatterFillMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (ScatterFillMap) SetupBoard added in v1.1.6

func (m ScatterFillMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type SinkholesMap added in v1.1.14

type SinkholesMap struct{}

func (SinkholesMap) ID added in v1.1.14

func (m SinkholesMap) ID() string

func (SinkholesMap) Meta added in v1.1.14

func (m SinkholesMap) Meta() Metadata

func (SinkholesMap) PostUpdateBoard added in v1.2.0

func (m SinkholesMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SinkholesMap) PreUpdateBoard added in v1.2.0

func (m SinkholesMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SinkholesMap) SetupBoard added in v1.1.14

func (m SinkholesMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type SnailModeMap added in v1.1.16

type SnailModeMap struct{}

func (SnailModeMap) ID added in v1.1.16

func (m SnailModeMap) ID() string

ID returns a unique identifier for this map.

func (SnailModeMap) Meta added in v1.1.16

func (m SnailModeMap) Meta() Metadata

Meta returns the non-functional metadata about this map.

func (SnailModeMap) PostUpdateBoard added in v1.2.0

func (m SnailModeMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

PostUpdateBoard does the work of placing the hazards along the 'snail tail' of snakes This is responsible for saving the current tail location off the board and restoring the previous tail position. This also handles removing one hazards from the current stacks so the hazards tails fade as the snake moves away.

func (SnailModeMap) PreUpdateBoard added in v1.2.0

func (m SnailModeMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SnailModeMap) SetupBoard added in v1.1.16

func (m SnailModeMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

SetupBoard here is pretty 'standard' and doesn't do any special setup for this game mode

type SoloMazeMap added in v1.1.12

type SoloMazeMap struct{}

func (SoloMazeMap) AdjustPosition added in v1.1.12

func (m SoloMazeMap) AdjustPosition(mazePosition rules.Point, actualBoardSize int, boardHeight int, boardWidth int) rules.Point

func (SoloMazeMap) CreateMaze added in v1.1.12

func (m SoloMazeMap) CreateMaze(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor, currentLevel int64) error

func (SoloMazeMap) ID added in v1.1.12

func (m SoloMazeMap) ID() string

func (SoloMazeMap) Meta added in v1.1.12

func (m SoloMazeMap) Meta() Metadata

func (SoloMazeMap) PlaceFood added in v1.1.12

func (m SoloMazeMap) PlaceFood(boardState *rules.BoardState, settings rules.Settings, editor Editor, currentLevel int64)

func (SoloMazeMap) PostUpdateBoard added in v1.2.0

func (m SoloMazeMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SoloMazeMap) PreUpdateBoard added in v1.2.0

func (m SoloMazeMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SoloMazeMap) ReadBitState added in v1.1.12

func (m SoloMazeMap) ReadBitState(boardState *rules.BoardState) (int64, error)

func (SoloMazeMap) SetupBoard added in v1.1.12

func (m SoloMazeMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SoloMazeMap) SubdivideRoom added in v1.1.12

func (m SoloMazeMap) SubdivideRoom(tempBoardState *rules.BoardState, rand rules.Rand, lowPoint rules.Point, highPoint rules.Point, disAllowedHorizontal []int, disAllowedVertical []int, depth int) bool

Mostly based off this algorithm from Wikipedia: https://en.wikipedia.org/wiki/Maze_generation_algorithm#Recursive_division_method

func (SoloMazeMap) WriteBitState added in v1.1.12

func (m SoloMazeMap) WriteBitState(boardState *rules.BoardState, state int64, editor Editor)

type SpiralHazardsMap added in v1.1.6

type SpiralHazardsMap struct{}

func (SpiralHazardsMap) ID added in v1.1.6

func (m SpiralHazardsMap) ID() string

func (SpiralHazardsMap) Meta added in v1.1.6

func (m SpiralHazardsMap) Meta() Metadata

func (SpiralHazardsMap) PostUpdateBoard added in v1.2.0

func (m SpiralHazardsMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SpiralHazardsMap) PreUpdateBoard added in v1.2.0

func (m SpiralHazardsMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (SpiralHazardsMap) SetupBoard added in v1.1.6

func (m SpiralHazardsMap) SetupBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type StandardMap

type StandardMap struct{}

func (StandardMap) ID

func (m StandardMap) ID() string

func (StandardMap) Meta

func (m StandardMap) Meta() Metadata

func (StandardMap) PostUpdateBoard added in v1.2.0

func (m StandardMap) PostUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StandardMap) PreUpdateBoard added in v1.2.0

func (m StandardMap) PreUpdateBoard(lastBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StandardMap) SetupBoard

func (m StandardMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

type StubMap added in v1.1.1

type StubMap struct {
	Id             string
	SnakePositions map[string]rules.Point
	Food           []rules.Point
	Hazards        []rules.Point
	Error          error
}

An implementation of GameMap that just does predetermined placements, for testing.

func (StubMap) ID added in v1.1.1

func (m StubMap) ID() string

func (StubMap) Meta added in v1.1.1

func (StubMap) Meta() Metadata

func (StubMap) PostUpdateBoard added in v1.2.0

func (m StubMap) PostUpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StubMap) PreUpdateBoard added in v1.2.0

func (m StubMap) PreUpdateBoard(previousBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

func (StubMap) SetupBoard added in v1.1.1

func (m StubMap) SetupBoard(initialBoardState *rules.BoardState, settings rules.Settings, editor Editor) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL