Skip to content

Commit

Permalink
style: autoformatting
Browse files Browse the repository at this point in the history
Some more docs converting
  • Loading branch information
raspersc2 committed Dec 30, 2024
1 parent 4143556 commit 2a269d5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 138 deletions.
36 changes: 18 additions & 18 deletions src/ares/behaviors/maneuver_recipes/dropship_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ def pickup_and_transport_cargo(
success_at_distance: float = 2.0,
) -> CombatManeuver:
"""
This is similar to `pickup_transport_and_drop_units`
But DOES NOT drop off the units
This is similar to `pickup_transport_and_drop_units`
But DOES NOT drop off the units
WARNING: Ensure `units_to_transport` are not already near
the dropoff point, or this might cause an infinite cycle.
WARNING: Ensure `units_to_transport` are not already near
the dropoff point, or this might cause an infinite cycle.
Parameters:
unit: The medivac, prism, or overlord.
units_to_transport: Units to be transported, can be empty
if they are already in the dropship cargo.
air_grid: The airgrid for dropship pathing.
target: The destination for cargo drop.
should_drop_units: Whether to drop units when reaching the destination.
Defaults to True
keep_dropship_safe: If set to True, the dropship will be
kept safe if no other tasks are present. Defaults to True.
cargo_switch_to_role: Switch the unit's role when picked up, useful for
task readiness after drop. Defaults to None.
success_at_distance: The behavior is complete when the unit is within
this distance from `target`. Defaults to 2.0.
Parameters:
unit: The medivac, prism, or overlord.
units_to_transport: Units to be transported, can be empty
if they are already in the dropship cargo.
air_grid: The airgrid for dropship pathing.
target: The destination for cargo drop.
should_drop_units: Whether to drop units when reaching the destination.
Defaults to True
keep_dropship_safe: If set to True, the dropship will be
kept safe if no other tasks are present. Defaults to True.
cargo_switch_to_role: Switch the unit's role when picked up, useful for
task readiness after drop. Defaults to None.
success_at_distance: The behavior is complete when the unit is within
this distance from `target`. Defaults to 2.0.
"""
maneuver: CombatManeuver = CombatManeuver()
Expand Down
19 changes: 8 additions & 11 deletions src/ares/managers/manager_mediator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Enable cross manager communication.
"""
"""Enable cross manager communication."""

from abc import ABCMeta, abstractmethod
from typing import (
Expand All @@ -9,7 +7,6 @@
Callable,
DefaultDict,
Dict,
List,
Optional,
Set,
Tuple,
Expand Down Expand Up @@ -76,7 +73,7 @@ class ManagerMediator(IManagerMediator):
def __init__(self) -> None:
self.managers: Dict[str, "Manager"] = {} # noqa

def add_managers(self, managers: List["Manager"]) -> None: # noqa
def add_managers(self, managers: list["Manager"]) -> None: # noqa
"""Generate manager dictionary.
Parameters:
Expand Down Expand Up @@ -769,7 +766,7 @@ def find_low_priority_path(self, **kwargs) -> list[Point2]:
**kwargs,
)

def find_lowest_cost_points(self, **kwargs) -> List[Point2]:
def find_lowest_cost_points(self, **kwargs) -> list[Point2]:
"""Find the point(s) with the lowest cost within `radius` from `from_pos`.
PathManager
Expand Down Expand Up @@ -1038,7 +1035,7 @@ def get_priority_ground_avoidance_grid(self) -> np.ndarray:
)

@property
def get_whole_map_array(self) -> List[List[int]]:
def get_whole_map_array(self) -> list[list[int]]:
"""Get the list containing every point on the map.
PathManager
Expand Down Expand Up @@ -1415,7 +1412,7 @@ def building_position_blocked_by_burrowed_unit(self, **kwargs) -> Optional[Point
**kwargs,
)

def get_behind_mineral_positions(self, **kwargs) -> List[Point2]:
def get_behind_mineral_positions(self, **kwargs) -> list[Point2]:
"""Finds 3 spots behind the mineral line
This is useful for building structures out of typical cannon range.
Expand Down Expand Up @@ -1614,7 +1611,7 @@ def get_ol_spot_near_enemy_nat(self) -> Point2:
)

@property
def get_ol_spots(self) -> List[Point2]:
def get_ol_spots(self) -> list[Point2]:
"""High ground Overlord hiding spots.
TerrainManager
Expand All @@ -1629,7 +1626,7 @@ def get_ol_spots(self) -> List[Point2]:
)

