DEV 1247: Add a new map generator interface (#71)
* reorganize code * first draft of map generator interfaces * add explicit random interface to board helpers * implement standard map * rename Generator to GameMap * allow initializing snakes separately from placing them * add random number generator to Settings * updates to GameMap interface * add helpers for creating and updating BoardState with maps
This commit is contained in:
parent
1c3f434841
commit
dab9178a55
16 changed files with 916 additions and 160 deletions
14
pipeline.go
14
pipeline.go
|
|
@ -2,9 +2,6 @@ package rules
|
|||
|
||||
import "fmt"
|
||||
|
||||
// StageRegistry is a mapping of stage names to stage functions
|
||||
type StageRegistry map[string]StageFunc
|
||||
|
||||
const (
|
||||
StageSpawnFoodStandard = "spawn_food.standard"
|
||||
StageGameOverStandard = "game_over.standard"
|
||||
|
|
@ -46,6 +43,17 @@ var globalRegistry = StageRegistry{
|
|||
StageModifySnakesShareAttributes: ShareAttributesSquad,
|
||||
}
|
||||
|
||||
// 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 StageFunc func(*BoardState, Settings, []SnakeMove) (bool, error)
|
||||
|
||||
// StageRegistry is a mapping of stage names to stage functions
|
||||
type StageRegistry map[string]StageFunc
|
||||
|
||||
// RegisterPipelineStage adds a stage to the registry.
|
||||
// If a stage has already been mapped it will be overwritten by the newly
|
||||
// registered function.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue