Package horizons :: Package ai :: Package aiplayer :: Package combat :: Module unitmanager :: Class UnitManager
[hide private]
[frames] | no frames]

Class UnitManager

source code

UnitManager objects is responsible for handling units in game. 1.Grouping combat ships into easy to handle fleets, 2.Ship filtering. 3.Distributing ships for missions when requested by other managers.

Instance Methods [hide private]
 
__init__(self, owner) source code
 
__init(self, owner) source code
 
get_ships(self, filtering_rules=None) source code
 
remove_unit(self, ship) source code
 
save(self, db) source code
 
_load(self, db, owner) source code
 
create_fleet(self, ships, destroy_callback=None) source code
 
destroy_fleet(self, fleet) source code
 
check_for_dead_fleets(self) source code
 
_is_fighter(self)
Rule stating that ship is a fighting ship, but not a pirate ship.
source code
 
_is_pirate(self, ship) source code
 
_is_worker(self) source code
 
_ship_type_rule(self, ship_types)
Rule stating that ship is any of ship_types instances
source code
 
_not_owned_rule(self)
Rule stating that ship is another player's ship
source code
 
_hostile_rule(self)
Rule selecting only hostile ships
source code
 
_ship_state_rule(self, state_dict, ship_states)
Rule stating that ship has to be in any of given states.
source code
 
_ship_not_in_fleet(self, ship)
Rule stating that ship is not assigned to any of the fleets.
source code
 
_selectable_rule(self)
Rule stating that ship has to be selectable.
source code
 
filter_ships(self, ships, rules)
This method allows for flexible ship filtering.
source code
 
find_ships_near_group(self, ship_group, radius) source code
 
tick(self) source code
 
get_player_islands(self, player) source code
 
get_player_ships(self, player) source code
 
get_warehouse_point(self, settlement)
Return point of given settlement's warehouse.
source code
 
get_warehouse_area(self, settlement, range=10) source code
Class Methods [hide private]
 
load(cls, db, owner) source code
 
get_lowest_hp_ship(cls, ship_group) source code
 
get_closest_ships_for_each(cls, ship_group, enemies)
For each ship in ship_group return an index of ship from enemies that is the closest to given ship.
source code
 
get_best_targets_for_each(cls, ship_group, enemies)
For each ship in ship_group return an index of ship from enemies that is the closest to given ship.
source code
float
calculate_power_balance(cls, ship_group, enemy_ship_group)
Calculate power balance between two groups of ships.
source code
float
calculate_ship_dispersion(cls, ship_group)
There are many solutions to solve the problem of caculating ship_group dispersion efficiently.
source code
Class Variables [hide private]
  log = logging.getLogger("ai.aiplayer.unitmanager")
Method Details [hide private]

filter_ships(self, ships, rules)

source code 

This method allows for flexible ship filtering. usage: other_ships = unit_manager.filter_ships(other_ships, [_not_owned_rule(), _ship_type_rule([PirateShip])])

Parameters:
  • ships (iterable) - iterable of ships to filter
  • rules (iterable of lambda(ship) or single lambda(ship)) - conditions each ship has to meet (AND)

get_closest_ships_for_each(cls, ship_group, enemies)
Class Method

source code 

For each ship in ship_group return an index of ship from enemies that is the closest to given ship. For example ship_group=[A, B, C] , enemies = [X, Y, Z], could return [(A,X), (B,Y), (C,Y)] if X was the closest to A and Y was the closest ship to both B and C

get_best_targets_for_each(cls, ship_group, enemies)
Class Method

source code 

For each ship in ship_group return an index of ship from enemies that is the closest to given ship. For example ship_group=[A, B, C] , enemies = [X, Y, Z], could return [(A,X), (B,Y), (C,Y)] if X was the closest to A and Y was the closest ship to both B and C

calculate_power_balance(cls, ship_group, enemy_ship_group)
Class Method

source code 

Calculate power balance between two groups of ships.

Parameters:
  • ship_group (Iterable) - iterable of ships to be counted as a numerator
  • enemy_ship_group (Iterable) - iterable of ships to be counted as denominator
Returns: float
power balance between two ship groups

calculate_ship_dispersion(cls, ship_group)
Class Method

source code 

There are many solutions to solve the problem of caculating ship_group dispersion efficiently. We generally care about computing that in linear time, rather than having accurate numbers in O(n^2). We settle for a diagonal of a bounding box for the whole group.

Returns: float
dispersion factor

get_warehouse_point(self, settlement)

source code 

Return point of given settlement's warehouse. Be careful with sailing directly to given warehouse