the first two numbers represent the rows and columns (used for setting up the maze with the file reader).
The # sign represents a wall
The . represents a path
The S is start and E is end.
How would I read in this file and represent it as a 5x4 array of characters?
(will be solving this in the near future with recursive coding)
Help appreciated. Thanks!
now what i need to do is draw the maze some how. in the console of course. so would i scan the file for nextChar, nextChar, nextChar and just add those in to a character array then step through and print char, print char, print char. For each row in the maze?
Carl, note that you can't use primitives as generic type arguments. You can also use simple List variables, because you shouldn't care about ArrayList functionality. Keep in mind that by convention Java variable names start with a lower case. So that would be:
A char is probably simpler for this job though.
Awesome! I used a char and the BufferedReader and can draw the maze. Now, I want to solve it recursively. I will have the recursive code in another method called "mazeTraversal" and will call that method inside "openMaze"
I just want to know how I would make the program start at the "S" in the text file and continue from there to scan for possible solutions?
Let's say you had a function that "magically" finds the path to the exit, given a maze and a current position.
Now, you could write a function that checks if you could find an exit from north, east, south and west of the current position, provided that the way back (the current position) was walled off.
If such a path exists from that direction, you can add that direction to the start of the path, and return the list of directions. Show us how you would implement such a function if you had the magic findExit() method.
All right, here's a skeleton for you. Take a good look at how this code transforms a maze text file into an actual Maze object. Such a Maze object is much easier to manipulate, because you can define methods that perform small operations on it.
Now see if you can implement the findExit() method.