コード例 #1
0
    def processing(self):
        # First we check whether we are at the end of the round
        if self.frame_data.getEmptyFlag(
        ) or self.frame_data.getRemainingFramesNumber() <= 0:
            self.is_game_just_started = True
            return
        if not self.is_game_just_started:
            # Simulate the delay and look ahead 2 frames. The simulator class exists already in FightingICE
            self.frame_data = self.simulator.simulate(self.frame_data,
                                                      self.player_num, None,
                                                      None, self.FRAME_AHEAD)
        else:
            # If the game just started, no point on simulating
            self.is_game_just_started = False
        self.cc.setFrameData(self.frame_data, self.player_num)
        # distance = self.frame_data.getDistanceX()
        # energy = my.getEnergy()
        # my_x = my.getX()
        # my_state = my.getState()
        # opp_x = opp.getX()
        # opp_state = opp.getState()
        # xDifference = my_x - opp_x
        if self.cc.getSkillFlag():
            # If there is a previous "command" still in execution, then keep doing it
            self.input_key = self.cc.getSkillKey()
            return
        # We empty the keys and cancel skill just in case
        self.input_key.empty()
        self.cc.skillCancel()

        # print("calling MCTS Prep")
        self.MCTSPrepare()
        # print("okay calling root_node")
        # print(self.simulator_ahead_frame_data)
        # print(self.my_actions)
        # print(self.op_actions)
        # print(self.game_data)
        # print(self.player_num)

        root_node = TreeNode(self.gateway, self.simulator_ahead_frame_data,
                             None, self.my_actions, self.op_actions,
                             self.game_data, self.player_num, self.cc)
        # print("root node created")

        # print("MCTS being called")
        best_action = root_node.MCTS()
        # print("MCTS is done?")
        # print("best_action: ",best_action)
        # print(self.DEBUG_MODE)

        # print(root_node)

        if self.DEBUG_MODE:
            print(root_node)
            # print("please work")

        # print("best_action : ")
        # print(best_action)
        # print("picked action: ",best_action.name())
        self.cc.commandCall(best_action.name())
