The problem was taken from Starter Problems
To find a way thru a maze from point s to e. I tweaked the problem to read the maze from a text file (say "Maze.txt". The PathFinder creates a Maze object from the file, finds a way thru it and outputs the maze with the solution to a new text file (e.g. named 'Solution to Maze.txt" as per the input filename). The PathFinder is able to deal with mazes of any height or width as long as it is rectangular.
To do a sample run,
p = PathFinder.new
p.findPath( "TestMaze.txt" )
This would create another text file named "Solution to TestMaze.txt" with the solution .
Under Influence of XP
Was simultaneously reading Ron Jeffries' book (see previous post) :). I did this the XP way, by which I mean I had a test store that I kept stashing test cases into as I went along.
ruby -w TestPathFinder.rb
The entire process took about 3 hrs including the tests, which is not bad by my standards.
The code has minimal comments at the same time, I feel it is quite readable. The only places I used comments are
- to blow my own trumpet in the file header
- I could not find a way to represent characters other than by using ASCII codes (71 instead of 'G'). Found another solution where he overcame this by using "G".. (eww..)