diplomacy.engine.power¶
Power
- Contains the power object representing a power in the game
-
class
diplomacy.engine.power.
Power
(game=None, name=None, **kwargs)[source]¶ Bases:
diplomacy.utils.jsonable.Jsonable
Power Class
Properties:
- abbrev - Contains the abbrev of the power (i.e. the first letter of the power name) (e.g. ‘F’ for FRANCE)
- adjust - List of pending adjustment orders (e.g. [‘A PAR B’, ‘A PAR R MAR’, ‘A MAR D’, ‘WAIVE’])
- centers - Contains the list of supply centers currently controlled by the power [‘MOS’, ‘SEV’, ‘STP’]
- civil_disorder - Bool flag to indicate that the power has been put in CIVIL_DISORDER (e.g. True or False)
- controller - Sorted dictionary mapping timestamp to controller (either dummy or a user ID) who takes control of power at this timestamp.
- game - Contains a reference to the game object
- goner - Boolean to indicate that this power doesn’t control any SCs any more (e.g. True or False)
- homes - Contains a list of homes supply centers (where you can build) e.g. [‘PAR’, ‘MAR’, … ] or None if empty
- influence - Contains a list of locations influenced by this power Note: To influence a location, the power must have visited it last. e.g [‘PAR’, ‘MAR’, … ]
- name - Contains the name of the power (e.g. ‘FRANCE’)
- orders - Contains a dictionary of units and their orders.
For NO_CHECK games, unit is ‘ORDER 1’, ‘ORDER 2’, …
- e.g. {‘A PAR’: ‘- MAR’ } or {‘ORDER 1’: ‘A PAR - MAR’, ‘ORDER 2’: ‘…’, … }
- Can also be {‘REORDER 1’: ‘A PAR - MAR’, ‘INVALID 1’: ‘A PAR - MAR’, … } after validation
- retreats - Contains the list of units that need to retreat with their possible retreat locations (e.g. {‘A PAR’: [‘MAR’, ‘BER’]})
- role - Power type (observer, omniscient, player or server power). Either the power name (for a player power) or a value in diplomacy.utils.strings.ALL_ROLE_TYPES
- tokens - Only for server power: set of tokens of current power controlled (if not None).
- units - Contains the list of units (e.g. [‘A PAR’, ‘A MAR’, …]
- vote - Only for omniscient, player and server power: power vote (‘yes’, ‘no’ or ‘neutral’).
-
reinit
(include_flags=6)[source]¶ Performs a reinitialization of some of the parameters
Parameters: include_flags – Bit mask to indicate which params to reset (bit 1 = orders, 2 = persistent, 4 = transient) Returns: None
-
static
compare
(power_1, power_2)[source]¶ Comparator object - Compares two Power objects
Parameters: - power_1 – The first Power object to compare
- power_2 – The second Power object to compare
Returns: 1 if self is greater, -1 if other is greater, 0 if they are equal
-
initialize
(game)[source]¶ Initializes a game and resets home, centers and units
Parameters: game (diplomacy.Game) – The game to use for initialization
-
merge
(other_power)[source]¶ Transfer all units, centers, and homes of the other_power to this power
Parameters: other_power – The other power (will be empty after the merge)
-
is_dummy
()[source]¶ Indicates if the power is a dummy
Returns: Boolean flag to indicate if the power is a dummy
-
is_eliminated
()[source]¶ Returns a flag to show if player is eliminated
Returns: If the current power is eliminated
-
moves_submitted
()[source]¶ Returns a boolean to indicate if moves has been submitted
Returns: 1 if not in Movement phase, or orders submitted, or no more units lefts
-
does_not_wait
()[source]¶ (Network Method) Return True if this power does not wait (ie. if we could already process orders of this power).
-
update_controller
(username, timestamp)[source]¶ (Network Method) Update controller with given username and timestamp.
-
set_controlled
(username)[source]¶ (Network Method) Control power with given username. Username may be None (meaning no controller).
-
get_controller
()[source]¶ (Network Method) Return current power controller name (‘dummy’ if power is not controlled).
-
get_controller_timestamp
()[source]¶ (Network Method) Return timestamp when current controller took control of this power.