lugo4go

package module
v2.0.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: GPL-3.0 Imports: 14 Imported by: 2

README

Lugo - Go Player Client

GoDoc Go Report Card

Go Player Client is a Go implementation of a client player for Lugo game.

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
git clone https://github.com/lugobots/lugo4go.git
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  lugobots/server:v1.1 play --dev-mode
    

    or

    Start the Docker compose file present in this project. The Docker compose will also start the away team.

    docker-compose up
    
  4. Now you will need to start your team processes. 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, if your have not started the away team, you may do the same for the other team.

    You play against your own team repeating the last step, but in the away side:

    ./play.sh 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

Overview

Package lugo4go is a generated GoMock package.

Index

Constants

View Source
const ProtocolVersion = "2.0"

Variables

This section is empty.

Functions

func DefaultBundle

func DefaultBundle() (Config, Logger, error)

Types

type Client

type Client interface {
	OnNewTurn(DecisionMaker, Logger)
	Stop() error
	GetGRPCConn() *grpc.ClientConn
	GetServiceConn() proto.GameClient
	// The sender will not need the entire snapshot struct. However there are plans to allow the sender
	// to do mre complex jobs (e.g. having middleware to save status for machine learning). Then, we are
	// passing the snapshot since now, so the new versions will be compatible.
	SenderBuilder(builder func(snapshot *proto.GameSnapshot, logger Logger) OrderSender)
}

func NewClient

func NewClient(config Config) (context.Context, Client, error)

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
	Number          uint32      `json:"number"`
	InitialPosition proto.Point `json:"-"`
}

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

func DefaultConfigurator

func DefaultConfigurator() (Config, error)

func LoadConfig

func LoadConfig(filepath string) (c Config, e error)

func (*Config) ParseConfigFlags

func (c *Config) ParseConfigFlags() error

ParseConfigFlags is a helper that sets flags to make the configuration be overwritten by command line. Note that it won't be used in production, The config file is the only official way to configure it.

type DecisionMaker

type DecisionMaker func(ctx context.Context, snapshot *proto.GameSnapshot, sender OrderSender)

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})
}

func DefaultLogger

func DefaultLogger(config Config) (Logger, error)

type MockClient

type MockClient struct {
	// contains filtered or unexported fields
}

MockClient is a mock of Client interface

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClient) GetGRPCConn

func (m *MockClient) GetGRPCConn() *grpc.ClientConn

GetGRPCConn mocks base method

func (*MockClient) GetServiceConn

func (m *MockClient) GetServiceConn() proto.GameClient

GetServiceConn mocks base method

func (*MockClient) OnNewTurn

func (m *MockClient) OnNewTurn(arg0 DecisionMaker, arg1 Logger)

OnNewTurn mocks base method

func (*MockClient) SenderBuilder

func (m *MockClient) SenderBuilder(builder func(*proto.GameSnapshot, Logger) OrderSender)

SenderBuilder mocks base method

func (*MockClient) Stop

func (m *MockClient) Stop() error

Stop mocks base method

type MockClientMockRecorder

type MockClientMockRecorder struct {
	// contains filtered or unexported fields
}

MockClientMockRecorder is the mock recorder for MockClient

func (*MockClientMockRecorder) GetGRPCConn

func (mr *MockClientMockRecorder) GetGRPCConn() *gomock.Call

GetGRPCConn indicates an expected call of GetGRPCConn

func (*MockClientMockRecorder) GetServiceConn

func (mr *MockClientMockRecorder) GetServiceConn() *gomock.Call

GetServiceConn indicates an expected call of GetServiceConn

func (*MockClientMockRecorder) OnNewTurn

func (mr *MockClientMockRecorder) OnNewTurn(arg0, arg1 interface{}) *gomock.Call

OnNewTurn indicates an expected call of OnNewTurn

func (*MockClientMockRecorder) SenderBuilder

func (mr *MockClientMockRecorder) SenderBuilder(builder interface{}) *gomock.Call

SenderBuilder indicates an expected call of SenderBuilder

func (*MockClientMockRecorder) Stop

func (mr *MockClientMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop

type MockLogger

type MockLogger struct {
	// contains filtered or unexported fields
}

MockLogger is a mock of Logger interface

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...interface{})

Debug mocks base method

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(template string, args ...interface{})

Debugf mocks base method

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(template string, args ...interface{})

Errorf mocks base method

func (*MockLogger) Fatalf

func (m *MockLogger) Fatalf(template string, args ...interface{})

Fatalf mocks base method

func (*MockLogger) Infof

func (m *MockLogger) Infof(template string, args ...interface{})

Infof mocks base method

func (*MockLogger) Warnf

func (m *MockLogger) Warnf(template string, args ...interface{})

Warnf mocks base method

type MockLoggerMockRecorder

type MockLoggerMockRecorder struct {
	// contains filtered or unexported fields
}

MockLoggerMockRecorder is the mock recorder for MockLogger

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(args ...interface{}) *gomock.Call

Debug indicates an expected call of Debug

func (*MockLoggerMockRecorder) Debugf

func (mr *MockLoggerMockRecorder) Debugf(template interface{}, args ...interface{}) *gomock.Call

Debugf indicates an expected call of Debugf

func (*MockLoggerMockRecorder) Errorf

func (mr *MockLoggerMockRecorder) Errorf(template interface{}, args ...interface{}) *gomock.Call

Errorf indicates an expected call of Errorf

func (*MockLoggerMockRecorder) Fatalf

func (mr *MockLoggerMockRecorder) Fatalf(template interface{}, args ...interface{}) *gomock.Call

Fatalf indicates an expected call of Fatalf

func (*MockLoggerMockRecorder) Infof

func (mr *MockLoggerMockRecorder) Infof(template interface{}, args ...interface{}) *gomock.Call

Infof indicates an expected call of Infof

func (*MockLoggerMockRecorder) Warnf

func (mr *MockLoggerMockRecorder) Warnf(template interface{}, args ...interface{}) *gomock.Call

Warnf indicates an expected call of Warnf

type MockOrderSender

type MockOrderSender struct {
	// contains filtered or unexported fields
}

MockOrderSender is a mock of OrderSender interface

func NewMockOrderSender

func NewMockOrderSender(ctrl *gomock.Controller) *MockOrderSender

NewMockOrderSender creates a new mock instance

func (*MockOrderSender) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockOrderSender) Send

func (m *MockOrderSender) Send(ctx context.Context, orders []proto.PlayerOrder, debugMsg string) (*proto.OrderResponse, error)

Send mocks base method

type MockOrderSenderMockRecorder

type MockOrderSenderMockRecorder struct {
	// contains filtered or unexported fields
}

MockOrderSenderMockRecorder is the mock recorder for MockOrderSender

func (*MockOrderSenderMockRecorder) Send

func (mr *MockOrderSenderMockRecorder) Send(ctx, orders, debugMsg interface{}) *gomock.Call

Send indicates an expected call of Send

type OrderSender

type OrderSender interface {
	Send(ctx context.Context, orders []proto.PlayerOrder, debugMsg string) (*proto.OrderResponse, error)
}

Directories

Path Synopsis
Package coach is a generated GoMock package.
Package coach is a generated GoMock package.
bot
Package proto is a generated GoMock package.
Package proto is a generated GoMock package.

Jump to

Keyboard shortcuts

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