controller

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2018 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func (a *ApiServer) PublishRefereeEvents(events []RefereeEvent)

func (*ApiServer) PublishState

func (a *ApiServer) PublishState(state State)

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"`
	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 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 Config

type Config struct {
	Network ConfigNetwork `yaml:"network"`
	Game    ConfigGame    `yaml:"game"`
	Server  ConfigServer  `yaml:"server"`
}

Config structure for the game controller

func DefaultConfig

func DefaultConfig() (c Config)

DefaultConfig creates a config with default values

func LoadConfig

func LoadConfig(fileName string) (config Config, err error)

LoadConfig loads a config from given file

type ConfigGame

type ConfigGame struct {
	YellowCardDuration        time.Duration                `yaml:"yellow-card-duration"`
	DefaultDivision           Division                     `yaml:"default-division"`
	Normal                    ConfigSpecial                `yaml:"normal"`
	Overtime                  ConfigSpecial                `yaml:"overtime"`
	TeamChoiceTimeout         time.Duration                `yaml:"team-choice-timeout"`
	DefaultGeometry           map[Division]*ConfigGeometry `yaml:"default-geometry"`
	MultipleCardStep          int                          `yaml:"multiple-card-step"`
	MultipleFoulStep          int                          `yaml:"multiple-foul-step"`
	MultiplePlacementFailures int                          `yaml:"multiple-placement-failures"`
	MaxBots                   map[Division]int             `yaml:"max-bots"`
	AutoRefProposalTimeout    time.Duration                `yaml:"auto-ref-proposal-timeout"`
}

ConfigGame holds configs that are valid for the whole game

type ConfigGeometry added in v0.8.0

type ConfigGeometry struct {
	FieldLength                     float64 `yaml:"field-length"`
	FieldWidth                      float64 `yaml:"field-width"`
	DefenseAreaDepth                float64 `yaml:"defense-area-depth"`
	DefenseAreaWidth                float64 `yaml:"defense-area-width"`
	PlacementOffsetTouchLine        float64 `yaml:"placement-offset-touch-line"`
	PlacementOffsetGoalLine         float64 `yaml:"placement-offset-goal-line"`
	PlacementOffsetGoalLineGoalKick float64 `yaml:"placement-offset-goal-line-goal-kick"`
	PlacementOffsetDefenseArea      float64 `yaml:"placement-offset-defense-area"`
}

type ConfigNetwork added in v0.9.0

type ConfigNetwork struct {
	PublishAddress string `yaml:"publish-address"`
	VisionAddress  string `yaml:"vision-address"`
}

ConfigNetwork holds configs for network communication

type ConfigServer added in v0.8.0

type ConfigServer struct {
	AutoRef ConfigServerAutoRef `yaml:"auto-ref"`
	Team    ConfigServerTeam    `yaml:"team"`
}

ConfigServer holds configs for the available server services

type ConfigServerAutoRef added in v0.8.0

type ConfigServerAutoRef struct {
	Address        string `yaml:"address"`
	TrustedKeysDir string `yaml:"trusted-keys-dir"`
}

ConfigServerAutoRef holds configs for the autoRef server

type ConfigServerTeam added in v0.8.0

type ConfigServerTeam struct {
	Address        string `yaml:"address"`
	TrustedKeysDir string `yaml:"trusted-keys-dir"`
}

ConfigServerTeam holds configs for the team server

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 Division added in v0.7.0

type Division string
const (
	DivA Division = "DivA"
	DivB Division = "DivB"
)

type Engine

type Engine struct {
	State         *State
	RefereeEvents []RefereeEvent
	StageTimes    map[Stage]time.Duration

	TimeProvider func() time.Time
	History      History
	Geometry     ConfigGeometry
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(config ConfigGame) (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 game event

func (*Engine) CardNumberIncremented added in v0.9.0

func (e *Engine) CardNumberIncremented(team Team)

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)

func (*Engine) LastGameStartCommand added in v0.8.0

func (e *Engine) LastGameStartCommand() (RefCommand, error)

func (*Engine) LogCard added in v0.6.0

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

func (*Engine) LogCommand added in v0.3.0

func (e *Engine) LogCommand()

func (*Engine) LogGameEvent added in v0.3.0

func (e *Engine) LogGameEvent(event GameEvent)

func (*Engine) LogIgnoredGameEvent added in v0.10.0

func (e *Engine) LogIgnoredGameEvent(event GameEvent)

func (*Engine) LogModify added in v0.9.0

func (e *Engine) LogModify(m EventModifyValue)

func (*Engine) LogStage added in v0.6.0

func (e *Engine) LogStage(stage Stage)

func (*Engine) LogTime added in v0.6.0

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

func (*Engine) PlacementFailuresIncremented added in v0.9.0

func (e *Engine) PlacementFailuresIncremented(team Team)

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

func (e *Engine) Tick(delta time.Duration)

Tick updates the times of the state and removes cards, if necessary

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"`
	GameEvent *GameEvent        `json:"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"`
	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

type EventModifyCardTime struct {
	CardID   int    `json:"cardId"`
	Duration string `json:"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"`
	GameEventBehavior GameEventBehavior `json:"gameEventBehavior"`
}

EventModifyGameEventBehavior holds the type to behavior mapping

type EventModifyValue

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

	Goals                 *int                          `json:"goals,omitempty"`
	Goalie                *int                          `json:"goalie,omitempty"`
	YellowCards           *int                          `json:"yellowCards,omitempty"`
	YellowCardTime        *EventModifyCardTime          `json:"yellowCardTime,omitempty"`
	RedCards              *int                          `json:"redCards,omitempty"`
	TimeoutsLeft          *int                          `json:"timeoutsLeft,omitempty"`
	TimeoutTimeLeft       *string                       `json:"timeoutTimeLeft,omitempty"`
	OnPositiveHalf        *bool                         `json:"onPositiveHalf,omitempty"`
	TeamName              *string                       `json:"teamName,omitempty"`
	FoulCounter           *int                          `json:"foulCounter,omitempty"`
	BallPlacementFailures *int                          `json:"ballPlacementFailures,omitempty"`
	CanPlaceBall          *bool                         `json:"canPlaceBall,omitempty"`
	Division              *Division                     `json:"division,omitempty"`
	AutoContinue          *bool                         `json:"autoContinue,omitempty"`
	GameEventBehavior     *EventModifyGameEventBehavior `json:"gameEventBehavior,omitempty"`
}

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
	AutoRefServer *rcon.AutoRefServer
	TeamServer    *rcon.TeamServer
	Engine        Engine

	Mutex          sync.Mutex
	VisionReceiver *VisionReceiver
	// 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)

func (*GameController) ProcessAutoRefRequests added in v0.8.0

func (c *GameController) ProcessAutoRefRequests(id string, request refproto.AutoRefToControllerRequest) 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.TeamToControllerRequest) error

func (*GameController) Run

func (c *GameController) Run()

Run the GameController by starting an endless loop in the background

type GameEvent added in v0.8.0

type GameEvent struct {
	Type    GameEventType    `json:"type"`
	Details GameEventDetails `json:"details"`
}

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) IncrementsBallPlacementFailureCounter added in v0.9.0

func (e GameEvent) IncrementsBallPlacementFailureCounter() bool

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

func (e GameEvent) IsContinued() bool

IsContinued checks if the game event is was continued (not stopped) based on the decision of a team

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) String added in v0.9.0

func (m GameEvent) String() string

func (GameEvent) ToProto added in v0.8.0

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

type GameEventBehavior added in v0.10.0

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

type GameEventDetails added in v0.8.0

