Unit

class games.pirates.unit.Unit

Bases: games.pirates.game_object.GameObject

The class representing the Unit in the Pirates game.

A unit group in the game. This may consist of a ship and any number of crew.

property acted

Whether this Unit has performed its action this turn.

Type

bool

attack(tile: games.pirates.tile.Tile, target: str) → bool

Attacks either the ‘crew’ or ‘ship’ on a Tile in range.

Parameters
  • tile (games.pirates.tile.Tile) – The Tile to attack.

  • target ('crew' or 'ship') – Whether to attack ‘crew’ or ‘ship’. Crew deal damage to crew and ships deal damage to ships. Consumes any remaining moves.

Returns

True if successfully attacked, False otherwise.

Return type

bool

bury(amount: int) → bool

Buries gold on this Unit’s Tile. Gold must be a certain distance away for it to get interest (Game.minInterestDistance).

Parameters

amount (int) – How much gold this Unit should bury. Amounts <= 0 will bury as much as possible.

Returns

True if successfully buried, False otherwise.

Return type

bool

property crew

How many crew are on this Tile. This number will always be <= crewHealth.

Type

int

property crew_health

How much total health the crew on this Tile have.

Type

int

deposit(amount: int = 0) → bool

Puts gold into an adjacent Port. If that Port is the Player’s port, the gold is added to that Player. If that Port is owned by merchants, it adds to that Port’s investment.

Parameters

amount (int) – The amount of gold to deposit. Amounts <= 0 will deposit all the gold on this Unit.

Returns

True if successfully deposited, False otherwise.

Return type

bool

dig(amount: int = 0) → bool

Digs up gold on this Unit’s Tile.

Parameters

amount (int) – How much gold this Unit should take. Amounts <= 0 will dig up as much as possible.

Returns

True if successfully dug up, False otherwise.

Return type

bool

property game_object_name

String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.

Type

str

property gold

How much gold this Unit is carrying.

Type

int

property id

A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.

Type

str

log(message: str) → None

Adds a message to this GameObject’s logs. Intended for your own debugging purposes, as strings stored here are saved in the gamelog.

Parameters

message (str) – A string to add to this GameObject’s log. Intended for debugging.

property logs

Any strings logged will be stored here. Intended for debugging.

Type

list[str]

move(tile: games.pirates.tile.Tile) → bool

Moves this Unit from its current Tile to an adjacent Tile. If this Unit merges with another one, the other Unit will be destroyed and its tile will be set to None. Make sure to check that your Unit’s tile is not None before doing things with it.

Parameters

tile (games.pirates.tile.Tile) – The Tile this Unit should move to.

Returns

True if it moved, False otherwise.

Return type

bool

property moves

How many more times this Unit may move this turn.

Type

int

property owner

The Player that owns and can control this Unit, or None if the Unit is neutral.

Type

games.pirates.player.Player or None

property path

(Merchants only) The path this Unit will follow. The first element is the Tile this Unit will move to next.

Type

list[games.pirates.tile.Tile]

rest() → bool

Regenerates this Unit’s health. Must be used in range of a port.

Returns

True if successfully rested, False otherwise.

Return type

bool

property ship_health

If a ship is on this Tile, how much health it has remaining. 0 for no ship.

Type

int

split(tile: games.pirates.tile.Tile, amount: int = 1, gold: int = 0) → bool

Moves a number of crew from this Unit to the given Tile. This will consume a move from those crew.

Parameters
  • tile (games.pirates.tile.Tile) – The Tile to move the crew to.

  • amount (int) – The number of crew to move onto that Tile. Amount <= 0 will move all the crew to that Tile.

  • gold (int) – The amount of gold the crew should take with them. Gold < 0 will move all the gold to that Tile.

Returns

True if successfully split, False otherwise.

Return type

bool

property stun_turns

(Merchants only) The number of turns this merchant ship won’t be able to move. They will still attack. Merchant ships are stunned when they’re attacked.

Type

int

property target_port

(Merchants only) The Port this Unit is moving to.

Type

games.pirates.port.Port or None

property tile

The Tile this Unit is on.

Type

games.pirates.tile.Tile or None

withdraw(amount: int = 0) → bool

Takes gold from the Player. You can only withdraw from your own Port.

Parameters

amount (int) – The amount of gold to withdraw. Amounts <= 0 will withdraw everything.

Returns

True if successfully withdrawn, False otherwise.

Return type

bool