Documentation
¶
Index ¶
- Constants
- 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(handler TurnHandler) error
- func (c *Client) PlayAsBot(bot Bot, logger Logger) 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 Error
- type Handler
- type Logger
- type OrderSender
- type PlayerState
- type Sender
- type TurnData
- type TurnHandler
- type TurnOrdersSender
Constants ¶
const ( // ErrGRPCConnectionClosed identifies when the error returned is cased by the connection has been closed ErrGRPCConnectionClosed = Error("grpc connection closed by the server") // ErrGRPCConnectionLost identifies that something unexpected broke the gRPC connection ErrGRPCConnectionLost = Error("grpc stream error") )
const ( ErrNilSnapshot = Error("invalid snapshot state (nil)") ErrPlayerNotFound = Error("player not found in the game snapshot") ErrNoBall = Error("no ball found in the snapshot") )
const ProtocolVersion = "0.0.1"
ProtocolVersion defines the current game protocol
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot interface { // OnDisputing is called when no one has the ball possession OnDisputing(ctx context.Context, sender TurnOrdersSender, snapshot *proto.GameSnapshot) error // OnDefending is called when an opponent player has the ball possession OnDefending(ctx context.Context, sender TurnOrdersSender, snapshot *proto.GameSnapshot) error // OnHolding is called when this bot has the ball possession OnHolding(ctx context.Context, sender TurnOrdersSender, snapshot *proto.GameSnapshot) error // OnSupporting is called when a teammate player has the ball possession OnSupporting(ctx context.Context, sender TurnOrdersSender, snapshot *proto.GameSnapshot) 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, sender TurnOrdersSender, snapshot *proto.GameSnapshot, state PlayerState) error }
type Client ¶
type Client struct { Stream proto.Game_JoinATeamClient GRPCClient proto.GameClient Handler TurnHandler Logger Logger // contains filtered or unexported fields }
Client handle the gRPC stuff and provide you an easy way to handle the game messages
func NewClient ¶
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 handler
func (*Client) Play ¶
func (c *Client) Play(handler TurnHandler) error
Play starts the player communication with the server. The TurnHandler will receive the raw snapshot from the game server. The context passed to the handler will be canceled as soon a new turn starts.
func (*Client) PlayAsBot ¶
PlayAsBot is a sugared Play mode that uses an TurnHandler from coach package. Coach TurnHandler creates basic player states to help the development of new bots.
type Handler ¶
type Handler struct { Logger Logger Sender OrderSender PlayerNumber uint32 Side proto.Team_Side Bot Bot }
Handler is a Lugo4go client handler that allow you to create an interface to follow a basic strategy based on team states.
func NewHandler ¶
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" )
func DefineMyState ¶
func DefineMyState(snapshot *proto.GameSnapshot, playerNumber uint32, side proto.Team_Side) (PlayerState, error)
type Sender ¶
type Sender struct {
GRPCClient proto.GameClient
}
func NewSender ¶
func NewSender(grpcClient proto.GameClient) *Sender
type TurnHandler ¶
type TurnHandler interface { // Handle is called every turn with the new game state Handle(ctx context.Context, snapshot *proto.GameSnapshot) }
TurnHandler is required by the Lugo4Go client to handle each turn snapshot
type TurnOrdersSender ¶
type TurnOrdersSender interface {
Send(ctx context.Context, orders []proto.PlayerOrder, debugMsg string) (*proto.OrderResponse, error)
}