controller

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2019 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

GameEventBehaviors contain all known command enum constants

GameStates contain all known command enum constants

GameStates contain all known command enum constants

Commands contain all known command enum constants

Stages include all available stages, ordered

Teams contain all known team enum constants

Functions

This section is empty.

Types

type ApiServer

type ApiServer struct {
	Consumer EventConsumer
	// contains filtered or unexported fields
}

func (*ApiServer) PublishState

func (a *ApiServer) PublishState(state State, engineState EngineState)

func (*ApiServer) PublishUiProtocol added in v0.16.0

func (a *ApiServer) PublishUiProtocol(protocol []UiProtocolEntry)

func (*ApiServer) PublishWrapper added in v0.3.0

func (a *ApiServer) PublishWrapper(wrapper MessageWrapper)

func (*ApiServer) WsHandler

func (a *ApiServer) WsHandler(w http.ResponseWriter, r *http.Request)

WsHandler handles incoming web socket connections

type CardModification

type CardModification struct {
	CardID   int           `json:"cardId" yaml:"cardId"`
	TimeLeft time.Duration `json:"timeLeft" yaml:"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 CardType

type CardType string

CardType is one of yellow or red

const (
	// CardTypeYellow yellow card
	CardTypeYellow CardType = "yellow"
	// CardTypeRed red card
	CardTypeRed CardType = "red"
)

type Engine

type Engine struct {
	State       *State
	UiProtocol  []UiProtocolEntry
	EngineState EngineState
	StageTimes  map[Stage]time.Duration

	TimeProvider   timer.TimeProvider
	LastTimeUpdate time.Time
	History        History
	Geometry       config.Geometry
	Rand           *rand.Rand
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(config config.Game, seed int64) (e Engine)

func (*Engine) AddGameEvent added in v0.8.0

func (e *Engine) AddGameEvent(gameEvent GameEvent)

func (*Engine) BallPlacementPos added in v0.8.0

func (e *Engine) BallPlacementPos() *Location

BallPlacementPos determines the ball placement position based on the primary game event

func (*Engine) CardNumberIncremented added in v0.9.0

func (e *Engine) CardNumberIncremented(team Team) *GameEvent

func (*Engine) CommandForEvent added in v0.9.0

func (e *Engine) CommandForEvent(event *GameEvent) (command RefCommand, forTeam Team, err error)

func (*Engine) Continue added in v0.4.0

func (e *Engine) Continue()

func (*Engine) FoulCounterIncremented added in v0.9.0

func (e *Engine) FoulCounterIncremented(team Team) *GameEvent

func (*Engine) LogCard added in v0.6.0

func (e *Engine) LogCard(card *EventCard)

LogCard adds a card to the protocol

func (*Engine) LogCommand added in v0.3.0

func (e *Engine) LogCommand()

LogCommand adds a command to the protocol

func (*Engine) LogGameEvent added in v0.3.0

func (e *Engine) LogGameEvent(event GameEvent)

LogGameEvent adds a game event to the protocol

func (*Engine) LogHint added in v0.28.0

func (e *Engine) LogHint(hint string, description string, team Team)

LogHint adds a hint for the game-controller operator to the protocol

func (*Engine) LogIgnoredGameEvent added in v0.10.0

func (e *Engine) LogIgnoredGameEvent(event GameEvent)

LogIgnoredGameEvent adds an ignored game event to the protocol

func (*Engine) LogModify added in v0.9.0

func (e *Engine) LogModify(m EventModifyValue)

LogModify adds a modification to the protocol

func (*Engine) LogStage added in v0.6.0

func (e *Engine) LogStage(stage Stage)

LogStage adds a stage change to the protocol

func (*Engine) LogTeamBotSubstitutionChange added in v0.17.0

func (e *Engine) LogTeamBotSubstitutionChange(forTeam Team, substituteBot bool)

LogTeamBotSubstitutionChange adds a bot substitution intend change from a team to the protocol

func (*Engine) LogTeamGoalkeeperChange added in v0.17.0

func (e *Engine) LogTeamGoalkeeperChange(forTeam Team, oldGoalkeeperId int, newGoalkeeperId int)

LogTeamGoalkeeperChange adds a goalkeeper change from a team to the protocol

func (*Engine) LogTime added in v0.6.0

func (e *Engine) LogTime(description string, forTeam Team)

LogTime adds a time event (like stage time ends or card time ends) to the protocol

func (*Engine) PlacementFailuresIncremented added in v0.9.0

func (e *Engine) PlacementFailuresIncremented(team Team) *GameEvent

func (*Engine) Process

func (e *Engine) Process(event Event) error

func (*Engine) ResetGame

func (e *Engine) ResetGame()

func (*Engine) SendCommand added in v0.4.0

func (e *Engine) SendCommand(command RefCommand, forTeam Team)

func (*Engine) UndoLastAction

func (e *Engine) UndoLastAction()

UndoLastAction restores the last state from internal history

func (*Engine) Update added in v0.25.0

func (e *Engine) Update() (newFullSecond bool, eventTriggered bool)

Update updates times and triggers events if needed

type EngineState added in v0.23.0

type EngineState struct {
	AutoRefsConnected      []string      `json:"autoRefsConnected" yaml:"autoRefsConnected"`
	TeamConnected          map[Team]bool `json:"teamConnected" yaml:"teamConnected"`
	TeamConnectionVerified map[Team]bool `json:"teamConnectionVerified" yaml:"teamConnectionVerified"`
}

func NewEngineState added in v0.23.0

func NewEngineState() (e EngineState)

type Event

type Event struct {
	Card      *EventCard        `json:"card" yaml:"card"`
	Command   *EventCommand     `json:"command" yaml:"command"`
	Modify    *EventModifyValue `json:"modify" yaml:"modify"`
	Stage     *EventStage       `json:"stage" yaml:"stage"`
	Trigger   *EventTrigger     `json:"trigger" yaml:"trigger"`
	GameEvent *GameEvent        `json:"gameEvent" yaml:"gameEvent"`
}

Event holds all possible events. Only one at a time can be applied

func (Event) String

func (e Event) String() string

type EventCard

type EventCard struct {
	ForTeam      Team             `json:"forTeam" yaml:"forTeam"`
	Type         CardType         `json:"cardType" yaml:"type"`
	Operation    CardOperation    `json:"operation" yaml:"operation"`
	Modification CardModification `json:"modification" yaml:"modification"`
}

EventCard is an event that can be applied

type EventCommand

type EventCommand struct {
	ForTeam  *Team      `json:"forTeam" yaml:"forTeam"`
	Type     RefCommand `json:"commandType" yaml:"type"`
	Location *Location  `json:"location" yaml:"location"`
}

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

type EventModifyCardTime struct {
	CardID   int    `json:"cardId" yaml:"cardId"`
	Duration string `json:"duration" yaml:"duration"`
}

EventModifyCardTime holds the duration for a certain yellow card duration

type EventModifyGameEventBehavior added in v0.10.0

type EventModifyGameEventBehavior struct {
	GameEventType     GameEventType     `json:"gameEventType" yaml:"gameEventType"`
	GameEventBehavior GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
}

EventModifyGameEventBehavior holds the type to behavior mapping

type EventModifyValue

type EventModifyValue struct {
	ForTeam Team `json:"forTeam,omitempty"`

	Goals                 *int                          `json:"goals,omitempty" yaml:"goals"`
	Goalkeeper            *int                          `json:"goalkeeper,omitempty" yaml:"goalkeeper"`
	YellowCards           *int                          `json:"yellowCards,omitempty" yaml:"yellowCards"`
	YellowCardTime        *EventModifyCardTime          `json:"yellowCardTime,omitempty" yaml:"yellowCardTime"`
	RedCards              *int                          `json:"redCards,omitempty" yaml:"redCards"`
	TimeoutsLeft          *int                          `json:"timeoutsLeft,omitempty" yaml:"timeoutsLeft"`
	TimeoutTimeLeft       *string                       `json:"timeoutTimeLeft,omitempty" yaml:"timeoutTimeLeft"`
	OnPositiveHalf        *bool                         `json:"onPositiveHalf,omitempty" yaml:"onPositiveHalf"`
	TeamName              *string                       `json:"teamName,omitempty" yaml:"teamName"`
	FoulCounter           *int                          `json:"foulCounter,omitempty" yaml:"foulCounter"`
	BallPlacementFailures *int                          `json:"ballPlacementFailures,omitempty" yaml:"ballPlacementFailures"`
	CanPlaceBall          *bool                         `json:"canPlaceBall,omitempty" yaml:"canPlaceBall"`
	Division              *config.Division              `json:"division,omitempty" yaml:"division"`
	AutoContinue          *bool                         `json:"autoContinue,omitempty" yaml:"autoContinue"`
	GameEventBehavior     *EventModifyGameEventBehavior `json:"gameEventBehavior,omitempty" yaml:"gameEventBehavior"`
	BotSubstitutionIntend *bool                         `json:"botSubstitutionIntend,omitempty" yaml:"botSubstitutionIntend"`
	RemoveGameEvent       *int                          `json:"removeGameEvent,omitempty" yaml:"removeGameEvent"`
}

EventModifyValue is an event that can be applied

func (EventModifyValue) String

func (m EventModifyValue) String() string

func (EventModifyValue) Type added in v0.11.1

func (m EventModifyValue) Type() string

func (EventModifyValue) Value added in v0.11.1

func (m EventModifyValue) Value() string

type EventStage

type EventStage struct {
	StageOperation StageOperation `json:"stageOperation" yaml:"stageOperation"`
}

EventStage is an event that can be applied

type EventTrigger

type EventTrigger struct {
	Type TriggerType `json:"triggerType" yaml:"type"`
}

EventTrigger is an event that can be applied

type GameController

type GameController struct {
	Config        config.Controller
	Publisher     Publisher
	ApiServer     ApiServer
	AutoRefServer *rcon.AutoRefServer
	TeamServer    *rcon.TeamServer
	CiServer      rcon.CiServer
	Engine        Engine

	ConnectionMutex sync.Mutex
	PublishMutex    sync.Mutex
	StateMutex      sync.Mutex
	VisionReceiver  *vision.Receiver
	// contains filtered or unexported fields
}

GameController controls a game

func NewGameController

func NewGameController() (c *GameController)

NewGameController creates a new RefBox

func (*GameController) OnNewEvent

func (c *GameController) OnNewEvent(event Event)

OnNewEvent processes the given event

func (*GameController) ProcessAutoRefRequests added in v0.8.0

func (c *GameController) ProcessAutoRefRequests(id string, request refproto.AutoRefToController) error

func (*GameController) ProcessGeometry added in v0.9.0

func (c *GameController) ProcessGeometry(data *sslproto.SSL_GeometryData)

func (*GameController) ProcessTeamRequests added in v0.8.0

func (c *GameController) ProcessTeamRequests(teamName string, request refproto.TeamToController) error

func (*GameController) Run

func (c *GameController) Run()

Run the GameController by starting several go-routines. This method will not block.

type GameEvent added in v0.8.0

type GameEvent struct {
	Type    GameEventType    `json:"type"`
	Details GameEventDetails `json:"details"`
	Origins []string         `json:"origins"`
	// contains filtered or unexported fields
}

GameEvent combines the type of a game event with the corresponding detail structures

func (GameEvent) AddsRedCard added in v0.8.0

func (e GameEvent) AddsRedCard() bool

AddsRedCard checks if this game event causes a red card

func (GameEvent) AddsYellowCard added in v0.8.0

func (e GameEvent) AddsYellowCard() bool

AddsYellowCard checks if this game event causes a yellow card

func (GameEvent) ByTeam added in v0.8.0

func (e GameEvent) ByTeam() Team

ByTeam extracts the `ByTeam` attribute from the game event details

func (GameEvent) IncrementsFoulCounter added in v0.8.0

func (e GameEvent) IncrementsFoulCounter() bool

IncrementsFoulCounter checks if the game event increments the foul counter

func (GameEvent) IsContinueGame added in v0.9.0

func (e GameEvent) IsContinueGame() bool

IsContinueGame checks if the game event should trigger continuing the game based on the current primary event

func (GameEvent) IsSecondary added in v0.8.0

func (e GameEvent) IsSecondary() bool

IsSecondary checks if this game event is a secondary one that does not influence the next referee command

func (GameEvent) IsSkipped added in v0.11.0

func (e GameEvent) IsSkipped() bool

IsSkipped checks if the game event is a skipped one (one for which the game was not stopped based on the decision of a team)

func (GameEvent) Occurred added in v0.30.0

func (e GameEvent) Occurred() time.Time

func (*GameEvent) SetOccurred added in v0.30.0

func (e *GameEvent) SetOccurred(occurred time.Time)

func (GameEvent) String added in v0.9.0

func (e GameEvent) String() string

String converts the game event into a string

func (GameEvent) ToProto added in v0.8.0

func (e GameEvent) ToProto() *refproto.GameEvent

ToProto converts the internal game event into a protobuf game event

type GameEventBehavior added in v0.10.0

type GameEventBehavior string
const (
	GameEventBehaviorOn       GameEventBehavior = "on"
	GameEventBehaviorMajority GameEventBehavior = "majority"
	GameEventBehaviorOff      GameEventBehavior = "off"
)

func (GameEventBehavior) Valid added in v0.19.0

func (b GameEventBehavior) Valid() bool

Valid checks if the GameEventBehavior enum value is among the known values

type GameEventDetails added in v0.8.0

type GameEventDetails struct {
	BallLeftFieldTouchLine         *refproto.GameEvent_BallLeftField                  `json:"ballLeftFieldTouchLine,omitempty"`
	BallLeftFieldGoalLine          *refproto.GameEvent_BallLeftField                  `json:"ballLeftFieldGoalLine,omitempty"`
	AimlessKick                    *refproto.GameEvent_AimlessKick                    `json:"aimlessKick,omitempty"`
	PossibleGoal                   *refproto.GameEvent_Goal                           `json:"possibleGoal,omitempty"`
	Goal                           *refproto.GameEvent_Goal                           `json:"goal,omitempty"`
	IndirectGoal                   *refproto.GameEvent_IndirectGoal                   `json:"indirectGoal,omitempty"`
	ChippedGoal                    *refproto.GameEvent_ChippedGoal                    `json:"chippedGoal,omitempty"`
	BotTooFastInStop               *refproto.GameEvent_BotTooFastInStop               `json:"botTooFastInStop,omitempty"`
	BotTippedOver                  *refproto.GameEvent_BotTippedOver                  `json:"botTippedOver,omitempty"`
	BotInterferedPlacement         *refproto.GameEvent_BotInterferedPlacement         `json:"botInterferedPlacement,omitempty"`
	BotCrashDrawn                  *refproto.GameEvent_BotCrashDrawn                  `json:"botCrashDrawn,omitempty"`
	BotKickedBallTooFast           *refproto.GameEvent_BotKickedBallTooFast           `json:"botKickedBallTooFast,omitempty"`
	BotDribbledBallTooFar          *refproto.GameEvent_BotDribbledBallTooFar          `json:"botDribbledBallTooFar,omitempty"`
	BotCrashUnique                 *refproto.GameEvent_BotCrashUnique                 `json:"botCrashUnique,omitempty"`
	BotCrashUniqueSkipped          *refproto.GameEvent_BotCrashUnique                 `json:"botCrashUniqueSkipped,omitempty"`
	BotPushedBot                   *refproto.GameEvent_BotPushedBot                   `json:"botPushedBot,omitempty"`
	BotPushedBotSkipped            *refproto.GameEvent_BotPushedBot                   `json:"botPushedBotSkipped,omitempty"`
	BotHeldBallDeliberately        *refproto.GameEvent_BotHeldBallDeliberately        `json:"botHeldBallDeliberately,omitempty"`
	AttackerDoubleTouchedBall      *refproto.GameEvent_AttackerDoubleTouchedBall      `json:"attackerDoubleTouchedBall,omitempty"`
	AttackerTooCloseToDefenseArea  *refproto.GameEvent_AttackerTooCloseToDefenseArea  `json:"attackerTooCloseToDefenseArea,omitempty"`
	AttackerInDefenseArea          *refproto.GameEvent_AttackerInDefenseArea          `json:"attackerInDefenseArea,omitempty"`
	AttackerTouchedKeeper          *refproto.GameEvent_AttackerTouchedKeeper          `json:"attackerTouchedKeeper,omitempty"`
	DefenderTooCloseToKickPoint    *refproto.GameEvent_DefenderTooCloseToKickPoint    `json:"defenderTooCloseToKickPoint,omitempty"`
	DefenderInDefenseAreaPartially *refproto.GameEvent_DefenderInDefenseAreaPartially `json:"defenderInDefenseAreaPartially,omitempty"`
	DefenderInDefenseArea          *refproto.GameEvent_DefenderInDefenseArea          `json:"defenderInDefenseArea,omitempty"`
	KeeperHeldBall                 *refproto.GameEvent_KeeperHeldBall                 `json:"keeperHeldBall,omitempty"`
	UnsportingBehaviorMinor        *refproto.GameEvent_UnsportingBehaviorMinor        `json:"unsportingBehaviorMinor,omitempty"`
	UnsportingBehaviorMajor        *refproto.GameEvent_UnsportingBehaviorMajor        `json:"unsportingBehaviorMajor,omitempty"`
	MultipleCards                  *refproto.GameEvent_MultipleCards                  `json:"multipleCards,omitempty"`
	MultipleFouls                  *refproto.GameEvent_MultipleFouls                  `json:"multipleFouls,omitempty"`
	MultiplePlacementFailures      *refproto.GameEvent_MultiplePlacementFailures      `json:"multiplePlacementFailures,omitempty"`
	KickTimeout                    *refproto.GameEvent_KickTimeout                    `json:"kickTimeout,omitempty"`
	NoProgressInGame               *refproto.GameEvent_NoProgressInGame               `json:"noProgressInGame,omitempty"`
	PlacementFailed                *refproto.GameEvent_PlacementFailed                `json:"placementFailed,omitempty"`
	PlacementSucceeded             *refproto.GameEvent_PlacementSucceeded             `json:"placementSucceeded,omitempty"`
	Prepared                       *refproto.GameEvent_Prepared                       `json:"prepared,omitempty"`
	BotSubstitution                *refproto.GameEvent_BotSubstitution                `json:"botSubstitution,omitempty"`
	TooManyRobots                  *refproto.GameEvent_TooManyRobots                  `json:"tooManyRobots,omitempty"`
}

GameEventDetails holds details of a game event. Only one field should be non-nil

func GameEventDetailsFromProto added in v0.16.0

func GameEventDetailsFromProto(event refproto.GameEvent) (d GameEventDetails)

GameEventDetailsFromProto converts a protobuf game event into internal details

func (GameEventDetails) EventType added in v0.8.0

func (d GameEventDetails) EventType() GameEventType

EventType returns the internal game event type of game event details

func (GameEventDetails) String added in v0.16.0

func (d GameEventDetails) String() string

String converts the game event details to a string

type GameEventProposal added in v0.10.0

type GameEventProposal struct {
	ProposerId string    `json:"proposerId"`
	GameEvent  GameEvent `json:"gameEvent"`
	ValidUntil time.Time `json:"validUntil"`
}

GameEventProposal holds a proposal for a game event from an autoRef

type GameEventType added in v0.3.0

type GameEventType string
const (
	GameEventNone GameEventType = ""

	GameEventPrepared           GameEventType = "prepared"
	GameEventNoProgressInGame   GameEventType = "noProgressInGame"
	GameEventPlacementFailed    GameEventType = "placementFailed"
	GameEventPlacementSucceeded GameEventType = "placementSucceeded"
	GameEventBotSubstitution    GameEventType = "botSubstitution"
	GameEventTooManyRobots      GameEventType = "tooManyRobots"

	GameEventBallLeftFieldTouchLine GameEventType = "ballLeftFieldTouchLine"
	GameEventBallLeftFieldGoalLine  GameEventType = "ballLeftFieldGoalLine"
	GameEventPossibleGoal           GameEventType = "possibleGoal"
	GameEventGoal                   GameEventType = "goal"
	GameEventIndirectGoal           GameEventType = "indirectGoal"
	GameEventChippedGoal            GameEventType = "chippedGoal"

	GameEventAimlessKick               GameEventType = "aimlessKick"
	GameEventKickTimeout               GameEventType = "kickTimeout"
	GameEventKeeperHeldBall            GameEventType = "keeperHeldBall"
	GameEventAttackerDoubleTouchedBall GameEventType = "attackerDoubleTouchedBall"
	GameEventAttackerInDefenseArea     GameEventType = "attackerInDefenseArea"
	GameEventAttackerTouchedKeeper     GameEventType = "attackerTouchedKeeper"
	GameEventBotDribbledBallTooFar     GameEventType = "botDribbledBallTooFar"
	GameEventBotKickedBallTooFast      GameEventType = "botKickedBallTooFast"

	GameEventAttackerTooCloseToDefenseArea  GameEventType = "attackerTooCloseToDefenseArea"
	GameEventBotInterferedPlacement         GameEventType = "botInterferedPlacement"
	GameEventBotCrashDrawn                  GameEventType = "botCrashDrawn"
	GameEventBotCrashUnique                 GameEventType = "botCrashUnique"
	GameEventBotCrashUniqueSkipped          GameEventType = "botCrashUniqueSkipped"
	GameEventBotPushedBot                   GameEventType = "botPushedBot"
	GameEventBotPushedBotSkipped            GameEventType = "botPushedBotSkipped"
	GameEventBotHeldBallDeliberately        GameEventType = "botHeldBallDeliberately"
	GameEventBotTippedOver                  GameEventType = "botTippedOver"
	GameEventBotTooFastInStop               GameEventType = "botTooFastInStop"
	GameEventDefenderTooCloseToKickPoint    GameEventType = "defenderTooCloseToKickPoint"
	GameEventDefenderInDefenseAreaPartially GameEventType = "defenderInDefenseAreaPartially"
	GameEventDefenderInDefenseArea          GameEventType = "defenderInDefenseArea"

	GameEventMultipleCards             GameEventType = "multipleCards"
	GameEventMultiplePlacementFailures GameEventType = "multiplePlacementFailures"
	GameEventMultipleFouls             GameEventType = "multipleFouls"

	GameEventUnsportingBehaviorMinor GameEventType = "unsportingBehaviorMinor"
	GameEventUnsportingBehaviorMajor GameEventType = "unsportingBehaviorMajor"
)

func AllGameEvents added in v0.10.0

func AllGameEvents() []GameEventType

AllGameEvents returns a list of all known game events

func (GameEventType) Valid added in v0.19.0

func (g GameEventType) Valid() bool

Valid checks if the GameEventType enum value is among the known values

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

func (GameState) Valid added in v0.19.0

func (g GameState) Valid() bool

Valid checks if the GameState enum value is among the known values

type History added in v0.3.0

type History []HistoryEntry

type HistoryEntry added in v0.3.0

type HistoryEntry struct {
	State      State
	UiProtocol []UiProtocolEntry
}

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) CloseOnExit added in v0.26.0

func (r *HistoryPreserver) CloseOnExit()

CloseOnExit makes sure to close the file when program exists

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 Location added in v0.8.0

type Location struct {
	X float64 `json:"x" yaml:"x"`
	Y float64 `json:"y" yaml:"y"`
}

Location is a two-dimensional coordinate

func (Location) String added in v0.17.0

func (l Location) String() string

type MessageWrapper added in v0.3.0

type MessageWrapper struct {
	State       *State             `json:"state"`
	UiProtocol  *[]UiProtocolEntry `json:"gameEvents"`
	EngineState *EngineState       `json:"engineState"`
}

type Publisher

type Publisher struct {
	Message RefMessage
	// contains filtered or unexported fields
}

Publisher can publish state and commands to the teams

func NewPublisher

func NewPublisher(address string) (publisher Publisher)

NewPublisher creates a new publisher that publishes referee messages via UDP to the teams

func (*Publisher) Publish

func (p *Publisher) Publish(state *State)

Publish the state and command

type RefCommand

type RefCommand string

RefCommand is a command to be send to the teams

const (
	// CommandUnknown not set
	CommandUnknown RefCommand = ""
	// 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"
)

func (RefCommand) ContinuesGame added in v0.9.0

func (c RefCommand) ContinuesGame() bool

func (RefCommand) IsFreeKick added in v0.19.0

func (c RefCommand) IsFreeKick() bool

func (RefCommand) IsPrepare added in v0.30.0

func (c RefCommand) IsPrepare() bool

func (RefCommand) NeedsTeam added in v0.19.0

func (c RefCommand) NeedsTeam() bool

func (RefCommand) Valid added in v0.19.0

func (c RefCommand) Valid() bool

Valid checks if the RefCommand enum value is among the known values

type RefMessage added in v0.8.0

type RefMessage struct {
	ProtoMsg *refproto.Referee

	Send func()
	// contains filtered or unexported fields
}

func (*RefMessage) Publish added in v0.8.0

func (p *RefMessage) Publish(state *State)

Publish the state and command

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) IsPausedStage added in v0.6.0

func (s Stage) IsPausedStage() bool

func (Stage) IsPreStage

func (s Stage) IsPreStage() bool

func (Stage) Next

func (s Stage) Next() Stage

func (Stage) Previous

func (s Stage) Previous() Stage

func (Stage) Valid added in v0.19.0

func (s Stage) Valid() bool

Valid checks if the Stage enum value is among the known values

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"
	// StageEndGame ends the game
	StageEndGame StageOperation = "endGame"
)

type State

type State struct {
	Stage                      Stage                               `json:"stage" yaml:"stage"`
	Command                    RefCommand                          `json:"command" yaml:"command"`
	CommandFor                 Team                                `json:"commandForTeam" yaml:"commandForTeam"`
	GameEvents                 []*GameEvent                        `json:"gameEvents" yaml:"gameEvents"`
	StageTimeElapsed           time.Duration                       `json:"stageTimeElapsed" yaml:"stageTimeElapsed"`
	StageTimeLeft              time.Duration                       `json:"stageTimeLeft" yaml:"stageTimeLeft"`
	MatchTimeStart             time.Time                           `json:"matchTimeStart" yaml:"matchTimeStart"`
	MatchDuration              time.Duration                       `json:"matchDuration" yaml:"matchDuration"` // MatchDuration contains the updated match duration based on MatchTimeStart for the UI
	TeamState                  map[Team]*TeamInfo                  `json:"teamState" yaml:"teamState"`
	Division                   config.Division                     `json:"division" yaml:"division"`
	PlacementPos               *Location                           `json:"placementPos" yaml:"placementPos"`
	AutoContinue               bool                                `json:"autoContinue" yaml:"autoContinue"`
	NextCommand                RefCommand                          `json:"nextCommand" yaml:"nextCommand"`
	NextCommandFor             Team                                `json:"nextCommandFor" yaml:"nextCommandFor"`
	GameEventBehavior          map[GameEventType]GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
	GameEventProposals         []*GameEventProposal                `json:"gameEventProposals" yaml:"gameEventProposals"`
	CurrentActionDeadline      time.Time                           `json:"currentActionDeadline" yaml:"currentActionDeadline"`
	CurrentActionTimeRemaining time.Duration                       `json:"currentActionTimeRemaining" yaml:"currentActionTimeRemaining"` // CurrentActionTimeRemaining contains the updated remaining lack of progress time for the UI
}

State of the game

func NewState

func NewState() (s *State)

NewState creates a new state, initialized for the start of a new game

func (State) BotSubstitutionIntend added in v0.11.0

func (s State) BotSubstitutionIntend() Team

func (State) DeepCopy added in v0.14.0

func (s State) DeepCopy() (c State)

func (State) GameState

func (s State) GameState() GameState

func (*State) GetFirstGameEvent added in v0.19.0

func (s *State) GetFirstGameEvent(gameEventType GameEventType) *GameEvent

func (*State) MatchesRecentGameEvent added in v0.30.0

func (s *State) MatchesRecentGameEvent(event *GameEvent) bool

func (*State) PrimaryGameEvent added in v0.14.0

func (s *State) PrimaryGameEvent() *GameEvent

func (State) String

func (s State) String() string

func (*State) TeamByName added in v0.8.0

func (s *State) TeamByName(teamName string) Team

type Team

type Team string

Team is one of Yellow or Blue

const (
	// TeamYellow is the yellow team
	TeamYellow Team = "Yellow"
	// TeamBlue is the blue team
	TeamBlue Team = "Blue"
	// TeamUnknown is an unknown team
	TeamUnknown Team = ""
	// TeamBoth are both teams
	TeamBoth = "Both"
)

func NewTeam added in v0.8.0

func NewTeam(team refproto.Team) Team

NewTeam creates a team from a protobuf team. Its either a single team or unknown. Not both.

func (Team) Is added in v0.23.1

func (t Team) Is(team Team) bool

Is returns true, if the team is equal to given team, respecting unknown and both accordingly

func (Team) Known added in v0.4.0

func (t Team) Known() bool

Known returns true if the team is blue or yellow

func (Team) Opposite

func (t Team) Opposite() Team

Opposite returns the other team if the team is not Yellow or Blue, return the same team

func (Team) Unknown

func (t Team) Unknown() bool

Unknown returns true if the team is not blue or yellow

func (Team) Valid added in v0.19.0

func (t Team) Valid() bool

Valid checks if the Team enum value is among the known values

type TeamChoice added in v0.8.0

type TeamChoice struct {
	Team      Team
	Event     Event
	IssueTime time.Time
}

TeamChoice represents an outstanding team choice request

type TeamInfo

type TeamInfo struct {
	Name                  string          `json:"name" yaml:"name"`
	Goals                 int             `json:"goals" yaml:"goals"`
	Goalkeeper            int             `json:"goalkeeper" yaml:"goalkeeper"`
	YellowCards           int             `json:"yellowCards" yaml:"yellowCards"`
	YellowCardTimes       []time.Duration `json:"yellowCardTimes" yaml:"yellowCardTimes"`
	RedCards              int             `json:"redCards" yaml:"redCards"`
	TimeoutsLeft          int             `json:"timeoutsLeft" yaml:"timeoutsLeft"`
	TimeoutTimeLeft       time.Duration   `json:"timeoutTimeLeft" yaml:"timeoutTimeLeft"`
	OnPositiveHalf        bool            `json:"onPositiveHalf" yaml:"onPositiveHalf"`
	FoulCounter           int             `json:"foulCounter" yaml:"foulCounter"`
	BallPlacementFailures int             `json:"ballPlacementFailures" yaml:"ballPlacementFailures"`
	CanPlaceBall          bool            `json:"canPlaceBall" yaml:"canPlaceBall"`
	MaxAllowedBots        int             `json:"maxAllowedBots" yaml:"maxAllowedBots"`
	BotSubstitutionIntend bool            `json:"botSubstitutionIntend" yaml:"botSubstitutionIntend"`
}

TeamInfo about a team

func (TeamInfo) DeepCopy added in v0.14.0

func (t TeamInfo) DeepCopy() (c TeamInfo)

func (TeamInfo) String

func (t TeamInfo) String() string

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"
	// TriggerContinue continues based on the current game event
	TriggerContinue TriggerType = "continue"
)

type UiProtocolEntry added in v0.16.0

type UiProtocolEntry struct {
	Timestamp   int64          `json:"timestamp"`
	StageTime   time.Duration  `json:"stageTime"`
	Type        UiProtocolType `json:"type"`
	Name        string         `json:"name"`
	Team        Team           `json:"team"`
	Description string         `json:"description"`
}

UiProtocolEntry represents a single protocol entry as should be displayed in the UI table

type UiProtocolType added in v0.16.0

type UiProtocolType string

UiProtocolType represents the type of a protocol entry

const (
	// UiProtocolCommand represents an issued referee command
	UiProtocolCommand UiProtocolType = "command"
	// UiProtocolStage represents a changed stage
	UiProtocolStage UiProtocolType = "stage"
	// UiProtocolCard represents an issued card
	UiProtocolCard UiProtocolType = "card"
	// UiProtocolTime represents an elapsed time, like stage time or card time
	UiProtocolTime UiProtocolType = "time"
	// UiProtocolGameEvent represents an issued game event
	UiProtocolGameEvent UiProtocolType = "gameEvent"
	// UiProtocolGameEventIgnored represents a detected game event that was not issued
	UiProtocolGameEventIgnored UiProtocolType = "ignoredGameEvent"
	// UiProtocolModify represents a manual modification on the state
	UiProtocolModify UiProtocolType = "modify"
	// UiProtocolTeamAction represents an action from a team
	UiProtocolTeamAction UiProtocolType = "teamAction"
	// UiProtocolHint represents a hint to the human game-controller operator
	UiProtocolHint UiProtocolType = "hint"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL