|
10 | 10 |
|
11 | 11 |
|
12 | 12 | class Situation(Enum): |
| 13 | + """ |
| 14 | + Enum class representing different game situations in a 2D soccer simulation. |
| 15 | +
|
| 16 | + Attributes: |
| 17 | + OurSetPlay_Situation (int): Represents a situation where our team is executing a set play. |
| 18 | + OppSetPlay_Situation (int): Represents a situation where the opposing team is executing a set play. |
| 19 | + Defense_Situation (int): Represents a defensive situation for our team. |
| 20 | + Offense_Situation (int): Represents an offensive situation for our team. |
| 21 | + PenaltyKick_Situation (int): Represents a penalty kick situation. |
| 22 | + """ |
13 | 23 | OurSetPlay_Situation = 0, |
14 | 24 | OppSetPlay_Situation = 1, |
15 | 25 | Defense_Situation = 2, |
16 | 26 | Offense_Situation = 3, |
17 | 27 | PenaltyKick_Situation = 4 |
18 | 28 |
|
19 | 29 | class Formation: |
| 30 | + """ |
| 31 | + A class to manage different soccer formations for various game situations. |
| 32 | +
|
| 33 | + Attributes: |
| 34 | + before_kick_off_formation (FormationFile): Formation used before the kick-off. |
| 35 | + defense_formation (FormationFile): Formation used during defense. |
| 36 | + offense_formation (FormationFile): Formation used during offense. |
| 37 | + goalie_kick_opp_formation (FormationFile): Formation used when the opponent's goalie kicks. |
| 38 | + goalie_kick_our_formation (FormationFile): Formation used when our goalie kicks. |
| 39 | + kickin_our_formation (FormationFile): Formation used during our team's kick-in. |
| 40 | + setplay_opp_formation (FormationFile): Formation used during the opponent's set play. |
| 41 | + setplay_our_formation (FormationFile): Formation used during our team's set play. |
| 42 | +
|
| 43 | + Args: |
| 44 | + path (str): The path to the directory containing the formation configuration files. |
| 45 | + logger (logging.Logger): Logger instance for logging formation-related information. |
| 46 | + """ |
20 | 47 | def __init__(self, path, logger: logging.Logger): |
| 48 | + # Initialize formation files for different game situations |
| 49 | + # before_kick_off_formation: Formation used before the kick-off |
21 | 50 | self.before_kick_off_formation: FormationFile = FormationFile(f'{path}/before-kick-off.conf', logger) |
| 51 | + # defense_formation: Formation used during defense |
22 | 52 | self.defense_formation: FormationFile = FormationFile(f'{path}/defense-formation.conf', logger) |
| 53 | + # offense_formation: Formation used during offense |
23 | 54 | self.offense_formation: FormationFile = FormationFile(f'{path}/offense-formation.conf', logger) |
| 55 | + # goalie_kick_opp_formation: Formation used when the opponent's goalie kicks |
24 | 56 | self.goalie_kick_opp_formation: FormationFile = FormationFile(f'{path}/goalie-kick-opp-formation.conf', logger) |
| 57 | + # goalie_kick_our_formation: Formation used when our goalie kicks |
25 | 58 | self.goalie_kick_our_formation: FormationFile = FormationFile(f'{path}/goalie-kick-our-formation.conf', logger) |
| 59 | + # kickin_our_formation: Formation used during our team's kick-in |
26 | 60 | self.kickin_our_formation: FormationFile = FormationFile(f'{path}/kickin-our-formation.conf', logger) |
| 61 | + # setplay_opp_formation: Formation used during the opponent's set play |
27 | 62 | self.setplay_opp_formation: FormationFile = FormationFile(f'{path}/setplay-opp-formation.conf', logger) |
| 63 | + # setplay_our_formation: Formation used during our team's set play |
28 | 64 | self.setplay_our_formation: FormationFile = FormationFile(f'{path}/setplay-our-formation.conf', logger) |
29 | 65 |
|
30 | 66 | class FormationStrategy(IPositionStrategy): |
31 | 67 | def __init__(self, logger: logging.Logger): |
32 | 68 | self.logger = logger |
33 | 69 | self.formations: dict[str, Formation] = {} |
34 | | - self.formations['4-3-3'] = Formation('src/formations/4-3-3', logger) |
35 | | - self.formations['4-3-3-cyrus-base'] = Formation('src/formations/4-3-3-cyrus-base', logger) |
36 | | - self.formations['4-3-3-helios-base'] = Formation('src/formations/4-3-3-helios-base', logger) |
37 | | - self.selected_formation_name = '4-3-3' # '4-3-3' '4-3-3-cyrus-base' '4-3-3-helios-base' |
| 70 | + |
| 71 | + self._read_formations() |
| 72 | + self._set_formation(None) |
38 | 73 |
|
39 | 74 | self._poses: dict[int, Vector2D] = {(i, Vector2D(0, 0)) for i in range(11)} |
40 | 75 | self.current_situation = Situation.Offense_Situation |
41 | 76 | self.current_formation_file: FormationFile = self._get_current_formation().offense_formation |
42 | 77 |
|
| 78 | + def _read_formations(self): |
| 79 | + self.formations['4-3-3'] = Formation('src/formations/4-3-3', self.logger) |
| 80 | + self.formations['4-3-3-cyrus-base'] = Formation('src/formations/4-3-3-cyrus-base', self.logger) |
| 81 | + self.formations['4-3-3-helios-base'] = Formation('src/formations/4-3-3-helios-base', self.logger) |
| 82 | + |
43 | 83 | def _get_current_formation(self) -> Formation: |
44 | 84 | return self.formations[self.selected_formation_name] |
45 | 85 |
|
46 | 86 | def _set_formation(self, wm: WorldModel): |
47 | | - self.selected_formation_name = '4-3-3' |
| 87 | + self.selected_formation_name = '4-3-3-cyrus-base' # '4-3-3' '4-3-3-cyrus-base' '4-3-3-helios-base' |
48 | 88 |
|
49 | 89 | def update(self, agent: IAgent): |
50 | 90 | logger = agent.logger |
@@ -117,13 +157,13 @@ def update(self, agent: IAgent): |
117 | 157 | def get_position(self, uniform_number) -> Vector2D: |
118 | 158 | return self._poses[uniform_number] |
119 | 159 |
|
120 | | - def get_role_name(self, uniform_number) -> int: |
| 160 | + def get_role_name(self, uniform_number) -> RoleName: |
121 | 161 | return self.current_formation_file.get_role(uniform_number).name |
122 | 162 |
|
123 | | - def get_role_type(self, uniform_number) -> int: |
| 163 | + def get_role_type(self, uniform_number) -> RoleType: |
124 | 164 | return self.current_formation_file.get_role(uniform_number).type |
125 | 165 |
|
126 | | - def get_role_side(self, uniform_number) -> int: |
| 166 | + def get_role_side(self, uniform_number) -> RoleSide: |
127 | 167 | return self.current_formation_file.get_role(uniform_number).side |
128 | 168 |
|
129 | 169 | def get_role_pair(self, uniform_number) -> int: |
|
0 commit comments