Documentation ¶
Index ¶
- Constants
- func DamageHazardsStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func EliminateSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func FeedSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func GameOverSolo(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func GameOverSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func GameOverStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func GrowSnakesConstrictor(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func MoveSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func MoveSnakesWrapped(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func NewRulesetBuilder() *rulesetBuilder
- func PlaceFoodAutomatically(b *BoardState) error
- func PlaceFoodFixed(b *BoardState) error
- func PlaceFoodRandomly(b *BoardState, n int32) error
- func PlaceSnake(b *BoardState, snakeID string, body []Point) error
- func PlaceSnakesAutomatically(b *BoardState, snakeIDs []string) error
- func PlaceSnakesFixed(b *BoardState, snakeIDs []string) error
- func PlaceSnakesRandomly(b *BoardState, snakeIDs []string) error
- func PopulateHazardsRoyale(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func ReduceSnakeHealthStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func RemoveFoodConstrictor(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func ResurrectSnakesSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func ShareAttributesSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- func SpawnFoodStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
- type BoardState
- type ConstrictorRuleset
- type Point
- type RoyaleRuleset
- type RoyaleSettings
- type Ruleset
- type RulesetError
- type Settings
- type Snake
- type SnakeMove
- type SoloRuleset
- type SquadRuleset
- type SquadSettings
- type StageFunc
- type StandardRuleset
- func (r *StandardRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
- func (r *StandardRuleset) IsGameOver(b *BoardState) (bool, error)
- func (r *StandardRuleset) ModifyInitialBoardState(initialState *BoardState) (*BoardState, error)
- func (r *StandardRuleset) Name() string
- func (r StandardRuleset) Settings() Settings
- type WrappedRuleset
Constants ¶
const ( MoveUp = "up" MoveDown = "down" MoveRight = "right" MoveLeft = "left" BoardSizeSmall = 7 BoardSizeMedium = 11 BoardSizeLarge = 19 SnakeMaxHealth = 100 SnakeStartSize = 3 // bvanvugt - TODO: Just return formatted strings instead of codes? NotEliminated = "" EliminatedByCollision = "snake-collision" EliminatedBySelfCollision = "snake-self-collision" EliminatedByOutOfHealth = "out-of-health" EliminatedByHeadToHeadCollision = "head-collision" EliminatedByOutOfBounds = "wall-collision" EliminatedBySquad = "squad-eliminated" // TODO - Error consts ErrorTooManySnakes = RulesetError("too many snakes for fixed start positions") ErrorNoRoomForSnake = RulesetError("not enough space to place snake") ErrorNoRoomForFood = RulesetError("not enough space to place food") ErrorNoMoveFound = RulesetError("move not provided for snake") ErrorZeroLengthSnake = RulesetError("snake is length zero") // Ruleset / game type names GameTypeConstrictor = "constrictor" GameTypeRoyale = "royale" GameTypeSolo = "solo" GameTypeSquad = "squad" GameTypeStandard = "standard" GameTypeWrapped = "wrapped" // Game creation parameter names ParamGameType = "name" ParamFoodSpawnChance = "foodSpawnChance" ParamMinimumFood = "minimumFood" ParamHazardDamagePerTurn = "damagePerTurn" ParamHazardMap = "hazardMap" ParamHazardMapAuthor = "hazardMapAuthor" ParamShrinkEveryNTurns = "shrinkEveryNTurns" ParamAllowBodyCollisions = "allowBodyCollisions" )
Variables ¶
This section is empty.
Functions ¶
func DamageHazardsStandard ¶
func DamageHazardsStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func EliminateSnakesStandard ¶
func EliminateSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func FeedSnakesStandard ¶
func FeedSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func GameOverSolo ¶
func GameOverSolo(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func GameOverSquad ¶
func GameOverSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func GameOverStandard ¶
func GameOverStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func GrowSnakesConstrictor ¶
func GrowSnakesConstrictor(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func MoveSnakesStandard ¶
func MoveSnakesStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func MoveSnakesWrapped ¶
func MoveSnakesWrapped(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func NewRulesetBuilder ¶
func NewRulesetBuilder() *rulesetBuilder
NewRulesetBuilder returns an instance of a builder for the Ruleset types.
func PlaceFoodAutomatically ¶
func PlaceFoodAutomatically(b *BoardState) error
PlaceFoodAutomatically initializes the array of food based on the size of the board and the number of snakes.
func PlaceFoodFixed ¶
func PlaceFoodFixed(b *BoardState) error
func PlaceFoodRandomly ¶
func PlaceFoodRandomly(b *BoardState, n int32) error
PlaceFoodRandomly adds up to n new food to the board in random unoccupied squares
func PlaceSnake ¶
func PlaceSnake(b *BoardState, snakeID string, body []Point) error
PlaceSnake adds a snake to the board with the given ID and body coordinates.
func PlaceSnakesAutomatically ¶
func PlaceSnakesAutomatically(b *BoardState, snakeIDs []string) error
PlaceSnakesAutomatically initializes the array of snakes based on the provided snake IDs and the size of the board.
func PlaceSnakesFixed ¶
func PlaceSnakesFixed(b *BoardState, snakeIDs []string) error
func PlaceSnakesRandomly ¶
func PlaceSnakesRandomly(b *BoardState, snakeIDs []string) error
func PopulateHazardsRoyale ¶
func PopulateHazardsRoyale(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func ReduceSnakeHealthStandard ¶
func ReduceSnakeHealthStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func RemoveFoodConstrictor ¶
func RemoveFoodConstrictor(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func ResurrectSnakesSquad ¶
func ResurrectSnakesSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func ShareAttributesSquad ¶
func ShareAttributesSquad(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
func SpawnFoodStandard ¶
func SpawnFoodStandard(b *BoardState, settings Settings, moves []SnakeMove) (bool, error)
Types ¶
type BoardState ¶
type BoardState struct { Turn int32 Height int32 Width int32 Food []Point Snakes []Snake Hazards []Point }
func CreateDefaultBoardState ¶
func CreateDefaultBoardState(width int32, height int32, snakeIDs []string) (*BoardState, error)
CreateDefaultBoardState is a convenience function for fully initializing a "default" board state with snakes and food. In a real game, the engine may generate the board without calling this function, or customize the results based on game-specific settings.
func NewBoardState ¶
func NewBoardState(width, height int32) *BoardState
NewBoardState returns an empty but fully initialized BoardState
func (*BoardState) Clone ¶
func (prevState *BoardState) Clone() *BoardState
Clone returns a deep copy of prevState that can be safely modified inside Ruleset.CreateNextBoardState
type ConstrictorRuleset ¶
type ConstrictorRuleset struct {
StandardRuleset
}
func (*ConstrictorRuleset) CreateNextBoardState ¶
func (r *ConstrictorRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
func (*ConstrictorRuleset) ModifyInitialBoardState ¶
func (r *ConstrictorRuleset) ModifyInitialBoardState(initialBoardState *BoardState) (*BoardState, error)
func (*ConstrictorRuleset) Name ¶
func (r *ConstrictorRuleset) Name() string
type RoyaleRuleset ¶
type RoyaleRuleset struct { StandardRuleset Seed int64 ShrinkEveryNTurns int32 }
func (*RoyaleRuleset) CreateNextBoardState ¶
func (r *RoyaleRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
func (*RoyaleRuleset) Name ¶
func (r *RoyaleRuleset) Name() string
func (RoyaleRuleset) Settings ¶
func (r RoyaleRuleset) Settings() Settings
type RoyaleSettings ¶
type RoyaleSettings struct { ShrinkEveryNTurns int32 `json:"shrinkEveryNTurns"` // contains filtered or unexported fields }
RoyaleSettings contains settings that are specific to the "royale" game mode
type Ruleset ¶
type Ruleset interface { Name() string ModifyInitialBoardState(initialState *BoardState) (*BoardState, error) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error) IsGameOver(state *BoardState) (bool, error) // Settings provides the game settings that are relevant to the ruleset. Settings() Settings }
type RulesetError ¶
type RulesetError string
func (RulesetError) Error ¶
func (err RulesetError) Error() string
type Settings ¶
type Settings struct { FoodSpawnChance int32 `json:"foodSpawnChance"` MinimumFood int32 `json:"minimumFood"` HazardDamagePerTurn int32 `json:"hazardDamagePerTurn"` HazardMap string `json:"hazardMap"` HazardMapAuthor string `json:"hazardMapAuthor"` RoyaleSettings RoyaleSettings `json:"royale"` SquadSettings SquadSettings `json:"squad"` }
Settings contains all settings relevant to a game. It is used by game logic to take a previous game state and produce a next game state.
type SoloRuleset ¶
type SoloRuleset struct {
StandardRuleset
}
func (*SoloRuleset) IsGameOver ¶
func (r *SoloRuleset) IsGameOver(b *BoardState) (bool, error)
func (*SoloRuleset) Name ¶
func (r *SoloRuleset) Name() string
type SquadRuleset ¶
type SquadRuleset struct { StandardRuleset SquadMap map[string]string // These are intentionally designed so that they default to a standard game. AllowBodyCollisions bool }
func (*SquadRuleset) CreateNextBoardState ¶
func (r *SquadRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
func (*SquadRuleset) IsGameOver ¶
func (r *SquadRuleset) IsGameOver(b *BoardState) (bool, error)
func (*SquadRuleset) Name ¶
func (r *SquadRuleset) Name() string
func (SquadRuleset) Settings ¶
func (r SquadRuleset) Settings() Settings
type SquadSettings ¶
type SquadSettings struct { AllowBodyCollisions bool `json:"allowBodyCollisions"` // contains filtered or unexported fields }
SquadSettings contains settings that are specific to the "squad" game mode
type StageFunc ¶
type StageFunc func(*BoardState, Settings, []SnakeMove) (bool, error)
StageFunc represents a single stage of an ordered pipeline and applies custom logic to the board state each turn. It is expected to modify the boardState directly. The return values are a boolean (to indicate whether the game has ended as a result of the stage) and an error if any errors occurred during the stage.
Errors should be treated as meaning the stage failed and the board state is now invalid.
type StandardRuleset ¶
type StandardRuleset struct { FoodSpawnChance int32 // [0, 100] MinimumFood int32 HazardDamagePerTurn int32 HazardMap string // optional HazardMapAuthor string // optional }
func (*StandardRuleset) CreateNextBoardState ¶
func (r *StandardRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
func (*StandardRuleset) IsGameOver ¶
func (r *StandardRuleset) IsGameOver(b *BoardState) (bool, error)
func (*StandardRuleset) ModifyInitialBoardState ¶
func (r *StandardRuleset) ModifyInitialBoardState(initialState *BoardState) (*BoardState, error)
func (*StandardRuleset) Name ¶
func (r *StandardRuleset) Name() string
func (StandardRuleset) Settings ¶
func (r StandardRuleset) Settings() Settings
type WrappedRuleset ¶
type WrappedRuleset struct {
StandardRuleset
}
func (*WrappedRuleset) CreateNextBoardState ¶
func (r *WrappedRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
func (*WrappedRuleset) Name ¶
func (r *WrappedRuleset) Name() string