pyagar.client

This module contains the Client class.

class pyagar.client.Client(nick, region='EU-London', party=False)[source]

The client.

Manages the connection, receives the data from the server and sends back any command requested by the player.

connect()[source]

Connects to the server.

create_party()[source]

Create a new party.

eject()[source]

Sends the mass eject command.

classmethod get_regions()[source]

Request the list of regions.

get_server()[source]

Requests a new server and token.

move(x, y)[source]

Sends the movement command.

read()[source]

Read, decode and queue data packets from the server.

spawn()[source]

Sends the spawn command.

spectate()[source]

Initiates the spectator mode.

split()[source]

Sends the split cell command.

pyagar.client.build_request(set_header)[source]

Build a handshake request to send to the server.

Return the key which must be passed to check_response().

pyagar.cmdline

Provides the cmdline facility.

pyagar.cmdline.pyagar(argv=None)[source]

pyagar cli interface.

pyagar.cmdline.pyagar_parser()[source]

Generates the argument parser.

pyagar.controller

Some very simple bots.

class pyagar.control.Center(client)[source]

Go to the center.

class pyagar.control.Closer(client)[source]

Go to the closer “non-virus” cell, no matter the type.

class pyagar.control.Controller(client)[source]

All bots should inherit from this class.

do_move()[source]

Make a movement.

edible

You can eat cells 10% smaller than you.

get_movement()[source]

The method that subclasses must implement.

get_name()[source]

Returns the name of this bot.

opponents

Return list of other cells.

player

Returns the player main cell. None if not exists.

predators

Cells that can eat me.

run()[source]

The main loop of the bot.

viruses

Returns a list of visible viruses.

class pyagar.control.EatWhenNoPredators(client)[source]

Only eats when all visible cells are smaller then itself.

class pyagar.control.Escape(client)[source]

Escape from bigger opponents.

compound_escape_vector(vectors, cells)[source]

Returns the sum of all vectors.

static escape_vector(player, cell)[source]

Movement to escape from a cell.

class pyagar.control.Greedy(client)[source]

Only wants to eat.

class pyagar.control.Movement(x, y)
x

Alias for field number 0

y

Alias for field number 1

pyagar.log

Contains the logger.

pyagar.messages

Protocol implementation.

class pyagar.messages.BaseMSG(buf, offset=0)[source]

All messages inherits from this class.

Contains utility methods for unpack the data.

get(ctype)[source]

Unpack the given ctype and update the offset.

getFloat32()[source]

Unpack an FLOAT32.

getFloat64()[source]

Unpack an FLOAT64.

getInt16()[source]

Unpack an INT16.

getInt32()[source]

Unpack an INT32.

getInt64()[source]

Unpack an INT64.

getInt8()[source]

Unpack an INT8.

getUint16()[source]

Unpack an UINT16.

getUint32()[source]

Unpack an UINT32.

getUint64()[source]

Unpack an UINT64.

getUint8()[source]

Unpack an UINT8.

parse()[source]

This method must be implemented in the message subclass.

string(ctype='H')[source]

Unpack a string.

class pyagar.messages.Camera(x, y, zoom)
x

Alias for field number 0

y

Alias for field number 1

zoom

Alias for field number 2

class pyagar.messages.CameraPosition(buf, offset=0)[source]

Change in the camera position and/or the zoom.

Only received in Spectate mode.

parse()[source]

Unpacks the data.

class pyagar.messages.Cell(id, x, y, size, color, is_virus, name)
color

Alias for field number 4

id

Alias for field number 0

is_virus

Alias for field number 5

name

Alias for field number 6

size

Alias for field number 3

x

Alias for field number 1

y

Alias for field number 2

class pyagar.messages.Dissapear(id)
id

Alias for field number 0

class pyagar.messages.Eat(eater, eatee)
eatee

Alias for field number 1

eater

Alias for field number 0

class pyagar.messages.Leaderboard(buf, offset=0)[source]

The Leaderboard.

The top bigger cells in descending order.

This message is only received in FFA and Experimental mode.

parse()[source]

Unpacks the data.

class pyagar.messages.MSG(buf, offset=0)[source]

All messages.

This class identify the specific message type and calls the proper parser.

parse()[source]

Unpacks the message identifier and instantiate the parser.

class pyagar.messages.MSGType[source]

This enum contains the identifier of each message along with the name of the class which parses it.

cls

Returns the parser class of this enum.

class pyagar.messages.Player(id, name)
id

Alias for field number 0

name

Alias for field number 1

class pyagar.messages.PlayerCell(buf, offset=0)[source]

ID of the player.

parse()[source]

Unpacks the data.

class pyagar.messages.PlayerID(id)
id

Alias for field number 0

class pyagar.messages.ResetSomething(buf, offset=0)[source]

This message is present in the code but never seen.

parse()[source]

Unpacks the data.

class pyagar.messages.Screen(x1, y1, x2, y2)
x1

Alias for field number 0

x2

Alias for field number 2

y1

Alias for field number 1

y2

Alias for field number 3

class pyagar.messages.ScreenAndCamera(buf, offset=0)[source]

Screen and Camera position, all in one.

This message is the first message in the stream.

parse()[source]

Unpacks the data.

class pyagar.messages.SetQARA(buf, offset=0)[source]

This message is present in the code but never seen.

parse()[source]

Unpacks the data.

class pyagar.messages.Status(buf, offset=0)[source]

The status of the stage.

Who eats who, what is visible, what dissapears...

parse()[source]

Unpacks the data.

class pyagar.messages.TeamsScore(buf, offset=0)[source]

The TeamScore.

The percent of mass of each team.

This message is only received in the Team mode.

parse()[source]

Unpacks the data.

pyagar.utils

Non categorized stuff.

class pyagar.utils.GameReplay(filename)[source]

Replay the messages saved with GameplaySaver.

class pyagar.utils.GameplaySaver(filename)[source]

Store the gameplay messages in a file with a timestamp.

class pyagar.utils.Output[source]

Prints every message received.

run()[source]

Logs all everything.

pyagar.utils.hub(src, *dsts)[source]

Broadcasts msgs from src.messages to all dsts.messages.

pyagar.utils.print_regions(regions)[source]

Prints a pretty table with the region data.

pyagar.visual

Provides the default visualizer.

class pyagar.visual.Visualizer(client, view_only=False, hardware=True)[source]

SDL based visualizer.

refresh()[source]

Draw the current status of the game in window.

The overall process is:

  1. The server send information about the board size and status.

1.1. We keep the information about the board in gamescreen.

  1. We draw the game in the texture stage. This texture can be smaller than gamescreen.
  2. The rectangle camera (in game coordinates) is copied from stage to window.
static remap(o_val, o_min, o_max, n_min, n_max)[source]

Map a value from one range to another.

stage = None

The texture we draw to.

tr_game2stage_coords(x, y)[source]

Translate from game cords to stage coordinates.

tr_game2stage_size(size)[source]

Translate a size (in pixels) from game to stage.

tr_win2game_coords(x, y)[source]

Translate from window coords to game coordinates.

window = None

The window where we show the game.

pyagar.visual.asrt(code)[source]

If there is an error on a SDL call raise an exception with the error description.