Skip to content

fix: replace hardcoded role map in DefenceStrategy with dynamic assignment#124

Open
isaac0804 wants to merge 1 commit into
mainfrom
fix/role-assignment-hardcoded-ids
Open

fix: replace hardcoded role map in DefenceStrategy with dynamic assignment#124
isaac0804 wants to merge 1 commit into
mainfrom
fix/role-assignment-hardcoded-ids

Conversation

@isaac0804

Copy link
Copy Markdown
Contributor

Summary

  • SetRoles in defense_strategy.py was assigning roles by fixed robot ID (0→MIDFIELDER, 1→DEFENDER, 2→GOALKEEPER), which breaks whenever robot IDs don't match that exact layout
  • Replaced with _assign_roles_dynamic(game): sorts robots by distance to own goal, assigns GOALKEEPER to the nearest, MIDFIELDER to the furthest, and DEFENDER to all in between
  • Closes Hardcoded robot id for strategies to be replaced with role assignment management #121 (Utama-Core side; Utama-Strategy is addressed in a separate PR)

Test plan

  • Import check: from utama_core.strategy.examples.defense_strategy import DefenceStrategy succeeds
  • SetRoles.update() no longer references hardcoded IDs
  • Run DefenceStrategy integration test with robots not at IDs 0/1/2 to verify correct role assignment

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 as MIDFIELDER, and intermediate robots as DEFENDER.
  • Replaces the hardcoded SetRoles role map with the dynamic assignment helper.

1: Role.DEFENDER,
2: Role.GOALKEEPER,
},
_assign_roles_dynamic(self.blackboard.game),
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.

Hardcoded robot id for strategies to be replaced with role assignment management

2 participants