In this module you will apply Top-Down engineering problem solving skills to reduce a well-defined but moderately complex problem to a series of smaller problems that will be implemented by a computer program. The goal is for the sub-problems to become sufficiently narrowly- and well-defined such that they can be implemented quickly and confidently.
A customer has hired you to design and implement a computer game. The game is intended to be used by people developing search algorithms for autonomous robots and some of the rules reflect that purpose.
The following is the description of the game that they have provided.
This game is a hidden maze game where the user starts off in the corner of a square maze. The maze consists of a grid of 2Nx2N squares (hence there will always be an even number of squares on each side). N will never be greater than 11. Each square is either open (meaning that the player can move into it) or blocked (meaning that they can't). The blocks are fixed and can't be moved. The goal of the player is to reach any of the center four (2x2) squares, all of which are open, in the fewest number of moves.
Initially, the only thing the person knows is the size of the maze, that that they are starting off in one of the corners and that the two adjacent blocks are both open. They don't even know which way they are facing within their starting square.
The outside boundaries of the maze are represented by 'X' characters. The goal squares are represented by '*' characters. If a given square within the interior is known to be open, it is represented by a ' ' (space character) and if it is blocked it is represented by a 'X'. Initially, all of the squares are unknown to the player and are represented by a '-' in the maze representation.
The player may only perform three actions - they may move forward by pressing the '8' key (if the square directly in front of them is open), they may turn ninety degrees to the left by pressing the '4' key, or they may turn ninety degrees to the right by pressing the '6' key. Each of these three actions counts as one move. In addition, they may exit the game at any time by pressing the 'x' key.
The player can only see the square directly in front of them and this is the only way they have of learning if a particular square is open or blocked.
The mouse's location is represented by a character at that location that also indicates the direction the mouse is facing. The possibilities are:
The maze is described by a text file with the following format:
Ignore all lines until the first line that starts with an '_' character is reached. This line represents the top boundary of the maze. The number of '_' on that line will be equal to the number of squares in one row of the maze plus two (for the two vertical bounding walls). From this you can determine the value of N.
The next 2N lines encode the interior of the maze. Each line starts with a '|' character (the left wall) and ends with a '|' character (the right wall). Between these two characters are exactly 2N characters that are either a ' ' (space) to represent an open square or a 'X' to represent a blocked square.
After the final interior row of the maze is presented, the bottom boundary of the maze is represented by a line of '=' characters. Like the top boundary, the number of characters on this line is two greater than the number of columns in the maze.
The program should ask the user for the name of the maze description file they want to use. It is acceptable to require that the maze file be in the current directory.
After loading the maze and randomly placing the mouse in one of the corner squares with a random orientation within that square, the user may wander through the maze seeking a path to any one of the goal squares. Any movement, either motion forward into an adjacent square or a turn within a square, is considered one move.
A game is over when the person reaches any of the center four squares or when they opt to quit the game. At this point, they should be told whether they won or lost and the total number of moves.