-
Notifications
You must be signed in to change notification settings - Fork 173
Fix TorchesAIE expansion locations #224
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
Fix TorchesAIE expansion locations #224
Conversation
Only adding currently active ones for now
…ing logic This change allows an expansion location to be correctly identified on TorchesAIE. There was previously an issue where the gold minerals were grouped with the base minerals. The flaw was check for any resource within 8.5 This change only merges resources if their cluster centers are near each other. The gold minerals wall on Torches use a typical unit type id, so we couldn't filter out based on that
sc2/bot_ai_internal.py
Outdated
# this check is needed for TorchesAIE where the gold mineral wall has a | ||
# unit type of `RichMineralField` so we can only filter out by amount of resources | ||
if amount > 12: | ||
logger.warning(f"Found resource group of size {amount}, possible mineral wall? Skipping this one.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.warning(f"Found resource group of size {amount}, possible mineral wall? Skipping this one.") | |
logger.debug(f"Found resource group of size {amount}, possible mineral wall? Skipping this one.") |
I think this function was only called once at the start of the game? However, each bot playing on this map or a map with a mineral wall will receive such a loguru entry. Is this desired behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't too sure how to handle it. Should the logging behavior be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think complete removal of logging would be even better.
sc2/bot_ai_internal.py
Outdated
def _find_expansion_location( | ||
self, resources: Units | list[Unit], amount: int, offsets: list[tuple] | ||
) -> Point2 | None: | ||
""" | ||
Finds the most suitable expansion location for resources. | ||
|
||
Parameters: | ||
resources: The list of resource entities or units near which the | ||
expansion location needs to be found. | ||
amount: The total number of resource entities or units to consider. | ||
offsets (list[tuple]): A list of coordinate pairs denoting position offsets to consider | ||
around the center of resources. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _find_expansion_location( | |
self, resources: Units | list[Unit], amount: int, offsets: list[tuple] | |
) -> Point2 | None: | |
""" | |
Finds the most suitable expansion location for resources. | |
Parameters: | |
resources: The list of resource entities or units near which the | |
expansion location needs to be found. | |
amount: The total number of resource entities or units to consider. | |
offsets (list[tuple]): A list of coordinate pairs denoting position offsets to consider | |
around the center of resources. | |
def _find_expansion_location( | |
self, resources: Units | list[Unit], amount: int, offsets: list[tuple[float, float]] | |
) -> Point2: | |
""" | |
Finds the most suitable expansion location for resources. | |
Parameters: | |
resources: The list of resource entities or units near which the | |
expansion location needs to be found. | |
amount: The total number of resource entities or units to consider. | |
offsets (list[tuple[float, float]]): A list of coordinate pairs denoting position offsets to consider | |
around the center of resources. |
I guess the tuples can be Point2
too and it should still work.
Also I don't see a return None
so that the return type can be reduced to Point2
? In the othe code calling this function, you never expect it to return None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! Not sure why it had a None
return type
sc2/bot_ai_internal.py
Outdated
def side_of_line(point): | ||
return point.y - slope * point.x - intercept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def side_of_line(point): | |
return point.y - slope * point.x - intercept | |
def side_of_line(point: Point2) -> float: | |
return point.y - slope * point.x - intercept |
This fixes two problems on the new map
TorchesAIE
. I believe this PR fixes the find expansion logic without breaking any existing maps.This is tricky because the gold mineral wall has the type
RICHMINERALFIELD
so we can't just filter it out. However there is a flaw in the logic that currently groups resources if its< 8.5
to any other resource. Instead of doing that we can measure the distance between two cluster centers to get more accurate resource groups. Now the base resources and the gold mineral wall are seperated.I did have to add some logic for dealing with the mineral wall, please let me know if this should be changed.
Here we can see for one resource group, there is a valid expansion position on both sides of the mineral line. For this I used linear regression to check for vespene geysers on either side of the (mineral) line. To allow support of this I had to change the data structure of
self._resource_location_to_expansion_position_dict
fromdict[Point2, Point2]
todict[Point2, set[Point2]]
so it supports the possibility a resource can belong to more then one base.