type GameEventDetails struct {
	BallLeftFieldTouchLine         *refproto.GameEvent_BallLeftFieldEvent             `json:"ballLeftFieldTouchLine,omitempty"`
	BallLeftFieldGoalLine          *refproto.GameEvent_BallLeftFieldEvent             `json:"ballLeftFieldGoalLine,omitempty"`
	AimlessKick                    *refproto.GameEvent_AimlessKick                    `json:"aimlessKick,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"`
	BotCrashUniqueContinue         *refproto.GameEvent_BotCrashUnique                 `json:"botCrashUniqueContinue,omitempty"`
	BotPushedBot                   *refproto.GameEvent_BotPushedBot                   `json:"botPushedBot,omitempty"`
	BotPushedBotContinue           *refproto.GameEvent_BotPushedBot                   `json:"botPushedBotContinue,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"`
	UnsportiveBehaviorMinor        *refproto.GameEvent_UnsportiveBehaviorMinor        `json:"unsportiveBehaviorMinor,omitempty"`
	UnsportiveBehaviorMajor        *refproto.GameEvent_UnsportiveBehaviorMajor        `json:"unsportiveBehaviorMajor,omitempty"`
	MultipleCards                  *refproto.GameEvent_MultipleCards                  `json:"multiple,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"`
	PlacementFailedByTeamInFavor   *refproto.GameEvent_PlacementFailedByTeamInFavor   `json:"placementFailedByTeamInFavor,omitempty"`
	PlacementFailedByOpponent      *refproto.GameEvent_PlacementFailedByOpponent      `json:"placementFailedByOpponent,omitempty"`
	PlacementSucceeded             *refproto.GameEvent_PlacementSucceeded             `json:"placementSucceeded,omitempty"`
	Prepared                       *refproto.GameEvent_Prepared                       `json:"prepared,omitempty"`
}

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

func NewGameEventDetails added in v0.8.0

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

func (GameEventDetails) Description added in v0.8.0

func (d GameEventDetails) Description() string

func (GameEventDetails) EventType added in v0.8.0

func (d GameEventDetails) EventType() GameEventType

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 = ""
	GameEventBallLeftFieldTouchLine         GameEventType = "ballLeftFieldTouchLine"
	GameEventBallLeftFieldGoalLine          GameEventType = "ballLeftFieldGoalLine"
	GameEventAimlessKick                    GameEventType = "aimlessKick"
	GameEventGoal                           GameEventType = "goal"
	GameEventIndirectGoal                   GameEventType = "indirectGoal"
	GameEventChippedGoal                    GameEventType = "chippedGoal"
	GameEventBotTooFastInStop               GameEventType = "botTooFastInStop"
	GameEventBotTippedOver                  GameEventType = "botTippedOver"
	GameEventBotInterferedPlacement         GameEventType = "botInterferedPlacement"
	GameEventBotCrashDrawn                  GameEventType = "botCrashDrawn"
	GameEventBotKickedBallTooFast           GameEventType = "botKickedBallTooFast"
	GameEventBotDribbledBallTooFar          GameEventType = "botDribbledBallTooFar"
	GameEventBotCrashUnique                 GameEventType = "botCrashUnique"
	GameEventBotCrashUniqueContinue         GameEventType = "botCrashUniqueContinue"
	GameEventBotPushedBot                   GameEventType = "botPushedBot"
	GameEventBotPushedBotContinue           GameEventType = "botPushedBotContinue"
	GameEventBotHeldBallDeliberately        GameEventType = "botHeldBallDeliberately"
	GameEventAttackerDoubleTouchedBall      GameEventType = "attackerDoubleTouchedBall"
	GameEventAttackerTooCloseToDefenseArea  GameEventType = "attackerTooCloseToDefenseArea"
	GameEventAttackerInDefenseArea          GameEventType = "attackerInDefenseArea"
	GameEventAttackerTouchedKeeper          GameEventType = "attackerTouchedKeeper"
	GameEventDefenderTooCloseToKickPoint    GameEventType = "defenderTooCloseToKickPoint"
	GameEventDefenderInDefenseAreaPartially GameEventType = "defenderInDefenseAreaPartially"
	GameEventDefenderInDefenseArea          GameEventType = "defenderInDefenseArea"
	GameEventKeeperHeldBall                 GameEventType = "keeperHeldBall"
	GameEventUnsportiveBehaviorMinor        GameEventType = "unsportiveBehaviorMinor"
	GameEventUnsportiveBehaviorMajor        GameEventType = "unsportiveBehaviorMajor"
	GameEventMultipleCards                  GameEventType = "multipleCards"
	GameEventMultipleFouls                  GameEventType = "multipleFouls"
	GameEventMultiplePlacementFailures      GameEventType = "multiplePlacementFailures"
	GameEventKickTimeout                    GameEventType = "kickTimeout"
	GameEventNoProgressInGame               GameEventType = "noProgressInGame"
	GameEventPlacementFailedByTeamInFavor   GameEventType = "placementFailedByTeamInFavor"
	GameEventPlacementFailedByOpponent      GameEventType = "placementFailedByOpponent"
	GameEventPlacementSucceeded             GameEventType = "placementSucceeded"
	GameEventPrepared                       GameEventType = "prepared"
)

