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

Implemented a maze solution algorithm. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

emresururi
Copy link
Contributor

As the created maze is a 'perfect' maze i.e., every position can be
reached from any other position, it can be solved using a cellular
automata approach by marking the dead-ends as closed and shrinking the
available cells by checking their relations to these dead-ends of the
previous iteration and marking them as dead-ends as well if they only
have one open side (one entry and no exit) at each iteration.

  • df_maze.py :
  • A new method, 'solve_from_to(start,end)' is added. It uses cellular
    automata approach to find the path from the 'start' (a (x0,y0) tuple)
    position to the 'end' (a (x1,y1) tuple) position and returns a numpy
    array 'path_line' that contains the sequential cell positions (starting
    from the 'start', ending at the 'end' position). A check is made on the
    values of the 'start' & 'end' values to ensure that they both are within
    the boundaries of the maze.

  • Two new optional parameters ('start' & ''end') are added to the
    'write_svg()' method. If the 'end' parameter is supplied, the generated
    SVG image will contain the solution path from 'start' (default value:
    the entry position) to the end position.

  • Importing of numpy: Even though numpy's ndarrays are used for
    practical purposes and could have been substituted with Python's native
    lists as array (at the cost of extra procedures), numpy was crucial
    mostly for the 'logical_or()' function where cell-based direct
    evaluations could be made.

  • make_df_maze.py: The example case is expanded to demonstrate the maze
    solution algorithm.

  • maze.svg: is updated to be compatible with the newly generated
    solution image.

  • maze_solved.svg: The output of the 'write_svg()' method with the
    maze solution enabled, hence 'maze.svg' with the solution path embedded.

As the created maze is a 'perfect' maze i.e., every position can be
reached from any other position, it can be solved using a cellular
automata approach by marking the dead-ends as closed and shrinking the
available cells by checking their relations to these dead-ends of the
previous iteration and marking them as dead-ends as well if they only
have one open side (one entry and no exit) at each iteration.

* df_maze.py :
- A new method, 'solve_from_to(start,end)' is added. It uses cellular
automata approach to find the path from the 'start' (a (x0,y0) tuple)
position to the 'end' (a (x1,y1) tuple) position and returns a numpy
array 'path_line' that contains the sequential cell positions (starting
from the 'start', ending at the 'end' position). A check is made on the
values of the 'start' & 'end' values to ensure that they both are within
the boundaries of the maze.

- Two new optional parameters ('start' & ''end') are added to the
'write_svg()' method. If the 'end' parameter is supplied, the generated
SVG image will contain the solution path from 'start' (default value:
the entry position) to the end position.

- Importing of numpy: Even though numpy's ndarrays are used for
practical purposes and could have been substituted with Python's native
lists as array (at the cost of extra procedures), numpy was crucial
mostly for the 'logical_or()' function where cell-based direct
evaluations could be made.

* make_df_maze.py: The example case is expanded to demonstrate the maze
solution algorithm.

* maze.svg: is updated to be compatible with the newly generated
solution image.

* maze_solved.svg: The output of the 'write_svg()' method with the
maze solution enabled, hence 'maze.svg' with the solution path embedded.
df_maze.py: the boundary check should also have included the upper
limits of the maze dimensions. ('{<,>}=' instead of '{<,>}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants