Skip to content

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