fix: replace hardcoded role map in DefenceStrategy with dynamic assignment#124
Open
isaac0804 wants to merge 1 commit into
Open
fix: replace hardcoded role map in DefenceStrategy with dynamic assignment#124isaac0804 wants to merge 1 commit into
isaac0804 wants to merge 1 commit into
Conversation
…nment SetRoles previously assigned roles by fixed robot ID (0→MIDFIELDER, 1→DEFENDER, 2→GOALKEEPER). Now sorts robots by distance to own goal and assigns GOALKEEPER to the nearest, MIDFIELDER to the furthest, and DEFENDER to all in between — matching the pattern from issue #121.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates DefenceStrategy to assign roles dynamically based on robot positions relative to the team’s own goal instead of assuming fixed robot IDs.
Changes:
- Adds
_assign_roles_dynamic(game)to sort friendly robots by distance to own goal. - Assigns nearest robot as
GOALKEEPER, furthest asMIDFIELDER, and intermediate robots asDEFENDER. - Replaces the hardcoded
SetRolesrole map with the dynamic assignment helper.
| 1: Role.DEFENDER, | ||
| 2: Role.GOALKEEPER, | ||
| }, | ||
| _assign_roles_dynamic(self.blackboard.game), |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SetRolesindefense_strategy.pywas assigning roles by fixed robot ID (0→MIDFIELDER, 1→DEFENDER, 2→GOALKEEPER), which breaks whenever robot IDs don't match that exact layout_assign_roles_dynamic(game): sorts robots by distance to own goal, assignsGOALKEEPERto the nearest,MIDFIELDERto the furthest, andDEFENDERto all in betweenTest plan
from utama_core.strategy.examples.defense_strategy import DefenceStrategysucceedsSetRoles.update()no longer references hardcoded IDsDefenceStrategyintegration test with robots not at IDs 0/1/2 to verify correct role assignment