AISettings is kind of hacky; basically exposing a global for all AI structs, however only 1 AI should ever be constructed per game so should be an ok assumption
var AISettings map[string]([]string)
RunOnServerCallback is the callback function for the game manager to hook into so RunOnServer works once the client is connected
var RunOnServerCallback func(GameObject, string, map[string]interface{}) interface{}
func InitImplDefaults()
InitImplDefaults should initialize any defaults for delta mergable fields.
func InjectIntoAI(ai *AIImpl, game Game, player Player)
InjectIntoAI injects into an AI its "private" player and game
AI is the base interface all game AIs should implement to correctly interface and play their game.
type AI interface { Start() Ended(bool, string) GameUpdated() Invalid(string) }
AIImpl is the implimentation struct for the AI interface
type AIImpl struct {
// contains filtered or unexported fields
}
func (ai AIImpl) Ended(won bool, reason string)
Ended is called when the game ends. You can clean up your data and dump files here if need be.
func (ai *AIImpl) Game() Game
Game returns the game this [base] AI is in
func (ai AIImpl) GameUpdated()
GameUpdated is called every time the game's state updates, so if you are tracking anything you can update it here.
func (ai AIImpl) GetSetting(key string) ([]string, bool)
GetSetting gets an AI setting passed to the program via the --aiSettings flag. If the flag was set it will be returned as a string value, undefined otherwise.
func (ai AIImpl) Invalid(message string)
Invalid is automatically called after this AI sends some run that is has arguments that are invalidated for some reason.
func (ai *AIImpl) Player() Player
Player returns the game this [base] AI is in
func (ai AIImpl) Start()
Start is called once the game starts and your AI knows its Player and Game. You can initialize your AI here.
DeltaMerge is a container of functions to facilitate type safe delta merging
type DeltaMerge interface { CannotConvertDeltaTo(string, interface{}) String(interface{}) string Int(interface{}) int64 Float(interface{}) float64 Boolean(interface{}) bool BaseGameObject(interface{}) GameObject ToDeltaMap(interface{}) map[string]interface{} ToDeltaArray(interface{}) (map[int]interface{}, int) IsDeltaRemoved(interface{}) bool }
DeltaMergeImpl is the base logic for primitive merging
type DeltaMergeImpl struct { Game Game DeltaRemovedValue string DeltaLengthKey string }
func (deltaMergeImpl *DeltaMergeImpl) BaseGameObject(delta interface{}) GameObject
BaseGameObject attempts to extract a base.GameObject from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) Boolean(delta interface{}) bool
Boolean attempts to extract a boolean from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) CannotConvertDeltaTo(strName string, delta interface{})
CannotConvertDeltaTo takes a string about why and a delta to explain why it's going to crash the program because a delta could not be merged.
func (deltaMergeImpl *DeltaMergeImpl) Float(delta interface{}) float64
Float attempts to extract a float from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) Int(delta interface{}) int64
Int attempts to extract an int from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) IsDeltaRemoved(delta interface{}) bool
IsDeltaRemoved checks if a given delta is the special DeltaRemoved token.
func (deltaMergeImpl *DeltaMergeImpl) String(delta interface{}) string
String attempts to extract a string from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) ToDeltaArray(delta interface{}) (map[int]interface{}, int)
ToDeltaArray attempts to extract a data for merging a list delta from a generic delta.
func (deltaMergeImpl *DeltaMergeImpl) ToDeltaMap(delta interface{}) map[string]interface{}
ToDeltaMap attempts to extract a map of string to more generics from a generic delta.
DeltaMergeable is an interface to something in the game that will receive and merge delta states
type DeltaMergeable interface { DeltaMerge(DeltaMerge, string, interface{}) (bool, error) InitImplDefaults() }
DeltaMergeableGame is a Game that is also DeltaMergeable
type DeltaMergeableGame interface { DeltaMergeable Game AddGameObject(string, GameObject) error }
DeltaMergeableGameObject is a GameObject that is also DeltaMergeable
type DeltaMergeableGameObject interface { DeltaMergeable GameObject }
DeltaMergeableImpl is the implimentation of a struct that can be delta merged
type DeltaMergeableImpl struct{}
func (DeltaMergeableImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)
DeltaMerge will merge the given delta into itself
Game is the base interface all games should implement for their Game interfaces.
type Game interface { GetGameObject(string) (GameObject, bool) }
GameImpl is the implimentation struct for the Game interface.
type GameImpl struct { DeltaMergeableImpl // contains filtered or unexported fields }
func (gameImpl *GameImpl) AddGameObject(id string, gameObject GameObject) error
AddGameObject adds a new gae object to the game. However if the GameObject is already present it returns an error.
func (gameImpl *GameImpl) GetGameObject(id string) (GameObject, bool)
GetGameObject simply attempts to get a game object from inside its gameObjects map.
func (gameImpl *GameImpl) InitImplDefaults()
InitImplDefaults initializes safe defaults for all fields in Game.
GameNamespace is the base interface all games must implement to be able to play via our soft reflection
type GameNamespace interface { Name() string Version() string PlayerName() string CreateAI() (AI, *AIImpl) CreateDeltaMerge(*DeltaMergeImpl) DeltaMerge CreateGame() DeltaMergeableGame CreateGameObject(string) (DeltaMergeableGameObject, error) OrderAI(AI, string, []interface{}) (interface{}, error) }
GameObject is the base interface all GameObjects in all games should implement
type GameObject interface { GameObjectName() string ID() string }
GameObjectImpl is the implimentation struct for BaseGameObject
type GameObjectImpl struct { DeltaMergeableImpl // contains filtered or unexported fields }
func (gameObjectImpl *GameObjectImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)
DeltaMerge merges the delta for a given attribute in GameObject.
func (gameObjectImpl *GameObjectImpl) GameObjectName() string
GameObjectName returns string representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.
func (gameObjectImpl *GameObjectImpl) ID() string
ID returns a unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.
func (gameObjectImpl *GameObjectImpl) InitImplDefaults()
InitImplDefaults initializes safe defaults for all fields in GameObject.
func (gameObjectImpl *GameObjectImpl) RunOnServer(functionName string, args map[string]interface{}) interface{}
RunOnServer is a slim wrapper that attempts to run game logic on behalf of this gameObject on the server.
func (gameObjectImpl *GameObjectImpl) String() string
String returns the string friendly representation of this game object
Player is the base interface all Player GameObjects within the game must implement.
type Player interface { GameObject /** If the player won the game or not. */ Won() bool /** If the player lost the game or not. */ Lost() bool /** The reason why the player won the game. */ ReasonWon() string /** The reason why the player lost the game. */ ReasonLost() string }