Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function BotAI.research() not returning correct result #191

Open
DrKwojn opened this issue Mar 6, 2024 · 0 comments
Open

Function BotAI.research() not returning correct result #191

DrKwojn opened this issue Mar 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@DrKwojn
Copy link

DrKwojn commented Mar 6, 2024

Description for function BotAI.research states that the result should only be True if the upgrade was started.
But the function will return True even if the research is not started because of the structure needed to research the upgrade not being finished.

python-sc2/sc2/bot_ai.py

Lines 1080 to 1085 in f175e81

def research(self, upgrade_type: UpgradeId) -> bool:
"""
Researches an upgrade from a structure that can research it, if it is idle and powered (protoss).
Returns True if the research was started.
Return False if the requirement was not met, or the bot did not have enough resources to start the upgrade,
or the building to research the upgrade was missing or not idle.

The problem seems to be that the condition checking for an available structure to do the research does not check if the structure has finished building.

python-sc2/sc2/bot_ai.py

Lines 1136 to 1152 in f175e81

structure: Unit
for structure in self.structures:
if (
# Structure can research this upgrade
structure.type_id in research_structure_types
# If structure hasn't received an action/order this frame
and structure.tag not in self.unit_tags_received_action
# Structure is idle
and structure.is_idle
# Structure belongs to protoss and is powered (near pylon)
and (not is_protoss or structure.is_powered)
):
# Can_afford check was already done earlier in this function
successful_action: bool = self.do(
structure.research(upgrade_type), subtract_cost=True, ignore_warning=True
)
return successful_action

Example 1:

self.research(UpgradeId.ZERGMISSILEWEAPONSLEVEL1)

Will return True if there is only one evolution chamber and if it is not finished, but it should be False.

Example 2:

self.research(UpgradeId.GLIALRECONSTITUTION)

Will return True if there is only one roach warren and if it is not finished, but it should be False.

Possible solution

Adding and structure.is_ready in the condition checking for an available structure would solve the issue.
Not sure if there are any problems with this.

python-sc2/sc2/bot_ai.py

Lines 1138 to 1147 in f175e81

if (
# Structure can research this upgrade
structure.type_id in research_structure_types
# If structure hasn't received an action/order this frame
and structure.tag not in self.unit_tags_received_action
# Structure is idle
and structure.is_idle
# Structure belongs to protoss and is powered (near pylon)
and (not is_protoss or structure.is_powered)
):

Version burnysc2 6.5.0

@DrKwojn DrKwojn closed this as completed Mar 6, 2024
@DrKwojn DrKwojn reopened this Mar 6, 2024
@BurnySc2 BurnySc2 added the bug Something isn't working label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants