-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from FredNoonienSingh/82-fix-production-bug
started implementing production buffer
- Loading branch information
Showing
7 changed files
with
139 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""DOCSTRING to shut up the Linter """ | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
from sc2.units import Units | ||
from sc2.bot_ai import BotAI | ||
from sc2.ids.unit_typeid import UnitTypeId | ||
|
||
|
||
class ProductionRequest: | ||
""" Class Representing the a Production Request """ | ||
|
||
def __new__(cls, requested_unit:UnitTypeId, army_group_tag:int, build_structure_tag:int) -> ProductionRequest: | ||
""" Creates new instance of Production Request | ||
Args: | ||
requested_unit (UnitTypeId): type of requested Unit | ||
army_group_tag (int): identifier of the ArmyGroup requesting the Unit | ||
Returns: | ||
ProductionRequest: Request for a Unit (gets called in ArmyGroup) | ||
""" | ||
instance = super().__new__(cls) | ||
instance.requested_unit = requested_unit | ||
instance.army_group_tag = army_group_tag | ||
instance.build_structure_tag = build_structure_tag | ||
|
||
return instance | ||
|
||
def __init__(self, requested_unit:UnitTypeId, army_group_tag:int, build_structure_tag:int) -> None: | ||
self.requested_unit:UnitTypeId = requested_unit | ||
self.army_group_tag:int = army_group_tag | ||
self.build_structure_tag = build_structure_tag | ||
|
||
def __repr__(self) -> str: | ||
return f"Unit: {self.requested_unit} requested by {self.army_group_tag}" | ||
|
||
@property | ||
def handled(self) -> bool: | ||
return False | ||
|
||
@handled.setter | ||
def handled(self, new_status) -> None: | ||
self.handled = new_status | ||
|
||
class ProductionBuffer: | ||
""" Buffer for Production Requests before they are full filled""" | ||
|
||
def __init__(self,bot:BotAI) -> None: | ||
self.bot:BotAI = bot | ||
self.requests:List[ProductionRequest] = [] | ||
|
||
@property | ||
def gateways(self) -> Units: | ||
return self.bot.units.filter(lambda struct: struct.type_id \ | ||
in [UnitTypeId.WARPGATE, UnitTypeId.GATEWAY]) | ||
|
||
@property | ||
def stargates(self) -> Units: | ||
return self.bot.units(UnitTypeId.STARGATE) | ||
|
||
@property | ||
def robofacilities(self) -> Units: | ||
return self.bot.units(UnitTypeId.ROBOTICSFACILITY) | ||
|
||
#def add_request(self) -> None: | ||
# self. |