...

Package base

import "joueur/base"
Overview
Index

Overview ▾

Package base implements the shared logic and structures between all games.

Index ▾

Variables
func InitImplDefaults()
func InjectIntoAI(ai *AIImpl, game Game, player Player)
type AI
type AIImpl
    func (ai AIImpl) Ended(won bool, reason string)
    func (ai *AIImpl) Game() Game
    func (ai AIImpl) GameUpdated()
    func (ai AIImpl) GetSetting(key string) ([]string, bool)
    func (ai AIImpl) Invalid(message string)
    func (ai *AIImpl) Player() Player
    func (ai AIImpl) Start()
type DeltaMerge
type DeltaMergeImpl
    func (deltaMergeImpl *DeltaMergeImpl) BaseGameObject(delta interface{}) GameObject
    func (deltaMergeImpl *DeltaMergeImpl) Boolean(delta interface{}) bool
    func (deltaMergeImpl *DeltaMergeImpl) CannotConvertDeltaTo(strName string, delta interface{})
    func (deltaMergeImpl *DeltaMergeImpl) Float(delta interface{}) float64
    func (deltaMergeImpl *DeltaMergeImpl) Int(delta interface{}) int64
    func (deltaMergeImpl *DeltaMergeImpl) IsDeltaRemoved(delta interface{}) bool
    func (deltaMergeImpl *DeltaMergeImpl) String(delta interface{}) string
    func (deltaMergeImpl *DeltaMergeImpl) ToDeltaArray(delta interface{}) (map[int]interface{}, int)
    func (deltaMergeImpl *DeltaMergeImpl) ToDeltaMap(delta interface{}) map[string]interface{}
type DeltaMergeable
type DeltaMergeableGame
type DeltaMergeableGameObject
type DeltaMergeableImpl
    func (DeltaMergeableImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)
type Game
type GameImpl
    func (gameImpl *GameImpl) AddGameObject(id string, gameObject GameObject) error
    func (gameImpl *GameImpl) GetGameObject(id string) (GameObject, bool)
    func (gameImpl *GameImpl) InitImplDefaults()
type GameNamespace
type GameObject
type GameObjectImpl
    func (gameObjectImpl *GameObjectImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)
    func (gameObjectImpl *GameObjectImpl) GameObjectName() string
    func (gameObjectImpl *GameObjectImpl) ID() string
    func (gameObjectImpl *GameObjectImpl) InitImplDefaults()
    func (gameObjectImpl *GameObjectImpl) RunOnServer(functionName string, args map[string]interface{}) interface{}
    func (gameObjectImpl *GameObjectImpl) String() string
type Player

Package files

base_ai.go base_delta_mergeable.go base_game.go base_game_object.go base_player.go delta_merge.go game_namespace.go

Variables

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

func InitImplDefaults()

InitImplDefaults should initialize any defaults for delta mergable fields.

func InjectIntoAI

func InjectIntoAI(ai *AIImpl, game Game, player Player)

InjectIntoAI injects into an AI its "private" player and game

type AI

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)
}

type AIImpl

AIImpl is the implimentation struct for the AI interface

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

func (AIImpl) Ended

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 (*AIImpl) Game

func (ai *AIImpl) Game() Game

Game returns the game this [base] AI is in

func (AIImpl) GameUpdated

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 (AIImpl) GetSetting

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 (AIImpl) Invalid

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 (*AIImpl) Player

func (ai *AIImpl) Player() Player

Player returns the game this [base] AI is in

func (AIImpl) Start

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.

type DeltaMerge

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
}

type DeltaMergeImpl

DeltaMergeImpl is the base logic for primitive merging

type DeltaMergeImpl struct {
    Game              Game
    DeltaRemovedValue string
    DeltaLengthKey    string
}

func (*DeltaMergeImpl) BaseGameObject

func (deltaMergeImpl *DeltaMergeImpl) BaseGameObject(delta interface{}) GameObject

