A6.2: A Maze Me

Announcements and Clarifications

7/1 - Fixed bug in last example.

Brief Description

Your task in this assignment is to a implement a program that solves mazes by either giving a path to solve the maze in the minimum number of moves or determining that no solution to the maze exists.

Goals and Requirements

Description

Your program will take a single command line argument, which specifies the maze file to read in. Your program should output three things:

  1. The input maze.
  2. If a solution exists, a copy of the input maze with the solution path marked with X's. If a solution does not exist, a copy of the input maze with all reachable rooms marked with an X.
  3. If a solution exists output the minimum number of steps to reach the goal, otherwise output "Solution not found".

If more than one solution exists display one of them, the solution displayed must have minimal length (there can be no other solutions that reach the end in fewer steps).

The file format is fairly straightfoward. The first line of the file will contain two integers, the first specifies the number of rows, r, in the maze and the second the number of columns, c. The next r lines will contain the rows of the maze, with c characters in each line. Do not make any assumptions about the size of the maze other than both r and c will be greater than zero. A variety of characters indicate the types of rooms in the maze:

  1. # - represents an impassible room, no solution can pass through or use this cell.
  2. S - represents the starting position of the player, only one starting position will be allowed per maze.
  3. G - represents the location the player is trying to reach, there will always be at least one such location (there may be more).
  4. . - represents an empty passible room in the maze.
  5. Digits 1 to 9 - represent special teleport rooms, if the player moves onto a teleport room, their next move can move them to any room adjacent to that digit anywhere in the maze. These rooms are not overwritten when the solution is displayed.
  6. v, ^, <, > - one-way rooms, the player cannot enter the room from the opposite direction of the arrow. For example if a room is > the player cannot enter that room from the right of the room but may enter the room from the left, above and below. These rooms are overwritten when the solution is displayed if they are part of the solution path.

Assume that input files that will be used to grade will follow the format specified.

Each turn the player may move in one of four directions, up, down, left and right. The player may not move into rooms that are impassible or move the wrong direction into one-way rooms. The player may also move off the edge of the board onto the opposite edge. For example, if our board looks like this (the player is in lower right corner):

G..
...
..S

If the player moves to the right he will be in the lower left corner, if he moves down he will be in the upper right corner.

Here are number of simple examples (the input is not echoed for the sake of brevity):

Input:

3 5
#####
#S.G#
#####
Output:
#####
#SXG#
#####
Solution takes 2 steps.
Input:
3 5
..#..
.S#G.
..#..
Output:
..#..
XS#GX
..#..
Solution takes 3 steps.
Input:
5 5
#####
#S.G#
#...#
#..G#
#####
Output:
#####
#SXG#
#...#
#..G#
#####
Solution takes 2 steps.
Input:
5 5
##.##
#S..#
###.#
#G#.#
#.###
Output:
##X##
#SXX#
###X#
#G#X#
#.###
Solution not found.
Input:
5 10
##########
#S......1#
#........#
#1......G#
##########
Output:
##########
#S......1#
#X......X#
#1......G#
##########
Solution takes 4 steps.
Input:
5 10
##########
#S<...>..#
#.<...<..#
#.>...<.G#
##########
Output:
##########
#S<..XXXX#
#X<..X<.X#
#XXXXX<.G#
##########
Solution takes 13 steps.
Input:
20 20
####################
#S<<<<<<<<<<<<<<<.G#
#.###############..#
#.#...<<.1.#######.#
#.#.#.##vvv######..#
#...#.##^^.####.#.##
#####.##.2.###2.#..#
#.....##...##..###.#
####.###vvv#.#.#...#
#.##.###...#.#..>..#
#......#.3.#....#..#
#.###########vvv####
#.....<...........3#
#.########.#########
#.#..<..1#.#1..<...#
#v#..<...#^#...<...#
#.#3.<...#.#...<..3#
#.########.#########
#.....>....#########
####################
Output:
####################
#S<<<<<<<<<<<<<<<.G#
#X###############.X#
#X#XXX<<.1.#######X#
#X#X#X##vXX######XX#
#XXX#X##^^X####.#X##
#####X##.2X###2.#XX#
#...XX##...##.X###X#
####X###vvv#.#X#XXX#
#.##X###...#.#XXX..#
#XXXX..#.3.#....#..#
#X###########vvv####
#X....<...XXXXXXXX3#
#X########X#########
#X#..<..1#X#1XXXXXX#
#X#..<...#X#...<..X#
#X#3.<...#X#...<..3#
#X########X#########
#XXXXXXXXXX#########
####################
Solution takes 82 steps.

The maze solution overwrites the empty rooms and the one-way rooms, but leaves the teleport rooms, start and end rooms present.

More sample mazes will be included as the week progresses.

Extra Credit

Implement additional types of rooms. The value of the extra credit will scale depending on the difficult of the addition feature, the amount of code and effort required and the degree of successs. Here are a couple ideas, others are possible (some are more difficult than others, they are generally ordered from easiest to hardest difficulty):

  1. E - elevators allows moving between adjacent floors on a 3D maze (add a height to the dimensions of the maze and input the floors one at a time separated by a blank line). Here's an example of a 3D maze:
    3 3 2
    S..
    .E.
    ...
    
    ...
    .E.
    ..G
    

    This is probably the simplest of the choices to implement.

  2. D - disappearing walls. These walls are impassible on even numbered turns, but passible on odd numbered turns. The BFS will have to be modified to allow solutions to be computed though the changes will not be major.

  3. Z - switches that will add/remove wall sections. Add two new wall tile indicators * and @, * will be passible like normal empty rooms, and @ will act like walls. If the player moves into the room with the switch * will become impassible and @ will be passible. If the player enter a room with Z again those walls revert to their initial state. Implementing this is similar to implementing disappearing walls, though more complex. For example:
    3 10
    ##########
    #SZ@Z*Z@G#
    ##########
    
  4. C - moving critters. These objects are move in a predefined pattern in the maze each turn, players cannot occupy the same cell as them. Depending how complex or general you make your critter this can be very easy or very hard.

Do not work on the extra credit unless the required portion of the program functions, also extra credit code should not interfere with the normal functions of the program.

Commenting and Style

Handin

Please hand all necessary files into your handin directory in a subdirectory named Amaze. Your application class should be called Amaze.java. There should be exactly one class declared within each .java file. If your program does anything strange (bugs), awesome(extra features) or has a non-intuitive interface please include a file called README.txt which explain them. If there are bugs in your program but you do not describe them in your README you will lose more credit than if you had described them.

Hints