Created
May 22, 2020 07:30
-
-
Save addy1997/18b8852b9eaf250cd0ff6962ca653e39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#next step | |
def step(self, action): | |
action = self.actions | |
reward_dict = {'up':10, 'down':10, 'left':10, 'right':10, 'begin':0, 'obstacle':-5} | |
next_state = (self.agent_state[0]+self.actions_pos_dict[actions][0], | |
self.agent_state[1]+self.actions_pos_dict[actions][1] ) | |
if action == "up": | |
return (self.observation, reward_dict.value[0], action) | |
elif action == "down": | |
return (self.observation, reward_dict.value[1], action) | |
elif action == "right": | |
return (self.observation, reward_dict.value[2], action) | |
elif action == "left": | |
return (self.observation, reward_dict.value[3], action) | |
else: | |
return (self.observation, reward_dict.value[4])#the agent begins from start position | |
#out of bounds condition | |
if next_state[0] < 0 or next_state[0] >= self.grid_shape[0]: | |
return (self.observation, "This state is out of bounds") | |
elif next_state[1] <0 or next_state[1] >= self.grid_shape[1]: | |
return (self.observation, "This state is out of bounds") | |
#obstacle avoidance | |
iterations =10 | |
for i in range(iterations): | |
for j in range(obstacles): | |
if next_state[i] == self.obstacle_mask[j]: | |
start == [0,0] | |
next_state == start | |
return (self.observation, next_state, reward_dict.value[5]) | |
#condition for starting again | |
elif next_state == "begin": | |
self.observation = self.reset() | |
return (self.observation, reward_dict.value[4]) | |
def reset(self): | |
self.agent_state = copy.deepcopy(self.start_state) | |
self.current_map = copy.deepcopy(self.initial_map) | |
self.observation = self.grid_map_observation(self.initial_map) | |
self.render() | |
return self.observation | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment