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.motion_executor = MotionExecutor(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))
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.motion_executor = MotionExecutor(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.motion_executor.exec() robot_commands = self.robot_command_executor.exec() return robot_commands def set_reference(self, world_reference: ReferenceTransferObject) -> 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)
class Coach(object): def __init__(self, mode_debug_active=True, pathfinder="astar", is_simulation=True): """ 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) """ self.mode_debug_active = mode_debug_active self.is_simulation = is_simulation # 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, pathfinder, is_simulation) self.movement_executor = MovementExecutor(self.world_state) self.regulator_executor = PositionRegulator(self.world_state, is_simulation) self.robot_command_executor = CommandExecutor(self.world_state) # logging DebugInterface().add_log(1, "\nCoach initialized with \nmode_debug_active = "+str(mode_debug_active) + "\npathfinder = "+str(pathfinder)+"\nis_simulation = "+str(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)
def __init__(self, mode_debug_active=True): self.mode_debug_active = mode_debug_active # For the framework! TODO make this better! self.debug_commands = [] self.robot_commands = [] self.world_state = WorldState() self.debug_executor = DebugExecutor(self.world_state) self.module_executor = ModuleExecutor(self.world_state) self.play_executor = PlayExecutor(self.world_state) self.robot_command_executor = CommandExecutor(self.world_state)
class Coach(object): def __init__(self, mode_debug_active=True): self.mode_debug_active = mode_debug_active # For the framework! TODO make this better! self.debug_commands = [] self.robot_commands = [] self.world_state = WorldState() self.debug_executor = DebugExecutor(self.world_state) self.module_executor = ModuleExecutor(self.world_state) self.play_executor = PlayExecutor(self.world_state) self.robot_command_executor = CommandExecutor(self.world_state) def main_loop(self, p_game_state): self.robot_commands.clear() self.debug_commands.clear() self.world_state.update(p_game_state) self.debug_executor.exec() self.module_executor.exec() self.play_executor.exec() self.robot_command_executor.exec() self.debug_executor.exec() self.robot_commands = self.world_state.play_state.ready_to_ship_robot_packet_list if self.mode_debug_active: self.debug_commands = self.world_state.debug_state.to_ui_packet_debug_cmds return self.robot_commands, self.debug_commands def set_team_color(self, p_our_team_colors): self.world_state.set_team_color(p_our_team_colors) def get_robot_commands(self): return self.robot_commands def get_debug_status(self): return self.mode_debug_active # FIXME only the debug command are accessed through method, the robot_commands are take straight from the variable! def get_debug_commands_and_clear(self): return self.debug_commands # Throwback for the last coach! TODO see if we still need to implement them! Or HOW! def halt(self): """ Hack pour sync les frames de vision et les itérations de l'IA """ pass def stop(self, game_state): """ *Devrait* déinit pour permettre un arrêt propre. """ pass
def __init__(self, mode_debug_active=True, pathfinder="astar", is_simulation=True): """ 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) """ self.mode_debug_active = mode_debug_active self.is_simulation = is_simulation # 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, pathfinder, is_simulation) self.movement_executor = MovementExecutor(self.world_state) self.regulator_executor = PositionRegulator(self.world_state, is_simulation) self.robot_command_executor = CommandExecutor(self.world_state) # logging DebugInterface().add_log(1, "\nCoach initialized with \nmode_debug_active = "+str(mode_debug_active) + "\npathfinder = "+str(pathfinder)+"\nis_simulation = "+str(is_simulation))
def setUp(self): self.ws = WorldState() self.rm = RobotMotion(self.ws, 0) self.rm.setting.rotation.deadzone = 0.1 self.rm.setting.rotation.sensibility = 0.01 self.rm.setting.rotation.max_speed = 1 self.rm.setting.translation.deadzone = 0.1 self.rm.setting.translation.sensibility = 0.01 self.rm.setting.translation.max_speed = 2 self.rm.setting.translation.max_acc = 2 self.rm.dt = 0.05
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.motion_executor = MotionExecutor(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 # debug code! no remostart_play_executorve pls (au moins pas avant le Japon) start_debug_interface = time.time() self.debug_executor.exec() end_debug_interface = start_play_executor = time.time() self.play_executor.exec() end_play_executor = start_module_executor = time.time() self.module_executor.exec() end_module_executor = start_motion_executor = time.time() self.motion_executor.exec() end_motion_executor = start_robot_commands = time.time() robot_commands = self.robot_command_executor.exec() end_robot_commands = time.time() dt_debug = end_debug_interface - start_debug_interface dt_play_exe = end_play_executor - start_play_executor dt_module_exe = end_module_executor - start_module_executor dt_motion_exe = end_motion_executor - start_motion_executor dt_robot_cmd = end_robot_commands - start_robot_commands sum = dt_debug + dt_play_exe + dt_module_exe + dt_motion_exe + dt_robot_cmd # Profiling code for debuging, DO NOT REMOVE # print("[{:4.1f}ms total] debug_inter:{:4.1f}ms/{:4.1f}% | play_exec:{:4.1f}ms/{:4.1f}% | module_exec:{:4.1f}ms/{:4.1f}% | motion_exec:{:4.1f}ms/{:4.1f}% | robot_cmd:{:4.1f}ms/{:3.1f}%" # .format(sum*1000, # dt_debug*1000, dt_debug/sum*100.0, # dt_play_exe*1000, dt_play_exe/sum*100.0, # dt_module_exe*1000, dt_module_exe/sum*100.0, # dt_motion_exe*1000, dt_motion_exe/sum*100.0, # dt_robot_cmd*1000, dt_robot_cmd/sum*100.0)) return robot_commands def set_reference(self, world_reference: ReferenceTransferObject) -> 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)