INNER CODE UNIT · Python
get_action
rlcode/reinforcement-learning · 1-grid-world/1-policy_iteration.py:78
def get_action(self, state):
random_pick = random.randrange(100) / 100
policy = self.get_policy(state)
policy_sum = 0.0
# return the action in the index
for index, value in enumerate(policy):
policy_sum += value
if random_pick < policy_sum:
return index
# get policy of specific state
def get_policy(self, state):
if state == [2, 2]:
return 0.0
return self.policy_table[state[0]][state[1]]
def get_value(self, state):