Skip to content

Commit 01a3dcb

Browse files
committed
feat: add GoalieDecisionMaker and integrate into DecisionMaker
1 parent 78a44a3 commit 01a3dcb

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

src/decision_makers/decision_maker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .play_on_decision_maker import PlayOnDecisionMaker
44
from .set_play_decision_maker import SetPlayDecisionMaker
55
from .penalty_decision_maker import PenaltyDecisionMaker
6+
from .goalie_decision_maker import GoalieDecisionMaker
67
from service_pb2 import *
78

89
if TYPE_CHECKING:
@@ -14,12 +15,14 @@ class DecisionMaker(IDecisionMaker):
1415
Attributes:
1516
play_on_decision_maker (PlayOnDecisionMaker): Handles decisions during the 'PlayOn' game mode.
1617
set_play_decision_maker (SetPlayDecisionMaker): Handles decisions during set plays.
18+
penalty_decision_maker (PenaltyDecisionMaker): Handles decisions during penalty kicks.
19+
goalie_decision_maker (GoalieDecisionMaker): Handles decisions for goalies.
1720
Methods:
1821
__init__():
1922
Initializes the DecisionMaker with specific decision makers for different game modes.
2023
make_decision(agent: IAgent):
2124
Makes a decision for the given agent based on its role and the current game mode.
22-
If the agent is a goalie, it adds a goalie action.
25+
If the agent is a goalie, it adds a goalie action using goalie_decision_maker.
2326
If the game mode is 'PlayOn', it delegates the decision to play_on_decision_maker.
2427
If the game mode is a penalty kick, it adds a penalty action using penalty_decision_maker.
2528
Otherwise, it adds a set play action using set_play_decision_maker.
@@ -28,10 +31,11 @@ def __init__(self, agent: "SamplePlayerAgent"):
2831
self.play_on_decision_maker = PlayOnDecisionMaker(agent)
2932
self.set_play_decision_maker = SetPlayDecisionMaker(agent)
3033
self.penalty_decision_maker = PenaltyDecisionMaker(agent)
34+
self.goalie_decision_maker = GoalieDecisionMaker(agent)
3135

3236
def make_decision(self, agent: "SamplePlayerAgent"):
3337
if agent.wm.self.is_goalie:
34-
agent.add_action(PlayerAction(helios_goalie=HeliosGoalie()))
38+
self.goalie_decision_maker.make_decision(agent)
3539
elif agent.wm.game_mode_type == GameModeType.PlayOn:
3640
self.play_on_decision_maker.make_decision(agent)
3741
elif agent.wm.is_penalty_kick_mode:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import TYPE_CHECKING
2+
from src.interfaces.IDecisionMaker import IDecisionMaker
3+
from src.interfaces.IAgent import IAgent
4+
from pyrusgeom.soccer_math import *
5+
from pyrusgeom.geom_2d import *
6+
from service_pb2 import *
7+
8+
9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
11+
12+
class GoalieDecisionMaker(IDecisionMaker):
13+
def __init__(self, agent: "SamplePlayerAgent"):
14+
pass
15+
16+
def make_decision(self, agent: "SamplePlayerAgent"):
17+
agent.logger.debug("--- GoalieDecisionMaker ---")
18+
agent.add_action(PlayerAction(helios_goalie=HeliosGoalie()))

src/sample_player_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, logger) -> None:
1111
super().__init__(logger)
1212
self.logger.info('SamplePlayerAgent created')
1313

14-
self.use_starter_code = True
14+
self.use_starter_code = False
1515

1616
self.decision_maker = DecisionMaker(self)
1717
self.strategy = FormationStrategy(self.logger) if not self.use_starter_code else StarterStrategy(self.logger)

src/strategy/formation_strategy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import TYPE_CHECKING
12
from src.interfaces.IPositionStrategy import IPositionStrategy
23
from src.strategy.formation_file import *
34
from src.interfaces.IAgent import IAgent
@@ -8,6 +9,8 @@
89
import logging
910

1011

12+
if TYPE_CHECKING:
13+
from src.sample_player_agent import SamplePlayerAgent
1114

1215
class Situation(Enum):
1316
"""
@@ -86,7 +89,7 @@ def _get_current_formation(self) -> Formation:
8689
def _set_formation(self, wm: WorldModel):
8790
self.selected_formation_name = '4-3-3-cyrus-base' # '4-3-3' '4-3-3-cyrus-base' '4-3-3-helios-base'
8891

89-
def update(self, agent: IAgent):
92+
def update(self, agent: 'SamplePlayerAgent'):
9093
logger = agent.logger
9194
logger.debug(f'---- update strategy ----')
9295

0 commit comments

Comments
 (0)