Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maze Goal Generator #13

Merged
merged 12 commits into from
Jan 8, 2019
Next Next commit
random goal generator
  • Loading branch information
e-dzia committed Dec 13, 2018
commit 6c63455de9203b8b95234909ed01b5e8a4321cff
17 changes: 17 additions & 0 deletions examples/maze_get_goal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
from random import choice

import gym
import sys
sys.path.insert(0, '/home/e-dzia/openai-envs')
# noinspection PyUnresolvedReferences
import gym_maze

logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
maze = gym.make('MazeF1-v0')

goal = maze.maze.get_goal_state()

logging.info("Finished")
3 changes: 3 additions & 0 deletions gym_maze/envs/abstract_maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,6 @@ def _render_element(el):
return utils.colorize('A', 'red')
else:
return utils.colorize(el, 'cyan')

def get_goal_state(self):
return self.maze.get_goal_state()
12 changes: 12 additions & 0 deletions gym_maze/maze.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

PATH_MAPPING = 0
WALL_MAPPING = 1
REWARD_MAPPING = 9
Expand Down Expand Up @@ -174,3 +176,13 @@ def get_possible_neighbour_cords(pos_x, pos_y) -> tuple:
nw = (pos_x - 1, pos_y - 1)

return n, ne, e, se, s, sw, w, nw

def get_goal_state(self):
pos_x = random.randint(0, self.max_x - 1)
pos_y = random.randint(0, self.max_y - 1)

while self.matrix[pos_y, pos_x] == WALL_MAPPING:
pos_x = random.randint(0, self.max_x - 1)
pos_y = random.randint(0, self.max_y - 1)

return self.perception(pos_x, pos_y)