Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultLogger(config Config) *zap.SugaredLogger
- type Bot
- type Client
- func (c *Client) HandleConn(_ context.Context, sts stats.ConnStats)
- func (c *Client) HandleRPC(context.Context, stats.RPCStats)
- func (c *Client) Play(rawBot RawBot) error
- func (c *Client) PlayAsBot(bot Bot) error
- func (c *Client) Stop() error
- func (c *Client) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (c *Client) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context
- type Config
- type Logger
- type OrderSender
- type PlayerState
- type RawBot
- type SnapshotInspector
- type Starter
Constants ¶
const ( EnvVarBotTeam = "BOT_TEAM" EnvVarBotNumber = "BOT_NUMBER" EnvVarBotGrpcUrl = "BOT_GRPC_URL" EnvVarBotGrpcInsecure = "BOT_GRPC_INSECURE" EnvVarBotToken = "BOT_TOKEN" )
const ( DefaultFieldMapCols = 16 DefaultFieldMapRows = 8 )
const ProtocolVersion = "0.0.1"
ProtocolVersion defines the current game protocol
Variables ¶
var ( // ErrGRPCConnectionClosed identifies when the error returned is cased by the connection has been closed ErrGRPCConnectionClosed = errors.New("grpc connection closed by the server") // ErrGRPCConnectionLost identifies that something unexpected broke the gRPC connection ErrGRPCConnectionLost = errors.New("grpc stream error") )
var ( ErrNilSnapshot = errors.New("invalid snapshot state (nil)") ErrPlayerNotFound = errors.New("player not found in the game snapshot") ErrNoBall = errors.New("no ball found in the snapshot") )
var DefaultInitialPositions = map[int]struct { Col int Row int }{ 2: {Col: 1, Row: 2}, 3: {Col: 1, Row: 3}, 4: {Col: 1, Row: 4}, 5: {Col: 1, Row: 5}, 6: {Col: 4, Row: 1}, 7: {Col: 4, Row: 3}, 8: {Col: 4, Row: 4}, 9: {Col: 4, Row: 6}, 10: {Col: 6, Row: 3}, 11: {Col: 6, Row: 4}, }
Functions ¶
func DefaultLogger ¶
func DefaultLogger(config Config) *zap.SugaredLogger
DefaultLogger creates a logger that is compatible with the lugo4go.rawBot expected logger. The bots are NOT obligated to use this logger though. You may implement your own logger.
Types ¶
type Bot ¶
type Bot interface { // OnDisputing is called when no one has the ball possession OnDisputing(ctx context.Context, inspector SnapshotInspector) ([]proto.PlayerOrder, string, error) // OnDefending is called when an opponent player has the ball possession OnDefending(ctx context.Context, inspector SnapshotInspector) ([]proto.PlayerOrder, string, error) // OnHolding is called when this bot has the ball possession OnHolding(ctx context.Context, inspector SnapshotInspector) ([]proto.PlayerOrder, string, error) // OnSupporting is called when a teammate player has the ball possession OnSupporting(ctx context.Context, inspector SnapshotInspector) ([]proto.PlayerOrder, string, error) // AsGoalkeeper is only called when this bot is the goalkeeper (number 1). This method is called on every turn, // and the player state is passed at the last parameter. AsGoalkeeper(ctx context.Context, inspector SnapshotInspector, state PlayerState) ([]proto.PlayerOrder, string, error) OnGetReady(ctx context.Context, inspector SnapshotInspector) }
type Client ¶
type Client struct { Stream proto.Game_JoinATeamClient GRPCClient proto.GameClient Logger Logger Sender OrderSender // contains filtered or unexported fields }
Client handle the gRPC stuff and provide you an easy way to handle the game messages
func NewClient ¶
func NewClient(config Config, logger *zap.SugaredLogger) (*Client, error)
NewClient creates a Lugo4Go client that will hide common logic and let you focus on your bot.
func (*Client) HandleConn ¶
HandleConn implements the interface required by gRPC rawBotWrapper
func (*Client) Play ¶
Play starts the player communication with the server. The RawBot will receive the raw snapshot from the game server. The context passed to the rawBotWrapper will be canceled as soon a new turn starts.
func (*Client) PlayAsBot ¶
PlayAsBot is a sugared Play mode that uses an RawBot from coach package. Coach RawBot creates basic player states to help the development of new bots.
type Config ¶
type Config struct { // Full url to the gRPC server GRPCAddress string `json:"grpc_address"` Insecure bool `json:"insecure"` Token string `json:"token"` TeamSide proto.Team_Side `json:"-"` Number int `json:"-"` InitialPosition *proto.Point `json:"-"` // contains filtered or unexported fields }
Config is the set of values expected as a initial configuration of the player
func DefaultInitBundle ¶
DefaultInitBundle created a basic configuration that may be used by the client to connect to the server. It also creates a logger that is compatible with the lugo4go.rawBot.
type OrderSender ¶
type OrderSender interface {
Send(ctx context.Context, turn uint32, orders []proto.PlayerOrder, debugMsg string) (*proto.OrderResponse, error)
}
type PlayerState ¶
type PlayerState string
PlayerState defines states specific for players
const ( // Supporting identifies the player supporting the teammate Supporting PlayerState = "supporting" // HoldingTheBall identifies the player holding the ball HoldingTheBall PlayerState = "holding" // Defending identifies the player defending against the opponent team Defending PlayerState = "defending" // DisputingTheBall identifies the player disputing the ball DisputingTheBall PlayerState = "disputing" )
type RawBot ¶
type RawBot interface { // TurnHandler is called every turn with the new game state TurnHandler(ctx context.Context, inspector SnapshotInspector) ([]proto.PlayerOrder, string, error) GetReadyHandler(ctx context.Context, inspector SnapshotInspector) }
RawBot is required by the Lugo4Go client to handle each turn snapshot
type SnapshotInspector ¶
type SnapshotInspector interface { GetSnapshot() *proto.GameSnapshot GetMe() *proto.Player GetBall() *proto.Ball GetBallHolder() (*proto.Player, bool) IsBallHolder(player *proto.Player) bool GetTeam(side proto.Team_Side) *proto.Team GetMyTeam() *proto.Team GetOpponentTeam() *proto.Team GetPlayer(side proto.Team_Side, number int) *proto.Player GetMyTeamPlayers() []*proto.Player GetOpponentPlayers() []*proto.Player GetMyTeamGoalkeeper() *proto.Player GetOpponentGoalkeeper() *proto.Player MakeOrderMove(target proto.Point, speed float64) (*proto.Order_Move, error) MakeOrderMoveMaxSpeed(target proto.Point) (*proto.Order_Move, error) MakeOrderMoveFromPoint(origin, target proto.Point, speed float64) (*proto.Order_Move, error) MakeOrderMoveFromVector(vector proto.Vector, speed float64) *proto.Order_Move MakeOrderMoveByDirection(direction field.Direction, speed float64) *proto.Order_Move MakeOrderMoveToStop() *proto.Order_Move MakeOrderJump(target proto.Point, speed float64) (*proto.Order_Jump, error) MakeOrderKick(target proto.Point, speed float64) (*proto.Order_Kick, error) MakeOrderKickMaxSpeed(target proto.Point) (*proto.Order_Kick, error) MakeOrderCatch() *proto.Order_Catch }
func NewGameSnapshotInspector ¶
func NewGameSnapshotInspector(botSide proto.Team_Side, playerNumber int, gameSnapshot *proto.GameSnapshot) (SnapshotInspector, error)
type Starter ¶
type Starter struct { Config Config Logger *zap.SugaredLogger }