func AllGameEvents added in v0.10.0

func AllGameEvents() []GameEventType

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

type Location struct {
	X float64
	Y float64
}

Location is a two-dimensional coordinate

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

func NewPublisher(address string) (publisher Publisher, err error)

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

type RefMessage added in v0.8.0

type RefMessage struct {
	// 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 RefereeEvent added in v0.3.0

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

type RefereeEventType added in v0.3.0

type RefereeEventType string
const (
	RefereeEventCommand          RefereeEventType = "command"
	RefereeEventStage            RefereeEventType = "stage"
	RefereeEventCard             RefereeEventType = "card"
	RefereeEventTime             RefereeEventType = "time"
	RefereeEventGameEvent        RefereeEventType = "gameEvent"
	RefereeEventGameEventIgnored RefereeEventType = "ignoredGameEvent"
	RefereeEventModify           RefereeEventType = "modify"
)

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

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"`
	Command            RefCommand                          `json:"command"`
	CommandFor         Team                                `json:"commandForTeam"`
	GameEvents         []*GameEvent                        `json:"gameEvents"`
	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"`
	Division           Division                            `json:"division"`
	PlacementPos       *Location                           `json:"placementPos"`
	AutoContinue       bool                                `json:"autoContinue"`
	NextCommand        RefCommand                          `json:"nextCommand"`
	NextCommandFor     Team                                `json:"nextCommandFor"`
	AutoRefsConnected  []string                            `json:"autoRefsConnected"`
	GameEventBehavior  map[GameEventType]GameEventBehavior `json:"gameEventBehavior"`
	GameEventProposals []*GameEventProposal                `json:"gameEventProposals"`
}

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

func (s State) GameState() GameState

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

func NewTeam added in v0.8.0

func NewTeam(team refproto.Team) Team

NewTeam creates a team from a protobuf team

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

type TeamChoice added in v0.8.0

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

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"`
	FoulCounter           int             `json:"foulCounter"`
	BallPlacementFailures int             `json:"ballPlacementFailures"`
	CanPlaceBall          bool            `json:"canPlaceBall"`
	MaxAllowedBots        int             `json:"maxAllowedBots"`
	Connected             bool            `json:"connected"`
}

TeamInfo about a team

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 VisionReceiver added in v0.9.0

type VisionReceiver struct {
	DetectionCallback func(*sslproto.SSL_DetectionFrame)
	GeometryCallback  func(*sslproto.SSL_GeometryData)
}

func NewVisionReceiver added in v0.9.0

func NewVisionReceiver(address string) (v *VisionReceiver)

Jump to

Keyboard shortcuts

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