BaseGameObject attempts to extract a base.GameObject from a generic delta.

func (*DeltaMergeImpl) Boolean

func (deltaMergeImpl *DeltaMergeImpl) Boolean(delta interface{}) bool

Boolean attempts to extract a boolean from a generic delta.

func (*DeltaMergeImpl) CannotConvertDeltaTo

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) Float

func (deltaMergeImpl *DeltaMergeImpl) Float(delta interface{}) float64

Float attempts to extract a float from a generic delta.

func (*DeltaMergeImpl) Int

func (deltaMergeImpl *DeltaMergeImpl) Int(delta interface{}) int64

Int attempts to extract an int from a generic delta.

func (*DeltaMergeImpl) IsDeltaRemoved

func (deltaMergeImpl *DeltaMergeImpl) IsDeltaRemoved(delta interface{}) bool

IsDeltaRemoved checks if a given delta is the special DeltaRemoved token.

func (*DeltaMergeImpl) String

func (deltaMergeImpl *DeltaMergeImpl) String(delta interface{}) string

String attempts to extract a string from a generic delta.

func (*DeltaMergeImpl) ToDeltaArray

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) ToDeltaMap

func (deltaMergeImpl *DeltaMergeImpl) ToDeltaMap(delta interface{}) map[string]interface{}

ToDeltaMap attempts to extract a map of string to more generics from a generic delta.

type DeltaMergeable

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()
}

type DeltaMergeableGame

DeltaMergeableGame is a Game that is also DeltaMergeable

type DeltaMergeableGame interface {
    DeltaMergeable
    Game

    AddGameObject(string, GameObject) error
}

type DeltaMergeableGameObject

DeltaMergeableGameObject is a GameObject that is also DeltaMergeable

type DeltaMergeableGameObject interface {
    DeltaMergeable
    GameObject
}

type DeltaMergeableImpl

DeltaMergeableImpl is the implimentation of a struct that can be delta merged

type DeltaMergeableImpl struct{}

func (DeltaMergeableImpl) DeltaMerge

func (DeltaMergeableImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)

DeltaMerge will merge the given delta into itself

type Game

Game is the base interface all games should implement for their Game interfaces.

type Game interface {
    GetGameObject(string) (GameObject, bool)
}

type GameImpl

GameImpl is the implimentation struct for the Game interface.

type GameImpl struct {
    DeltaMergeableImpl
    // contains filtered or unexported fields
}

func (*GameImpl) AddGameObject

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) GetGameObject

func (gameImpl *GameImpl) GetGameObject(id string) (GameObject, bool)

GetGameObject simply attempts to get a game object from inside its gameObjects map.

func (*GameImpl) InitImplDefaults

func (gameImpl *GameImpl) InitImplDefaults()

InitImplDefaults initializes safe defaults for all fields in Game.

type GameNamespace

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)
}

type GameObject

GameObject is the base interface all GameObjects in all games should implement

type GameObject interface {
    GameObjectName() string
    ID() string
}

type GameObjectImpl

GameObjectImpl is the implimentation struct for BaseGameObject

type GameObjectImpl struct {
    DeltaMergeableImpl
    // contains filtered or unexported fields
}

func (*GameObjectImpl) DeltaMerge

func (gameObjectImpl *GameObjectImpl) DeltaMerge(deltaMerge DeltaMerge, attribute string, delta interface{}) (bool, error)

DeltaMerge merges the delta for a given attribute in GameObject.

func (*GameObjectImpl) GameObjectName

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) ID

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) InitImplDefaults

func (gameObjectImpl *GameObjectImpl) InitImplDefaults()

InitImplDefaults initializes safe defaults for all fields in GameObject.

func (*GameObjectImpl) RunOnServer

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) String

func (gameObjectImpl *GameObjectImpl) String() string

String returns the string friendly representation of this game object

type Player

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
}