forked from RoboCupULaval/StrategyAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coach.py
70 lines (57 loc) · 2.75 KB
/
coach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Under MIT License, see LICENSE.txt
from typing import List
from RULEngine.Debug.debug_interface import DebugInterface
from RULEngine.Util.game_world import GameWorld
from ai.executors.regulator import PositionRegulator
from ai.states.world_state import WorldState
from ai.executors.debug_executor import DebugExecutor
from ai.executors.module_executor import ModuleExecutor
from ai.executors.play_executor import PlayExecutor
from ai.executors.command_executor import CommandExecutor
from ai.executors.movement_executor import MovementExecutor
from config.config_service import ConfigService
class Coach(object):
def __init__(self):
"""
Initialise le coach de l'IA.
:param mode_debug_active: (bool) indique si les commandes de debug sont actives
:param pathfinder: (str) indique le nom du pathfinder par défault
:param is_simulation: (bool) indique si en simulation (true) ou en vrai vie (false)
"""
cfg = ConfigService()
self.mode_debug_active = cfg.config_dict["DEBUG"]["using_debug"] == "true"
self.is_simulation = cfg.config_dict["GAME"]["type"] == "sim"
# init the states
self.world_state = WorldState()
# init the executors
self.debug_executor = DebugExecutor(self.world_state)
self.play_executor = PlayExecutor(self.world_state)
self.module_executor = ModuleExecutor(self.world_state)
self.movement_executor = MovementExecutor(self.world_state)
self.regulator_executor = PositionRegulator(self.world_state)
self.robot_command_executor = CommandExecutor(self.world_state)
# logging
DebugInterface().add_log(1, "\nCoach initialized with \nmode_debug_active = "+str(self.mode_debug_active) +
"\nis_simulation = "+str(self.is_simulation))
def main_loop(self) -> List:
"""
Execute un tour de boucle de l'IA
:return: List(_Command) les commandes des robots
"""
# main loop de l'IA
self.debug_executor.exec()
self.play_executor.exec()
self.module_executor.exec()
self.movement_executor.exec()
self.regulator_executor.exec()
robot_commands = self.robot_command_executor.exec()
return robot_commands
def set_reference(self, world_reference: GameWorld) -> None:
"""
Permet de mettre les références dans le worldstate et le debugexecutor.
:param world_reference: Objet GameWorld contenant les références des objets en jeu provenant du RULEngine.
C'est un data transfert object.
:return: None.
"""
self.world_state.set_reference(world_reference)
self.debug_executor.set_reference(world_reference.debug_info)