Implemented a maze solution algorithm. #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.