Skip to content

Commit 251a23b

Browse files
authored
Merge pull request #5 from CLSFramework/start_develop_nader
update code by adding use_starter_code
2 parents 9786031 + 6c6a7fb commit 251a23b

16 files changed

+82
-68
lines changed

src/behaviors/bhv_block.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class Bhv_Block(IBehavior):
1113
"""
@@ -26,7 +28,7 @@ class Bhv_Block(IBehavior):
2628
def __init__(self):
2729
pass
2830

29-
def execute(self, agent: IAgent) -> bool:
31+
def execute(self, agent: "SamplePlayerAgent") -> bool:
3032
"""
3133
Executes the block behavior for the agent. Predicts the future position of the ball and checks if the agent or any teammate can block it within a certain number of cycles.
3234
Parameters:
@@ -38,9 +40,6 @@ def execute(self, agent: IAgent) -> bool:
3840
- Calculate the first cycle that the agent or a teammate can block the ball.
3941
- If the agent can block the ball, add a Body_GoToPoint action to the agent.
4042
"""
41-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
42-
assert isinstance(agent, SamplePlayerAgent)
43-
4443
agent.logger.debug(f'------ Bhv_Block ------')
4544
wm = agent.wm
4645
sp = agent.server_params

src/behaviors/bhv_kick_planner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from typing import TYPE_CHECKING
12
from src.interfaces.IBehavior import IBehavior
23
from src.interfaces.IAgent import IAgent
34
from pyrusgeom.soccer_math import *
45
from pyrusgeom.geom_2d import *
56
from service_pb2 import *
67

8+
if TYPE_CHECKING:
9+
from src.sample_player_agent import SamplePlayerAgent
710

811
class BhvKickPlanner(IBehavior):
912
"""
@@ -33,10 +36,8 @@ class BhvKickPlanner(IBehavior):
3336
def __init__(self):
3437
pass
3538

36-
def execute(self, agent: IAgent):
39+
def execute(self, agent: "SamplePlayerAgent"):
3740
agent.logger.debug("--- WithBallDecisionMaker ---")
38-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
39-
assert isinstance(agent, SamplePlayerAgent)
4041

4142
agent.add_action(
4243
PlayerAction(helios_offensive_planner=self._get_helios_offensive_planner(agent))

src/behaviors/bhv_penalty.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvPenalty(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvPenalty.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
agent.add_action(PlayerAction(helios_penalty=HeliosPenalty()))

src/behaviors/bhv_setplay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvSetPlay(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvSetPlay.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
agent.add_action(PlayerAction(helios_set_play=HeliosSetPlay()))

src/behaviors/bhv_starter_penalty.py

Lines changed: 6 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.IBehavior import IBehavior
23
import numpy as np
34
from src.interfaces.IAgent import IAgent
@@ -14,11 +15,15 @@
1415
from src.utils.convertor import Convertor
1516
from src.behaviors.bhv_starter_clearball import BhvStarterClearBall
1617

18+
if TYPE_CHECKING:
19+
from src.sample_player_agent import SamplePlayerAgent
20+
1721
class BhvStarterPenalty(IBehavior):
1822
def __init__(self):
1923
pass
2024

21-
def execute(self, agent: IAgent) -> bool:
25+
def execute(self, agent: "SamplePlayerAgent"):
26+
agent.logger.debug("BhvStarterPenalty.execute")
2227
wm = agent.wm
2328
state = wm.penalty_kick_state
2429
actions = []
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvStarterSetPlay(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvSetPlay.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
raise NotImplementedError("BhvStarterSetPlay.execute not implemented")

src/behaviors/bhv_starter_tackle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
from typing import TYPE_CHECKING
12
from src.interfaces.IAgent import IAgent
23
from src.utils.convertor import Convertor
34
from pyrusgeom.geom_2d import *
45
from pyrusgeom.soccer_math import *
56
from service_pb2 import *
67
from src.interfaces.IBehavior import IBehavior
78

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
811

912
class BhvStarterTackle(IBehavior):
1013
def __init__(self, min_prob: float, body_thr: float):
1114
self.min_prob = min_prob
1215
self.body_thr = body_thr
1316

14-
def execute(self, agent: IAgent) -> bool:
17+
def execute(self, agent: "SamplePlayerAgent"):
1518
agent.logger.debug("BhvStarterTackle.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1819
wm = agent.wm
1920
use_foul = False
2021
tackle_prob = wm.self.tackle_probability

src/behaviors/bhv_tackle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvTackle(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvTackle.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
agent.add_action(PlayerAction(helios_basic_tackle=HeliosBasicTackle(min_prob=0.8, body_thr=100.0)))

src/behaviors/starter_setplay/bhv_starter_setplay.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from pyrusgeom.circle_2d import Circle2D
1414
from src.utils.convertor import Convertor
1515
from src.strategy.starter_strategy import StarterStrategy
16+
17+
1618
class BhvStarterSetPlay(IBehavior):
1719
def __init__(self):
1820
pass

src/decision_makers/decision_maker.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from typing import TYPE_CHECKING
12
from src.interfaces.IDecisionMaker import IDecisionMaker
23
from .play_on_decision_maker import PlayOnDecisionMaker
34
from .set_play_decision_maker import SetPlayDecisionMaker
45
from .penalty_decision_maker import PenaltyDecisionMaker
5-
from src.interfaces.IAgent import IAgent
66
from service_pb2 import *
77

8-
8+
if TYPE_CHECKING:
9+
from src.sample_player_agent import SamplePlayerAgent
10+
911
class DecisionMaker(IDecisionMaker):
1012
"""
1113
DecisionMaker is responsible for making decisions for an agent based on the current game state.
@@ -22,12 +24,12 @@ class DecisionMaker(IDecisionMaker):
2224
If the game mode is a penalty kick, it adds a penalty action using penalty_decision_maker.
2325
Otherwise, it adds a set play action using set_play_decision_maker.
2426
"""
25-
def __init__(self):
26-
self.play_on_decision_maker = PlayOnDecisionMaker()
27-
self.set_play_decision_maker = SetPlayDecisionMaker()
28-
self.penalty_decision_maker = PenaltyDecisionMaker()
27+
def __init__(self, agent: "SamplePlayerAgent"):
28+
self.play_on_decision_maker = PlayOnDecisionMaker(agent)
29+
self.set_play_decision_maker = SetPlayDecisionMaker(agent)
30+
self.penalty_decision_maker = PenaltyDecisionMaker(agent)
2931

30-
def make_decision(self, agent: IAgent):
32+
def make_decision(self, agent: "SamplePlayerAgent"):
3133
if agent.wm.self.is_goalie:
3234
agent.add_action(PlayerAction(helios_goalie=HeliosGoalie()))
3335
elif agent.wm.game_mode_type == GameModeType.PlayOn:

0 commit comments

Comments
 (0)