client

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: GPL-3.0 Imports: 19 Imported by: 0

README

MakeItPlay - Football Go Player Client

GoDoc Go Report Card

Go Player Client is a Go implementation of a client player for MakeItPlay football game server.

It is not a bot that plays the game, it is only the client for the game server.

This client implements a brainless player in the game. So, this library implements many methods that does not affect the player intelligence/behaviour/decisions. It is meant to reduce the developer concerns on communication, protocols, attributes, etc, and focus in the player intelligence.

Using this client, you just need to implement the Artificial Intelligence of your player and some other few methods to support your strategy (see the project The Dummies as an example).

Documentation
Requirements
  1. Docker >= 18.03 (https://docs.docker.com/install/)
  2. Docker Compose >= 1.21 (https://docs.docker.com/compose/install/)
  3. Go Lang >= 1.12 (https://golang.org/doc/install)
Installation
go get github.com/makeitplay/client-player-go
Kick start
  1. Copy the example directory as a new Golang project

  2. Build your bot executing the command below inside the project directory

    go build -o myAwesomeBot
    
  3. Run the game server using the command

    docker run -p 8080:8080  makeitplay/football:1.0.0-alpha
    
  4. Now you will need to start your team process. Each team must have 11 process (one for each player).

    Option A: You may start your team players manually executing the command ./myAwesomeBot -team=home -number=[1-11] eleven times.

    or

    Option B: You can use the script in the example directory to do this automatically for you: ./play.sh home

  5. And finally you may do the same for the other team.

    Option A: You play against your own team repeating the last step, but in the away side: ./play.sh away

    or

    Option B: You may play against The Dummies team executing the script start-team-container.sh available in the example directory:

    ./start-team-container.sh makeitplay/the-dummies-go away

    or

    Option C: You may play against another team: ./start-team-container.sh [container image name] away

Next steps

As you may have noticed, the bot player in the example directory does not play well. Now, you may start your bot implementing its behaviour based on the game state after each message got by the function reactToNewState.

Deploying you bots

After developing your bot, you may share it with other developers.

Using this client your code will be compiled into a binary file. So you do not have to share the bot source code.

There is a Dockerfile template in the example directory to guide you how to create a container. After having customized (or not) your Dockerfile, you just need to build the container:

docker build -t [your username]/[your bot awesome name] .
docker push

If you are not familiar with Dockerfile, Docker composer, and so on, consider spending 11 minutes to learn it watching this video. It is by far the best and simplest way to learn Docker.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TalkerSetup

func TalkerSetup(mainCtx GamerCtx, config *Configuration, initialPos physics.Point) (context.Context, talk.Talker, error)

Types

type Ball

type Ball struct {
	physics.Element
	// Holder identifies the player who is holding the ball
	Holder *Player
}

Ball is the ball :-)

type Configuration

type Configuration struct {
	// TeamPlace must be "home" or "away" and identifies the side of the field that the team is going to play
	TeamPlace arena.TeamPlace
	// PlayerNumber must be a number between 1-11 that identifies this player in his team
	PlayerNumber arena.PlayerNumber

	LogLevel logrus.Level
	// UUID is the match UUID. It will be always local for local games
	UUID string
	// WSHost is the hostname of the game server (only HTTP for now)
	WSHost string
	// WSPort is the port used by the game server
	WSPort string
	// Token is passed to the game server to bind the player to specific process, and avoid cheating
	Token string
}

Configuration is the set of values expected as a initial configuration of the player

func (*Configuration) ParseFromFlags

func (c *Configuration) ParseFromFlags()

ParseFromFlags sets the flag that will allows us to change the default config

type Controller

type Controller interface {
	SendOrders(place arena.TeamPlace, number arena.PlayerNumber, orderList []orders.Order)
	//ToggleDebugMode()
	NextTurn() (newState GameMessage, err error)
	LoadArrangement(name string) (newState GameMessage, err error)
	SetBallProperties(v physics.Velocity, position physics.Point) (newState GameMessage, err error)
	SetPlayerPos(place arena.TeamPlace, number arena.PlayerNumber, position physics.Point) (newState GameMessage, err error)
	SetGameTurn(turn int) (newState GameMessage, err error)
	ResetScore() (newState GameMessage, err error)
	SetFrameInterval(time time.Duration)
	GetGamerCtx(place arena.TeamPlace, number arena.PlayerNumber) (ctx TurnContext, err error)
}

func NewTestController

func NewTestController(ctx context.Context, confg Configuration) (context.Context, Controller, error)

type GameInfo

type GameInfo struct {
	State arena.GameState `json:"state"`
	// Turn is the sequential number of turns. Read the game documentation to understand what a turn is
	Turn     int  `json:"turn"`
	Ball     Ball `json:"ball"`
	HomeTeam Team `json:"home"`
	AwayTeam Team `json:"away"`
}

GameInfo is the set of values that defines the current game state

type GameMessage

type GameMessage struct {
	Type     arena.MsgType          `json:"type"`
	GameInfo GameInfo               `json:"info"`
	State    arena.GameState        `json:"state"`
	Data     map[string]interface{} `json:"data"`
	// Message is quite useless, but could help the developers to debug the game server messages
	Message string `json:"message"`
}

GameMessage is the message sent from the game server to the player

func (*GameMessage) Ball

func (g *GameMessage) Ball() Ball

func (*GameMessage) ForEachPlayByTeam

func (g *GameMessage) ForEachPlayByTeam(place arena.TeamPlace, callback func(index int, player *Player))

func (*GameMessage) GetTeam

func (g *GameMessage) GetTeam(place arena.TeamPlace) Team

func (*GameMessage) Turn

func (g *GameMessage) Turn() int

type Gamer

type Gamer struct {
	OnMessage      func(msg GameMessage)
	OnAnnouncement func(turnTx TurnContext)
	LogLevel       logrus.Level

	Talker  talk.Talker
	LastMsg GameMessage
	// contains filtered or unexported fields
}

func (*Gamer) Play

func (p *Gamer) Play(initialPosition physics.Point, configuration *Configuration) (GamerCtx, error)

Play make the player start to play

func (*Gamer) SendOrders

func (p *Gamer) SendOrders(message string, ordersList ...orders.Order)

SendOrders sends a list of orders to the game server, and includes a message to them (only displayed in the game server log)

func (*Gamer) StopToPlay

func (p *Gamer) StopToPlay(interrupted bool)

StopToPlay stop the player to play

type GamerCtx

type GamerCtx interface {
	context.Context
	Logger() *logrus.Entry
	CreateTurnContext(msg GameMessage) TurnContext
}

func NewGamerContext

func NewGamerContext(ctx context.Context, config *Configuration) (GamerCtx, context.CancelFunc)

type Player

type Player struct {
	physics.Element
	Id        string             `json:"id"`
	Number    arena.PlayerNumber `json:"number"`
	TeamPlace arena.TeamPlace    `json:"team_place"`
}

func (*Player) CreateCatchOrder

func (p *Player) CreateCatchOrder() orders.Order

CreateCatchOrder creates the catch order

func (*Player) CreateJumpOrder

func (p *Player) CreateJumpOrder(target physics.Point, speed float64) (orders.Order, error)

CreateJumpOrder creates a jump order (only allowed to goal keeper

func (*Player) CreateKickOrder

func (p *Player) CreateKickOrder(ball Ball, target physics.Point, speed float64) (orders.Order, error)

CreateKickOrder creates a kick order and try to find the best vector to reach the target

func (*Player) CreateMoveOrder

func (p *Player) CreateMoveOrder(target physics.Point, speed float64) (orders.Order, error)

CreateMoveOrder creates a move order

func (*Player) CreateMoveOrderMaxSpeed

func (p *Player) CreateMoveOrderMaxSpeed(target physics.Point) (orders.Order, error)

CreateMoveOrderMaxSpeed creates a move order with max speed allowed

func (*Player) CreateStopOrder

func (p *Player) CreateStopOrder(direction physics.Vector) orders.Order

CreateStopOrder creates a move order with speed zero

func (*Player) DefenseGoal

func (p *Player) DefenseGoal() arena.Goal

DefenseGoal returns the player team goal

func (*Player) FindOpponentPlayer

func (p *Player) FindOpponentPlayer(status GameInfo, playerNumber arena.PlayerNumber) *Player

FindOpponentPlayer retrieve a specific opponent player status from the game server message

func (*Player) GetMyTeamStatus

func (p *Player) GetMyTeamStatus(gameInfo GameInfo) Team

GetMyTeamStatus retrieve the player team status from the game server message

func (*Player) GetOpponentPlace

func (p *Player) GetOpponentPlace() arena.TeamPlace

func (*Player) GetOpponentTeam

func (p *Player) GetOpponentTeam(status GameInfo) Team

GetOpponentTeam retrieve the opponent team status from the game server message

func (*Player) ID

func (p *Player) ID() string

ID returns the player ID, that is the team place and it concatenated.

func (*Player) IHoldTheBall

func (p *Player) IHoldTheBall(ball Ball) bool

IHoldTheBall returns true when the player is holding the ball

func (*Player) IsGoalkeeper

func (p *Player) IsGoalkeeper() bool

IsGoalkeeper returns true if the player is the goalkeeper

func (*Player) OpponentGoal

func (p *Player) OpponentGoal() arena.Goal

OpponentGoal returns the Goal os the opponent

type PlayerMessage

type PlayerMessage struct {
	Type   arena.MsgType  `json:"type"`
	Orders []orders.Order `json:"orders"`
	// Debug is a message the will be only visible in the game server log (used for debugging purposes)
	Debug string `json:"message"`
}

PlayerMessage is the message sent from a player to the game server

type Responder

type Responder interface {
	SendOrders(message string, ordersList ...orders.Order)
}

type Team

type Team struct {
	Name    arena.TeamPlace `json:"name"`
	Score   int             `json:"score"`
	Players []*Player       `json:"players"`
}

Team groups the player team info based on the status sent by the game server

type TurnContext

type TurnContext interface {
	context.Context
	Logger() *logrus.Entry
	Player() *Player
	GameMsg() *GameMessage
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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