@property
def get_own_expansions(self) -> List[Tuple[Point2, float]]:
def get_own_expansions(self) -> list[Tuple[Point2, float]]:
"""Get the expansions.
TerrainManager
Expand Down Expand Up @@ -1871,7 +1868,7 @@ def get_enemy_tree(self) -> KDTree:

def get_units_in_range(
self, **kwargs
) -> Union[Dict[Union[int, Tuple[float, float]], Units], List[Units]]:
) -> Union[Dict[Union[int, Tuple[float, float]], Units], list[Units]]:
"""Get units in range of other units or points.
UnitMemoryManager
Expand Down
144 changes: 35 additions & 109 deletions src/ares/managers/path_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def find_path_next_point(
sensitivity: int = 5,
smoothing: bool = False,
sense_danger: bool = True,
danger_distance: int = 20.,
danger_distance: int = 20.0,
danger_threshold: float = 5.0,
) -> Point2:
"""Find the next point in a path.
Expand Down Expand Up @@ -575,18 +575,13 @@ def is_position_safe(
) -> bool:
"""Check if the given position is considered dangerous.
Parameters
----------
grid :
The grid to evaluate safety on.
position :
The position to check the safety of.
weight_safety_limit :
The maximum value the point can have on the grid to be considered safe.
Parameters:
grid: The grid to evaluate safety on.
position: The position to check the safety of.
weight_safety_limit: The maximum value the point can
have on the grid to be considered safe.
Returns
-------
bool:
Returns:
True if the position is considered safe, False otherwise.
"""
Expand All @@ -595,14 +590,8 @@ def is_position_safe(
def reset_grids(self, iteration: int) -> None:
"""Get fresh grids so that the influence can be updated.
Parameters
----------
iteration :
The current game iteration.
Returns
-------
Parameters:
iteration: The current game iteration.
"""
self.air_grid = self._cached_clean_air_grid.copy()
self.air_vs_ground_grid = self._cached_clean_air_vs_ground_grid.copy()
Expand All @@ -625,16 +614,9 @@ def add_unit_influence(self, enemy: Unit) -> None:
"""Add influence to the relevant grid.
Called from _prepare_units.
Work in progress.
Parameters
----------
enemy :
The enemy unit to add the influence of.
Returns
-------
Parameters:
enemy: The enemy unit to add the influence of.
"""

if not enemy.is_ready and not enemy.is_cloaked and not enemy.is_burrowed:
Expand All @@ -646,14 +628,8 @@ def add_structure_influence(self, enemy: Unit) -> None:
Called from _prepare_units.
Parameters
----------
enemy :
The enemy structure to add the influence of.
Returns
-------
Parameters:
enemy: The enemy structure to add the influence of.
"""
# these will expire out of our vision, don't add to grid
if enemy.type_id == UnitID.AUTOTURRET and enemy.is_snapshot:
Expand All @@ -662,12 +638,7 @@ def add_structure_influence(self, enemy: Unit) -> None:
self._add_structure_influence(enemy)

def _add_effects(self) -> None:
"""Add effects influence to map.
Returns
-------
"""
"""Add effects influence to map."""
effect_values: Dict = self.config[PATHING][EFFECTS]

for effect in self.ai.state.effects:
Expand Down Expand Up @@ -795,14 +766,8 @@ def _add_effects(self) -> None:
def _add_structure_influence(self, structure: Unit) -> None:
"""Add structure influence to map.
Parameters
----------
structure :
The structure to add the influence of.
Returns
-------
Parameters:
structure: The structure to add the influence of.
"""
if structure.type_id == UnitID.PHOTONCANNON:
(
Expand Down Expand Up @@ -886,14 +851,8 @@ def _add_structure_influence(self, structure: Unit) -> None:
def _add_unit_influence(self, unit: Unit) -> None:
"""Add unit influence to maps.
Parameters
----------
unit :
The unit to add the influence of.
Returns
-------
Parameters:
unit: The unit to add the influence of.
"""
if unit.type_id in WEIGHT_COSTS:
weight_values = WEIGHT_COSTS[unit.type_id]
Expand Down Expand Up @@ -993,16 +952,9 @@ def _add_cost_to_all_grids(self, unit: Unit, weight_values: Dict) -> None:
TODO: Could perhaps be renamed as misleading name, cost is added to the main
grids but not all
Parameters
----------
unit :
Unit to add the costs of.
weight_values :
Dictionary containing the weights of units.
Returns
-------
Parameters:
unit: Unit to add the costs of.
weight_values: Dictionary containing the weights of units.
"""
if unit.type_id == UnitID.AUTOTURRET:
(
Expand Down Expand Up @@ -1075,37 +1027,25 @@ def _add_cost_to_all_grids(self, unit: Unit, weight_values: Dict) -> None:
def _add_delayed_effect(
self,
position: Point2,
effect_dict: Dict,
effect_dict: dict,
) -> None:
"""Add an effect that we know exists but is not in the game observation.
Parameters
----------
position :
Where to add the effect.
effect_dict :
Currently tracked effects.
Returns
-------
Parameters:
position: Where to add the effect.
effect_dict: Currently tracked effects.
"""
# no record of this yet
if position not in effect_dict:
effect_dict[position] = self.ai.state.game_loop

def _clear_delayed_effects(self, effect_dict: Dict, effect_duration: int) -> None:
def _clear_delayed_effects(self, effect_dict: dict, effect_duration: int) -> None:
"""Remove delayed effects when they've expired.
Parameters
----------
effect_dict :
Currently tracked effects.
effect_duration :
How long the effect lasts.
Returns
-------
Parameters:
effect_dict: Currently tracked effects.
effect_duration: How long the effect lasts.
"""
current_frame: int = self.ai.state.game_loop
Expand All @@ -1127,20 +1067,11 @@ def _add_delayed_effects_to_grids(
) -> None:
"""Add the costs of the delayed effects to the grids.
Parameters
----------
cost :
Cost of the effect.
radius :
How far around the center position the cost should be added.
effect_dict :
Currently tracked effects.
react_on_frame :
When units should begin reacting to this effect.
Returns
-------
Parameters:
cost: Cost of the effect.
radius: How far around the center position the cost should be added.
effect_dict: Currently tracked effects.
react_on_frame: When units should begin reacting to this effect.
"""
current_frame: int = self.ai.state.game_loop
for position, frame_commenced in effect_dict.items():
Expand Down Expand Up @@ -1170,12 +1101,7 @@ def _add_delayed_effects_to_grids(
)

def _update_delayed_effects(self) -> None:
"""Update manually tracked effects.
Returns
-------
"""
"""Update manually tracked effects."""
# these effects disappear from the observation, so we have to manually add them
self._add_delayed_effects_to_grids(
cost=self.config[PATHING][EFFECTS][CORROSIVE_BILE][COST],
Expand Down

0 comments on commit 2a269d5

Please sign in to comment.