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 GameState
- type Publisher
- type RefCommand
- 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) PublishState ¶
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
MatchTimeStart time.Time
StageTimes map[Stage]time.Duration
StateHistory []State
// contains filtered or unexported fields
}
func NewEngine ¶
func NewEngine(config ConfigGame) (e Engine)
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"`
}
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 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 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
func (*Publisher) Publish ¶
func (p *Publisher) Publish(state *State, command *EventCommand)
Publish the state and command
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" // CommandGoal GOAL CommandGoal RefCommand = "goal" )
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"`
GameState GameState `json:"gameState"`
GameStateFor *Team `json:"gameStateForTeam"`
StageTimeElapsed time.Duration `json:"gameTimeElapsed"`
StageTimeLeft time.Duration `json:"gameTimeLeft"`
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"`
}
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" )