Skip to content

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

Merged
merged 5 commits into from
Jul 20, 2025

Conversation

raspersc2
Copy link
Contributor

This fixes two problems on the new map TorchesAIE. I believe this PR fixes the find expansion logic without breaking any existing maps.

  1. Mineral wall resources get grouped with base resources

gold-and-min-broken

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.

gold-and-min-not-broken

I did have to add some logic for dealing with the mineral wall, please let me know if this should be changed.

if amount > 12:
    logger.warning(f"Found resource group of size {amount}, possible mineral wall? Skipping this one.")
    continue
  1. Not handling locations with two possible expansion positions

expansion-missing

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 from dict[Point2, Point2] to dict[Point2, set[Point2]] so it supports the possibility a resource can belong to more then one base.

expansion-not-missing

raspersc2 added 4 commits July 8, 2025 09:45
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
# 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.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Contributor Author

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?

Copy link
Owner

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.

Comment on lines 205 to 216
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.
Copy link
Owner

@BurnySc2 BurnySc2 Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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

Comment on lines 309 to 310
def side_of_line(point):
return point.y - slope * point.x - intercept
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@BurnySc2 BurnySc2 merged commit dd593e7 into BurnySc2:develop Jul 20, 2025
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants