예제 #1
0
 def _selectAction(self, recommended_a_id=None):
     # if no action is recommended or we randomly roll below our
     # random_action_rate, select a random action. TODO it might be a good idea
     # to have state similarity here to pick a closest observed action
     possible_actions = getValidActionsInState(self.s)
     possible_action_ids = [
         Database.upsertAction(action) for action in possible_actions
     ]
     if not recommended_a_id or np.random.random(
     ) < self.random_action_rate or recommended_a_id not in possible_action_ids:
         random_action_index = np.random.randint(len(possible_action_ids))
         random_action_id = possible_action_ids[random_action_index]
         self._printIfVerbose("agent randomly chose",
                              possible_actions[random_action_index])
         return random_action_id, possible_actions[random_action_index]
     else:
         action = Database.getAction(recommended_a_id)
         self._printIfVerbose("agent chose", action)
         Stats.recordStat("{}{}".format(
             "chosen_action={}".format(action["action"]),
             "_id={}".format(action["card_id"])
             if "card_id" in action and action["card_id"] != None else ""))
         return recommended_a_id, action