Beispiel #1
0
    def order(self, observations: Observations, step_index: int)-> Order:
        if observations.last():
            self.qlearn.learn(str(self.previous_state), self.previous_action, observations.reward(), 'terminal')
            QLearningTableStorage().save(self.qlearn, self.agent_name)

            self.previous_action = None
            self.previous_state = None
            self.previous_order = None

            return NoOrder()

        elif observations.first():
            self.location = Location(observations)
            self.smart_actions = SmartActions(self.location)
            self.qlearn = QLearningTable(actions=list(range(len(self.smart_actions.all()))))
            QLearningTableStorage().load(self.qlearn, self.agent_name)
            self.control_group_order = PrepareSCVControlGroupsOrder(self.location)

        if not self.control_group_order.done(observations):
            return self.control_group_order

        elif not self.previous_order or self.previous_order.done(observations):

            current_state = StateBuilder().build_state(self.location, observations)

            if self.previous_action is not None:
                self.qlearn.learn(str(self.previous_state), self.previous_action, 0, str(current_state))

            rl_action = self.qlearn.choose_action(str(current_state))

            self.previous_state = current_state
            self.previous_action = rl_action
            self.previous_order = self.smart_actions.order(rl_action)

        return self.previous_order
Beispiel #2
0
    def step(self, obs):
        super(ReinforcementMarineAgent, self).step(obs)
        observations = Observations(obs)
        if observations.first():
            self.commander = QLearningCommander(self.name())
        elif observations.last():
            game_results = GameResultsTable(self.name())
            game_info = FinishedGameInformationDetails(self.steps, "unknown")
            game_results.append(observations.reward(),
                                observations.score_cumulative(), game_info)

        return self.commander.order(observations,
                                    self.steps).execute(observations)
Beispiel #3
0
 def step(self, obs):
     super(BuildOrderAgent, self).step(obs)
     observations = Observations(obs)
     if observations.first():
         base_location = Location(observations)
         self.commander = GameCommander(base_location)
     elif observations.last():
         game_results = GameResultsTable(self.name())
         game_info = FinishedGameInformationDetails(self.steps, "unknown")
         game_results.append(observations.reward(),
                             observations.score_cumulative(), game_info)
     if self.debug:
         time.sleep(0.5)
     return self.commander.order(observations,
                                 self.steps).execute(observations)
Beispiel #4
0
 def step(self, obs):
     super(HybridAttackReinforcementAgent, self).step(obs)
     observations = Observations(obs)
     if observations.first():
         base_location = Location(observations)
         self.enemy_detector = EnemyDetector()
         self.commander = HybridGameCommander(base_location, self.name(),
                                              self.enemy_detector)
     elif observations.last():
         game_results = GameResultsTable(self.name())
         game_info = FinishedGameInformationDetails(
             self.steps, self.enemy_detector.race())
         game_results.append(observations.reward(),
                             observations.score_cumulative(), game_info)
     return self.commander.order(observations,
                                 self.steps).execute(observations)
Beispiel #5
0
    def order(self, observations: Observations, step_index: int) -> Order:
        if observations.last():
            self.qlearn.learn(str(self.previous_state), self.previous_action,
                              observations.reward(), 'terminal')
            QLearningTableStorage().save(self.qlearn, self.agent_name)
            self.previous_action = None
            self.previous_state = None
            self.previous_order = None
            return NoOrder()

        if not self.previous_order or self.previous_order.done(observations):
            current_state = StateBuilder().build_state(self.location,
                                                       observations,
                                                       self.enemy_detector)
            if self.previous_action is not None:
                self.qlearn.learn(str(self.previous_state),
                                  self.previous_action, 0, str(current_state))
            rl_action = self.qlearn.choose_action(str(current_state))
            self.previous_state = current_state
            self.previous_action = rl_action
            self.previous_order = self.smart_actions.order(rl_action)

        return self.previous_order