To use the Stack ADT to solve a maze.
The code that you write for this assignment will build on top of two ADTs (List and Stack) and their implementations. You must use the ADT interfaces and implementations I provide, not the Java Standard Library ones. The five files you will need are:
Do not modify the provided .java files (or the .class files, for that matter). None of these five files should be part of your submission for this assignment, either; only turn in the code you wrote.
Every source-code file you turn in must have your name in a comment at the top.
This is optionally a partner assignment. If you worked alone on the last assignment, you must work alone on this one too; if you work with a partner on this assignment, it must be the same partner as last time. Make sure to put both people's names at the top of each file. Write your code by pair-programming: code together, at the same computer, and switch off who's at the keyboard. Only one of you should ultimately submit your team's code via Moodle.
In this assignment, you will build on your work from the previous assignment to write a program that solves mazes. I'm giving you the algorithm to use to solve a maze; you just have to implement it.
Supplement your Maze.java from the last assignment to support solving mazes and printing the solved version.
Specifically:
Maze
class must include a method with the following signature:
/** * Computes and returns a solution to this maze. If there are multiple * solutions, only one is returned, and getSolution() makes no guarantees about * which one. However, the returned solution will not include visits to dead * ends or any backtracks, even if backtracking occurs during the solution * process. * * @return a stack of Square objects containing the sequence of squares * visited to go from the start square (bottom of the stack) to the finish * square (top of the stack). */ private Stack<Square> getSolution()
Your program's command line should follow the syntax:
java Maze <mazeFile> [--solve]
For example, suppose maze.txt contains:
6 5 0 0 0 4 L-_|_- |L--|_ |-_-|_ |L|L|| L__L__
then this command:
java Maze maze.txt
should print the maze with no solution, like so:
+-----+-----+-----+-----+-----+-----+ | | | | S | | | | | +-----+ +-----+ +-----+ + | | | | | | | | | | | | + +-----+ + + +-----+ | | | | | | | | | + + +-----+ + +-----+ | | | | | | | | | | | | | | | | | | | | | + +-----+ +-----+ + + | | | | F | | | | | +-----+-----+-----+-----+-----+-----+
However, this command:
java Maze maze.txt --solve
should print the maze with the path of a solution marked, like so:
+-----+-----+-----+-----+-----+-----+ | | | | S * | | | | | +-----+ +-----+ +-----+ + | | | | | | * * * | | | | | | + +-----+ + + +-----+ | | | | * * * * | | | | | + + +-----+ + +-----+ | | | | | | | | * | | | | | | | | | | | | | + +-----+ +-----+ + + | | | | F | | | | | +-----+-----+-----+-----+-----+-----+
Submit your Maze.java file on Moodle. (Only one submission per pair!)
Start early, ask lots of questions, and have fun!
This assignment originally designed by Jeff Ondich. Thanks for sharing, Jeff!