API documentation¶
-
class
pyrts.server.Action[source]¶ Bases:
objectClass containing the actions accepted by MicroRTS. Variable names indicate their meaning and integer values are used in the JSON serialization.
-
class
pyrts.server.Direction[source]¶ Bases:
objectClass containing directions, as accepted by MicroRTS in their action parameters. Variable names indicate their meaning and integer values are used in the JSON serialization.
-
class
pyrts.server.Server(player_id, logging_level=50)[source]¶ Bases:
objectPython implementation of a MicroRTS server, which communicates with MicroRTS via a network socket by sending actions and receiving states in the JSON format. This class should be used as the base class for other agents who which to interact with MicroRTS.
-
abstract
get_action(state, gameover)[source]¶ Send a list of actions to MicroRTS, given a state. Override this in the super class.
Be aware that, if gameover = True, the action provided will not be processed by MicroRTS.
-
get_available_actions_by_type_name(unit_type_table, type_name)[source]¶ Given the unit type and the unit type table, return a complete list of the possible actions that unit can perform
-
get_busy_units(state)[source]¶ Get a list of the units that are currently busy performing an action
- Parameters
state – [description]
- Returns
[description]
-
get_resource_usage_from_actions(actions)[source]¶ From a list of actions, sum the cost of the actions
-
get_resource_usage_from_state(state)[source]¶ How many resources are currently being used to build units
-
get_resources_for_player(state, for_player=None)[source]¶ Get the number of resources the player currently has available
-
get_unit_type_table()[source]¶ Returns the unit type table, which describes the environment
- Returns
[description]
-
get_valid_action_positions_for_state(state)[source]¶ Returns a tuple containing the following: invalid_move_positions - a set of all the positions that cannot be moved into valid_harvest_positions - a set of all the resource locations valid_base_positions - a set of the positions of bases on the current players team valid_attack_positions - a set of the positions that can be attacked
These positions can be cross-referenced with possible actions that units can perform, to make sure no invalid actions are sent to the environment
-
get_valid_actions_for_unit(unit, available_actions, valid_positions)[source]¶ Get the actions that are valid for a unit to perform.
An action is INVALID if the action cannot be performed in the environment.
For example, if the action is MOVE(left) but the position to the left of the unit is blocked
-
start(start_microrts=False, microrts_properties=None)[source]¶ Start the MicroRTS server.
- Parameters
start_microrts (bool, optional) – whether to also start a MicroRTS instance along with the server. Be aware that, in order to spawn a java subprocess that will start MicroRTS, the MICRORTSPATH environment variable must be set, containing the path to the directory with the necessary libraries to start MicroRTS, as well as MicroRTS class files. Defaults to False
microrts_properties (str, optional) – path to a properties file, which will be read by MicroRTS -f flag, defaults to None
-
abstract