Skip to content

Commit

Permalink
fixed more linitng errors added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
FredNoonienSingh committed Jan 17, 2025
1 parent 32fe2f2 commit 8543b81
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 56 deletions.
27 changes: 26 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
{
"cSpell.words": [
"Baumeister",
"burnysc",
"chronoboost",
"csvfile",
"CYBERNETICSCORE",
"distrubute",
"hackcheating",
"Harstems",
"linalg",
"ndarray",
"opponentid",
"pathing",
"PHOTONCANNON",
"Premove",
"PRIO",
"Protoss",
"proyimity",
"ROBO",
"robofacilities",
"stargates"
"speedmining",
"STARGATE",
"stargates",
"townhall",
"townhalls",
"unittype",
"Utilityclass",
"vespene",
"warpin",
"WARPPRISM",
"warprism"
]
}
14 changes: 8 additions & 6 deletions bot/HarstemsAunt/army_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ def retreat(self) -> None:
unit.position, self.retreat_pos, grid
)
)

#self.observer.retreat(self.units(UnitTypeId.OBSERVER), self.retreat_pos)

#TODO: #31 Regroup Units by Range
Expand Down Expand Up @@ -280,7 +279,7 @@ async def update(self, target:Union[Point2, Point3, Unit]):
shall be called every tick in main.py
"""
if not self.requested_units:
self.request_unit()
self.request_units()
#last_status: GroupStatus = self.status

# Move Units in Transit to Army_group:
Expand All @@ -294,13 +293,15 @@ async def update(self, target:Union[Point2, Point3, Unit]):
if Utils.in_proximity_to_point(unit, self.position, 2):
self.units_in_transit.remove(unit.tag)
self.unit_list.append(unit.tag)
await self.bot.chat_send(f"Army Group: {self.name} got reinforced by {unit.type_id}")
await self.bot.chat_send(f"Army Group: {self.name} \
got reinforced by {unit.type_id}")

# CHECK DEFEND POSITION
for townhall in self.bot.townhalls:
enemies_in_area = self.bot.enemy_units.closer_than(30, townhall)
if enemies_in_area:
supply_in_area = sum([self.bot.calculate_supply_cost(unit.type_id) for unit in enemies_in_area])
supply_in_area = sum([self.bot.calculate_supply_cost(unit.type_id) \
for unit in enemies_in_area])
if supply_in_area > 10:
self.defend(townhall)
self.status = GroupStatus.DEFENDING
Expand All @@ -310,11 +311,12 @@ async def update(self, target:Union[Point2, Point3, Unit]):
# CHECK RETREAT CONDITIONS
shield_condition = self.average_shield_percentage < .45
supply_condition = self.supply <= self.enemy_supply_in_proximity
if Utils.and_or(shield_condition, supply_condition) or len(self.units) < len(self.units_in_transit):
if Utils.and_or(shield_condition, supply_condition) \
or len(self.units) < len(self.units_in_transit):
self.retreat()
self.status = GroupStatus.RETREATING
return

#self.regroup()
await self.attack(target)
self.status = GroupStatus.ATTACKING
self.status = GroupStatus.ATTACKING
23 changes: 15 additions & 8 deletions bot/HarstemsAunt/build_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DOCSTRING to shut up the Linter """
# pylint: disable=C0103
from __future__ import annotations