コード例 #2
0
ファイル: RLAgent.py プロジェクト: a3madkour/game_ai_final
    def ExecuteOption(self, action):
        # print(action)
        if type(action) is str:
            # print("action is a string")
            print("The option picked: ", action)
            action_name = action
        else:
            action_name = action.name()

        selected_action = self.ACTION.NEUTRAL
        # print("starting the ifs")
        if "OPTION" in action_name:
            # print("it is an option")
            if "GUARD" in action_name:
                self.action_air = [self.ACTION.AIR_GUARD]
                # print("done with air")
                self.action_ground = [
                    self.ACTION.DASH, self.ACTION.NEUTRAL, self.ACTION.STAND_A,
                    self.ACTION.CROUCH_B, self.ACTION.THROW_A,
                    self.ACTION.STAND_B, self.ACTION.CROUCH_A
                ]
                # print("done with ground")
                self.op_action_air = [
                    self.ACTION.AIR_B, self.ACTION.AIR_DB, self.ACTION.AIR_FB
                ]
                self.op_action_ground = [
                    self.ACTION.STAND, self.ACTION.DASH, self.ACTION.STAND_A,
                    self.ACTION.CROUCH_B, self.ACTION.STAND_B
                ]
                self.simulate_time = 60

            elif "KICK" in action_name:
                # print("I am kicker")
                self.action_air = [self.ACTION.AIR_GUARD]
                # print("done with air")
                self.action_ground = [
                    self.ACTION.STAND, self.ACTION.DASH,
                    self.ACTION.FORWARD_WALK, self.ACTION.CROUCH_A,
                    self.ACTION.CROUCH_B, self.ACTION.CROUCH_FB,
                    self.ACTION.STAND_D_DB_BB
                ]
                # print("done with ground")
                self.op_action_air = [
                    self.ACTION.AIR_B, self.ACTION.AIR_DB, self.ACTION.AIR_FB
                ]
                # print("done with option air")
                self.op_action_ground = [
                    self.ACTION.STAND, self.ACTION.DASH, self.ACTION.CROUCH_FB
                ]
                # print("done with option ground")
                self.simulate_time = 60

            elif "GRAB" in action_name:
                # print("I am grabber")
                self.action_air = [self.ACTION.AIR]
                # print("done with air")
                self.action_ground = [
                    self.ACTION.FORWARD_WALK, self.ACTION.DASH,
                    self.ACTION.STAND_A, self.ACTION.THROW_A
                ]
                # print("done with ground")
                self.op_action_air = [self.ACTION.AIR]
                # print("done with option air")
                self.op_action_ground = [
                    self.ACTION.STAND, self.ACTION.DASH, self.ACTION.STAND_A
                ]
                # print("done with option ground")
                self.simulate_time = 20

            elif "ANTI-AIR" in action_name:
                # print("I am antiair")

                self.action_air = [self.ACTION.AIR_GUARD]
                # print("done with air")
                self.action_ground = [
                    self.ACTION.FORWARD_WALK, self.ACTION.CROUCH_FA,
                    self.ACTION.STAND_FB
                ]
                # print("done with ground")
                self.op_action_air = [self.ACTION.NEUTRAL]
                # print("done with option air")
                self.op_action_ground = [self.ACTION.NEUTRAL]
                # print("done with option ground")
                self.simulate_time = 20

            elif "ALL_ACTIONS" in action_name:
                self.action_air = [
                    self.ACTION.AIR_GUARD, self.ACTION.AIR_A,
                    self.ACTION.AIR_B, self.ACTION.AIR_DA, self.ACTION.AIR_DB,
                    self.ACTION.AIR_FA, self.ACTION.AIR_FB, self.ACTION.AIR_UA,
                    self.ACTION.AIR_UB, self.ACTION.AIR_D_DF_FA,
                    self.ACTION.AIR_D_DF_FB, self.ACTION.AIR_F_D_DFA,
                    self.ACTION.AIR_F_D_DFB, self.ACTION.AIR_D_DB_BA,
                    self.ACTION.AIR_D_DB_BB
                ]
                # print("done with air")

                self.action_ground = [
                    self.ACTION.STAND_D_DB_BA, self.ACTION.BACK_STEP,
                    self.ACTION.FORWARD_WALK, self.ACTION.DASH,
                    self.ACTION.JUMP, self.ACTION.FOR_JUMP,
                    self.ACTION.BACK_JUMP, self.ACTION.STAND_GUARD,
                    self.ACTION.CROUCH_GUARD, self.ACTION.THROW_A,
                    self.ACTION.THROW_B, self.ACTION.STAND_A,
                    self.ACTION.STAND_B, self.ACTION.CROUCH_A,
                    self.ACTION.CROUCH_B, self.ACTION.STAND_FA,
                    self.ACTION.STAND_FB, self.ACTION.CROUCH_FA,
                    self.ACTION.CROUCH_FB, self.ACTION.STAND_D_DF_FA,
                    self.ACTION.STAND_D_DF_FB, self.ACTION.STAND_F_D_DFA,
                    self.ACTION.STAND_F_D_DFB, self.ACTION.STAND_D_DB_BB
                ]
                # print("done with ground")

                self.op_action_air = self.action_air
                # print("done with option air")
                self.op_action_ground = self.action_ground
                # print("done with option ground")
                self.simulate_time = 60

            self.MCTSPrepare()

            root_node = TreeNode(self.gateway, self.simulator_ahead_frame_data,
                                 None, self.my_actions, self.op_actions,
                                 self.game_data, self.player_num, self.cc)

            best_action = root_node.MCTS()
            print("exeuting: ", best_action.name())
            self.cc.commandCall(best_action.name())