Documentation ¶
Index ¶
- Variables
- type ApiServer
- type CardModification
- type CardOperation
- type CardType
- type Config
- type ConfigGame
- type ConfigPublish
- type ConfigSpecial
- type Engine
- type Event
- type EventCard
- type EventCommand
- type EventConsumer
- type EventModifyCardTime
- type EventModifyValue
- type EventStage
- type EventTrigger
- type GameController
- type GameEventType
- type GameState
- type History
- type HistoryEntry
- type HistoryPreserver
- type MessageWrapper
- type Publisher
- type RefCommand
- type RefereeEvent
- type RefereeEventType
- type Stage
- type StageOperation
- type State
- type Team
- type TeamInfo
- type TriggerType
Constants ¶
This section is empty.
Variables ¶
var Stages = []Stage{ StagePreGame, StageFirstHalf, StageHalfTime, StageSecondHalfPre, StageSecondHalf, StageOvertimeBreak, StageOvertimeFirstHalfPre, StageOvertimeFirstHalf, StageOvertimeHalfTime, StageOvertimeSecondHalfPre, StageOvertimeSecondHalf, StageShootoutBreak, StageShootout, StagePostGame, }
Stages include all available stages, ordered
Functions ¶
This section is empty.
Types ¶
type ApiServer ¶
type ApiServer struct { Consumer EventConsumer // contains filtered or unexported fields }
func (*ApiServer) PublishGameEvents ¶ added in v0.3.0
func (a *ApiServer) PublishGameEvents(events []RefereeEvent)
func (*ApiServer) PublishState ¶
func (*ApiServer) PublishWrapper ¶ added in v0.3.0
func (a *ApiServer) PublishWrapper(wrapper MessageWrapper)
type CardModification ¶
type CardModification struct { CardID int `json:"cardId"` TimeLeft time.Duration `json:"timeLeft"` }
CardModification to apply to a card
type CardOperation ¶
type CardOperation string
CardOperation on a card
const ( // CardOperationAdd add a card CardOperationAdd CardOperation = "add" // CardOperationRevoke revoke a card CardOperationRevoke CardOperation = "revoke" // CardOperationModify modify a card CardOperationModify CardOperation = "modify" )
type Config ¶
type Config struct { Publish ConfigPublish `yaml:"publish"` Game ConfigGame `yaml:"game"` }
Config structure for the game controller
func DefaultConfig ¶
func DefaultConfig() (c Config)
DefaultConfig creates a config with default values
func LoadConfig ¶
LoadConfig loads a config from given file
type ConfigGame ¶
type ConfigGame struct { YellowCardDuration time.Duration `yaml:"yellow-card-duration"` Normal ConfigSpecial `yaml:"normal"` Overtime ConfigSpecial `yaml:"overtime"` }
ConfigGame holds configs that are valid for the whole game
type ConfigPublish ¶
type ConfigPublish struct {
Address string `yaml:"address"`
}
ConfigPublish holds configs for publishing the state and commands to the teams
type ConfigSpecial ¶
type ConfigSpecial struct { HalfDuration time.Duration `yaml:"half-duration"` HalfTimeDuration time.Duration `yaml:"half-time-duration"` TimeoutDuration time.Duration `yaml:"timeout-duration"` Timeouts int `yaml:"timeouts"` BreakAfter time.Duration `yaml:"break-after"` }
ConfigSpecial holds configs that are different between normal and overtime halves
type Engine ¶
type Engine struct { State *State RefereeEvents []RefereeEvent StageTimes map[Stage]time.Duration TimeProvider func() time.Time History History // contains filtered or unexported fields }
func NewEngine ¶
func NewEngine(config ConfigGame) (e Engine)
func (*Engine) LogCommand ¶ added in v0.3.0
func (e *Engine) LogCommand(command *EventCommand)
func (*Engine) LogGameEvent ¶ added in v0.3.0
func (e *Engine) LogGameEvent(eventType GameEventType)
func (*Engine) UndoLastAction ¶
func (e *Engine) UndoLastAction()
UndoLastAction restores the last state from internal history
type Event ¶
type Event struct { Card *EventCard `json:"card"` Command *EventCommand `json:"command"` Modify *EventModifyValue `json:"modify"` Stage *EventStage `json:"stage"` Trigger *EventTrigger `json:"trigger"` }
Event holds all possible events. Only one at a time can be applied
type EventCard ¶
type EventCard struct { ForTeam Team `json:"forTeam"` Type CardType `json:"cardType"` Operation CardOperation `json:"operation"` Modification CardModification `json:"modification"` }
EventCard is an event that can be applied
type EventCommand ¶
type EventCommand struct { ForTeam *Team `json:"forTeam"` Type RefCommand `json:"commandType"` }
EventCommand is an event that can be applied
func (EventCommand) String ¶
func (c EventCommand) String() string
type EventConsumer ¶
type EventConsumer interface {
OnNewEvent(event Event)
}
type EventModifyCardTime ¶
EventModifyCardTime holds the duration for a certain yellow card duration
type EventModifyValue ¶
type EventModifyValue struct { ForTeam Team `json:"forTeam"` Goals *int `json:"goals"` Goalie *int `json:"goalie"` YellowCards *int `json:"yellowCards"` YellowCardTime *EventModifyCardTime `json:"yellowCardTime"` RedCards *int `json:"redCards"` TimeoutsLeft *int `json:"timeoutsLeft"` TimeoutTimeLeft *string `json:"timeoutTimeLeft"` OnPositiveHalf *bool `json:"onPositiveHalf"` TeamName *string `json:"teamName"` BotCollisions *int `json:"botCollisions"` BallPlacementFailures *int `json:"ballPlacementFailures"` BotSpeedInfringements *int `json:"botSpeedInfringements"` }
EventModifyValue is an event that can be applied
func (EventModifyValue) String ¶
func (m EventModifyValue) String() string
type EventStage ¶
type EventStage struct {
StageOperation StageOperation `json:"stageOperation"`
}
EventStage is an event that can be applied
type EventTrigger ¶
type EventTrigger struct {
Type TriggerType `json:"triggerType"`
}
EventTrigger is an event that can be applied
type GameController ¶
type GameController struct { Config Config Publisher Publisher ApiServer ApiServer Engine Engine // contains filtered or unexported fields }
GameController controls a game
func NewGameController ¶
func NewGameController() (r *GameController)
NewGameController creates a new RefBox
func (*GameController) OnNewEvent ¶
func (r *GameController) OnNewEvent(event Event)
func (*GameController) Run ¶
func (r *GameController) Run() (err error)
Run the GameController by starting an endless loop in the background
type GameEventType ¶ added in v0.3.0
type GameEventType string
type GameState ¶
type GameState string
GameState of a game
const ( // GameStateHalted halted GameStateHalted GameState = "Halted" // GameStateStopped stopped GameStateStopped GameState = "Stopped" // GameStateRunning running GameStateRunning GameState = "Running" // GameStatePreKickoff kickoff GameStatePreKickoff GameState = "Prepare Kickoff" // GameStatePrePenalty penalty GameStatePrePenalty GameState = "Prepare Penalty" // GameStateTimeout timeout GameStateTimeout GameState = "Timeout" // GameStateBallPlacement ball placement GameStateBallPlacement GameState = "Ball Placement" )
type History ¶ added in v0.3.0
type History []HistoryEntry
type HistoryEntry ¶ added in v0.3.0
type HistoryEntry struct { State State RefereeEvents []RefereeEvent }
type HistoryPreserver ¶ added in v0.3.0
type HistoryPreserver struct {
// contains filtered or unexported fields
}
func (*HistoryPreserver) Close ¶ added in v0.3.0
func (r *HistoryPreserver) Close()
Close closes the history file
func (*HistoryPreserver) Load ¶ added in v0.3.0
func (r *HistoryPreserver) Load() (*History, error)
Load loads the history from the filesystem
func (*HistoryPreserver) Open ¶ added in v0.3.0
func (r *HistoryPreserver) Open() error
Open opens the history file
func (*HistoryPreserver) Save ¶ added in v0.3.0
func (r *HistoryPreserver) Save(history History)
Save writes the current state into a file
type MessageWrapper ¶ added in v0.3.0
type MessageWrapper struct { State *State `json:"state"` RefereeEvents *[]RefereeEvent `json:"gameEvents"` }
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher can publish state and commands to the teams
func NewPublisher ¶
NewPublisher creates a new publisher that publishes referee messages via UDP to the teams
type RefCommand ¶
type RefCommand string
RefCommand is a command to be send to the teams
const ( // CommandHalt HALT CommandHalt RefCommand = "halt" // CommandStop STOP CommandStop RefCommand = "stop" // CommandNormalStart NORMAL_START CommandNormalStart RefCommand = "normalStart" // CommandForceStart FORCE_START CommandForceStart RefCommand = "forceStart" // CommandDirect DIRECT CommandDirect RefCommand = "direct" // CommandIndirect INDIRECT CommandIndirect RefCommand = "indirect" // CommandKickoff KICKOFF CommandKickoff RefCommand = "kickoff" // CommandPenalty PENALTY CommandPenalty RefCommand = "penalty" // CommandTimeout TIMEOUT CommandTimeout RefCommand = "timeout" // CommandBallPlacement BALL_PLACEMENT CommandBallPlacement RefCommand = "ballPlacement" )
type RefereeEvent ¶ added in v0.3.0
type RefereeEvent struct { Timestamp time.Time `json:"timestamp"` StageTime time.Duration `json:"stageTime"` Type RefereeEventType `json:"type"` GameEventType *GameEventType `json:"gameEventType"` Command *RefCommand `json:"command"` Team *Team `json:"team"` Description *string `json:"description"` }
type RefereeEventType ¶ added in v0.3.0
type RefereeEventType string
const ( RefereeEventCommand RefereeEventType = "command" RefereeEventGameEvent RefereeEventType = "gameEvent" )
type Stage ¶
type Stage string
Stage represents the different stages of a game
const ( // StagePreGame before game has started StagePreGame Stage = "Pre-First Half" // StageFirstHalf in first half StageFirstHalf Stage = "First Half" // StageHalfTime in half time StageHalfTime Stage = "Half Time" // StageSecondHalfPre before second half StageSecondHalfPre Stage = "Pre-Second Half" // StageSecondHalf in second half StageSecondHalf Stage = "Second Half" // StageOvertimeBreak in break to overtime StageOvertimeBreak Stage = "Overtime Break" // StageOvertimeFirstHalfPre before first overtime half StageOvertimeFirstHalfPre Stage = "Pre-Overtime First Half" // StageOvertimeFirstHalf in first overtime half StageOvertimeFirstHalf Stage = "Overtime First Half" // StageOvertimeHalfTime in overtime half time StageOvertimeHalfTime Stage = "Overtime Half Time" // StageOvertimeSecondHalfPre before second overtime half StageOvertimeSecondHalfPre Stage = "Pre-Overtime Second Half" // StageOvertimeSecondHalf in second overtime half StageOvertimeSecondHalf Stage = "Overtime Second Half" // StageShootoutBreak in break to shootout StageShootoutBreak Stage = "Shootout Break" // StageShootout in Shootout StageShootout Stage = "Shootout" // StagePostGame after game ended StagePostGame Stage = "End of Game" )
func (Stage) IsPreStage ¶
type StageOperation ¶
type StageOperation string
StageOperation to apply on the current stage
const ( // StageNext next stage StageNext StageOperation = "next" // StagePrevious previous stage StagePrevious StageOperation = "previous" )
type State ¶
type State struct { Stage Stage `json:"stage"` Command RefCommand `json:"command"` CommandFor *Team `json:"commandForTeam"` StageTimeElapsed time.Duration `json:"stageTimeElapsed"` StageTimeLeft time.Duration `json:"stageTimeLeft"` MatchTimeStart time.Time `json:"matchTimeStart"` MatchDuration time.Duration `json:"matchDuration"` TeamState map[Team]*TeamInfo `json:"teamState"` }
State of the game
type Team ¶
type Team string
Team is one of Yellow or Blue
type TeamInfo ¶
type TeamInfo struct { Name string `json:"name"` Goals int `json:"goals"` Goalie int `json:"goalie"` YellowCards int `json:"yellowCards"` YellowCardTimes []time.Duration `json:"yellowCardTimes"` RedCards int `json:"redCards"` TimeoutsLeft int `json:"timeoutsLeft"` TimeoutTimeLeft time.Duration `json:"timeoutTimeLeft"` OnPositiveHalf bool `json:"onPositiveHalf"` BotCollisions int `json:"botCollisions"` BallPlacementFailures int `json:"ballPlacementFailures"` BotSpeedInfringements int `json:"botSpeedInfringements"` }
TeamInfo about a team
type TriggerType ¶
type TriggerType string
TriggerType is something that can be triggered
const ( // TriggerResetMatch reset match TriggerResetMatch TriggerType = "resetMatch" // TriggerSwitchColor switch color TriggerSwitchColor TriggerType = "switchColor" // TriggerSwitchSides switch sides/goals (onPositiveHalf) TriggerSwitchSides TriggerType = "switchSides" // TriggerUndo undo last action TriggerUndo TriggerType = "undo" )