from enum import Enum
Expand Down Expand Up @@ -37,8 +38,10 @@ def __new__(cls,type_id:UnitTypeId,position:Union[Point2,Point3,Unit]=None,\
Args:
type_id (UnitTypeId): type of structure or unit that needs to be build
position (Union[Point2,Point3,Unit], optional): position on which the structure will be build. Defaults to None.
worker_command (UnitCommand, optional): Worker Command after finishing the structure. Defaults to None.
position (Union[Point2,Point3,Unit], optional): position on which the \
structure will be build. Defaults to None.
worker_command (UnitCommand, optional): Worker Command after finishing the \
structure. Defaults to None.
Returns:
_type_: BuildInstruction
Expand All @@ -57,7 +60,8 @@ def __init__(self,type_id:UnitTypeId, position:Union[Point2,Point3,Unit],\
Args:
type_id (UnitTypeId): type of unit or structure
position (Union[Point2,Point3,Unit]): position on which the structure will be build
worker_command (UnitCommand, optional): Worker Command after finishing the structure. Defaults to None.
worker_command (UnitCommand, optional): Worker Command after finishing \
the structure. Defaults to None.
"""
self.type_id = type_id
self.position = position
Expand Down Expand Up @@ -89,7 +93,7 @@ def __repr__(self) -> str:
class BuildOrder:
""" Class containing the build order and methods connected with it
"""

def __init__(self, bot:BotAI, build:Build=Build.FOUR_GATE):
self.bot = bot
self.build = build
Expand All @@ -112,12 +116,14 @@ def instruction_list(self) -> List[BuildInstruction]:
minerals:Units = self.bot.expansion_locations_dict[self.bot.start_location].mineral_field
wall_buildings:list = list(self.bot.main_base_ramp.protoss_wall_buildings)
wall_pylon_pos:Point2 = self.bot.main_base_ramp.protoss_wall_pylon
tech_pylon_pos:Point2 = self.bot.start_location.towards(self.bot.start_location.furthest(minerals).position, 10)
tech_pylon_pos:Point2 = self.bot.start_location\
.towards(self.bot.start_location.furthest(minerals).position, 10)
angle_pylon_pos:Point2 = self.bot.start_location.towards(self.bot.game_info.map_center,10)
vespene_position_0:Point2 = self.bot.vespene_geyser.closer_than(12, start_pos)[0]
vespene_position_1:Point2 = self.bot.vespene_geyser.closer_than(12, start_pos)[1]

cannon_pylon_0: Point2 = self.bot.enemy_start_locations[0].towards(self.bot.game_info.map_center, 5)
cannon_pylon_0: Point2 = self.bot.enemy_start_locations[0]\
.towards(self.bot.game_info.map_center, 5)

FOUR_GATE = [
BuildInstruction(UnitTypeId.PYLON,wall_pylon_pos),
Expand Down Expand Up @@ -211,7 +217,8 @@ def add_constructed_structure(self, structure:UnitTypeId) -> None:
""" appends structure to constructed structures currently not in use """
self.constructed_structures.append(structure)

#TODO: Make this structure dependent -> return the last pylon not in Vision Pylons for any structure and a different pos for pylons
#TODO: Make this structure dependent -> return the last pylon not in \
# Vision Pylons for any structure and a different pos for pylons
def get_build_pos(self) -> Union[Point2, Point3, Unit]:
""" returns build pos
Expand Down Expand Up @@ -258,7 +265,7 @@ async def update(self):
(0.01, 0.20), color=(255,255,255), size=15)

def debug_build_pos(self, pos:Union[Point2, Point3]):
"""debug methode to show the current build pos """
"""debug method to show the current build pos """
z = self.bot.get_terrain_z_height(pos)+1
x,y = pos.x, pos.y
pos_3d = Point3((x,y,z))
Expand Down
8 changes: 5 additions & 3 deletions bot/HarstemsAunt/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""MainClass of the Bot handling"""

# pylint: disable=W0201
import os
import csv
import threading
Expand Down Expand Up @@ -180,7 +180,8 @@ async def on_step(self, iteration:int):
color = (0, 0, 255)
else:
color = (0, 255, 0)
self.client.debug_text_screen(f"{labels[i]}: {value}", (0, 0.025+(i*0.025)), color=color, size=20)
self.client.debug_text_screen(f"{labels[i]}: {value}", \
(0, 0.025+(i*0.025)), color=color, size=20)

threads: list = []
for i, sector in enumerate(self.map_sectors):
Expand All @@ -200,7 +201,8 @@ async def on_step(self, iteration:int):
self.macro.build_order.opponent_has_detection = True

if not self.macro.build_order.opponent_uses_cloak:
if [unit for unit in self.seen_enemies if (unit.is_cloaked and unit.can_attack) or (unit.is_burrowed and unit.can_attack)]:
if [unit for unit in self.seen_enemies if (unit.is_cloaked and unit.can_attack) \
or (unit.is_burrowed and unit.can_attack)]:
self.macro.build_order.opponent_uses_cloak = True
await self.chat_send("Stop hiding and fight like a honorable ... \
ähm... Robot?\ndo computers have honor ?")
Expand Down
106 changes: 96 additions & 10 deletions bot/HarstemsAunt/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Utility Module"""
# pylint: disable=C0411

import math
import numpy as np

Expand Down Expand Up @@ -50,7 +52,8 @@ def can_build_unit(bot:BotAI, unit_id:UnitTypeId) ->bool:
Returns:
bool: True if Bot can build unit
"""
return bot.can_afford(unit_id) and bot.can_feed(unit_id) and bot.tech_requirement_progress(unit_id)
return bot.can_afford(unit_id) and bot.can_feed(unit_id) \
and bot.tech_requirement_progress(unit_id)

@staticmethod
def can_research_upgrade(bot:BotAI,upgrade_id:UpgradeId)->bool:
Expand Down Expand Up @@ -115,47 +118,130 @@ def get_intersections(p0: Point2, r0: float, p1:Point2, r1:float) -> Iterable[Po

@staticmethod
def get_build_pos(bot:BotAI) -> Union[Point2, Point3, Unit]:
""" returns build_pos
Args:
bot (BotAI): instance of Bot
Returns:
Union[Point2, Point3, Unit]: Build Pos
"""
if not bot.structures(UnitTypeId.PYLON):
return bot.main_base_ramp.protoss_wall_pylon
elif not bot.structures(UnitTypeId.GATEWAY) and not bot.already_pending(UnitTypeId.GATEWAY):
return bot.main_base_ramp.protoss_wall_warpin
return bot.main_base_ramp.protoss_wall_warpin
else:
return bot.structures(UnitTypeId.NEXUS)[0].position3d.towards(bot.game_info.map_center, 5)
return bot.structures(UnitTypeId.NEXUS)[0]\
.position3d.towards(bot.game_info.map_center, 5)

@staticmethod
def get_warp_in_pos(bot:BotAI) -> Union[Point2, Point3, Unit]:
""" returns Warp in position
Args:
bot (BotAI): Instance of the Bot
Returns:
Union[Point2, Point3, Unit]: Warp in Pos
"""
if not bot.units(UnitTypeId.WARPPRISM):
if bot.supply_army > 10:
return bot.structures(UnitTypeId.PYLON).in_closest_distance_to_group([x for x in bot.units if x not in bot.workers])
return bot.structures(UnitTypeId.PYLON)\
.in_closest_distance_to_group([x for x in bot.units if x not in bot.workers])
else:
return bot.structures(UnitTypeId.PYLON).closest_to(bot.enemy_start_locations[0]).position.towards(bot.enemy_start_locations[0], distance=1, limit=False)
return bot.structures(UnitTypeId.PYLON)\
.closest_to(bot.enemy_start_locations[0])\
.position.towards(bot.enemy_start_locations[0], distance=1, limit=False)
else:
if bot.enemy_units:
active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_units.center)
else:
active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_start_locations[0])
active_prism = bot.units(UnitTypeId.WARPPRISM)\
.closest_to(bot.enemy_start_locations[0])
return active_prism.position

@staticmethod
def unittype_in_proximity_to_point(bot:BotAI,type_id:UnitTypeId,point:Union[Point2,Point3,Unit],max_distance:float=.5) -> bool:
def unittype_in_proximity_to_point(bot:BotAI,
type_id:UnitTypeId,
point:Union[Point2,Point3,Unit],
max_distance:float=.5
) -> bool:
""" Returns true if a unit of type is in radius around point
Args:
bot (BotAI): instance of the bot
type_id (UnitTypeId): checked unit type
point (Union[Point2,Point3,Unit]): checked point
max_distance (float, optional): radius around point. Defaults to .5.
Returns:
bool: _description_
"""
return bot.units(type_id).filter(lambda unit: unit.distance_to(point)<max_distance)

@staticmethod
def structure_in_proximity(bot:BotAI, structure_type:UnitTypeId, structure:Unit, max_distance:float)-> bool:
if bot.structures(structure_type).filter(lambda struct: struct.distance_to(structure)<max_distance):
def structure_in_proximity(bot:BotAI,
structure_type:UnitTypeId,
structure:Unit,
max_distance:float
)-> bool:
""" returns true if
Args:
bot (BotAI): _description_
structure_type (UnitTypeId): _description_
structure (Unit): _description_
max_distance (float): _description_
Returns:
bool: _description_
"""
if bot.structures(structure_type)\
.filter(lambda struct: struct.distance_to(structure)<max_distance):
return True
return False

@staticmethod
def unit_in_proximity(bot:BotAI, unit_type:UnitTypeId, unit:Unit, max_distance:float) ->bool:
""" Checks if the a specific unit is in proyimity to a Unit of Unit type
Args:
bot (BotAI): Instance of Bot
unit_type (UnitTypeId): _description_
unit (Unit): _description_
max_distance (float): _description_
Returns:
bool: _description_
"""
if bot.units(unit_type).filter(lambda struct: struct.distance_to(unit)<max_distance):
return True
return False

@staticmethod
def in_proximity_to_point(unit:Unit, point:Union[Point2, Point3], max_distance:float) -> bool:
""" checks if Unit is in proximity to a point
Args:
unit (Unit): _description_
point (Union[Point2, Point3]): _description_
max_distance (float): _description_
Returns:
bool: _description_
"""
return unit.distance_to(point) < max_distance

@staticmethod
def is_close_to_unit(unit_1:Unit, unit_2:Unit, max_distance:float) -> bool:
return unit_1.distance_to(unit_2) <= max_distance
""" checks if two units are close to each other
Args:
unit_1 (Unit): _description_
unit_2 (Unit): _description_
max_distance (float): _description_
Returns:
bool: _description_
"""
return unit_1.distance_to(unit_2) <= max_distance
5 changes: 3 additions & 2 deletions bot/Unit_Classes/DarkTemplar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from HarstemsAunt.common import logger
"""make linter shut up"""
# pylint: disable=C0103
# pylint: disable=E0401
from Unit_Classes.baseClassGround import BaseClassGround


class DarkTemplar(BaseClassGround):
""" Extension of BaseClassGround """
4 changes: 3 additions & 1 deletion bot/Unit_Classes/HighTemplar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from HarstemsAunt.common import logger
"""make linter shut up"""
# pylint: disable=C0103
# pylint: disable=E0401
from Unit_Classes.baseClassGround import BaseClassGround


Expand Down
4 changes: 3 additions & 1 deletion bot/Unit_Classes/Immortal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from HarstemsAunt.common import logger
"""make linter shut up"""
# pylint: disable=C0103
# pylint: disable=E0401
from Unit_Classes.baseClassGround import BaseClassGround


Expand Down
Loading

0 comments on commit 8543b81

Please sign in to comment.