1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
In this programming assignment, you will implement the maze above using references to instances of a Node class, which you will define. Each node in the graph will be implemented as an instance of Node. The edges correspond to the links that connect one node to another and can be represented in Node as instance variables that reference another Node class object. Since there are four possible links, Node must contain four links (pointers) ̶ north, south, east and west ̶ to other Node objects.
The Start variable references is a Node pointer type that points to the node where the user starts, which may represent the room A. The goal is to reach the finish point which is the node that is referenced by the Finish variable which may reference the node representing the room L.
Graph Configuration
The configuration of the graph that you will use in the program will be read in from a text file. Your program must first prompt the user for name of the Graph Configuration file, e.g. graphConfig1.txt, and then opens the file for reading. Each line in the file indicates information on each node, i.e. the name of the node, and the links that may exist from that node to another node in the North, East, South and West directions. If there is no link in a specific direction, then there is an ‘*’ in place of the node name. For example, the configuration file for the graph above is as follows:
(This is what appears inside my Maze.txt file, so if you are testing my program just type the following in a txt document with no spaces)
A E B * *
B * * * A
C G * * *
D H * * *
E * F A *
F J G * E
G K H C F
H * * D G
I * J * *
J * * F I
K * L G *
L * * * K
In the first line of the configuration file above, the name of the node is A. It has a pointer to node E in the North direction and a pointer to node B in the East direction but no link in either the South or West direction. Thus the South and West pointers are set to NULL.
Your program will first read the graph configuration file and construct the graph data structures used for the Tiger Maze app. Your program must work with any graph configuration file. Several test configuration files will be released to you close to the deadline for you to test the correct execution of your program. All graph configuration files will have exactly twenty-four nodes, but their edges will be different.
To construct the graph based on the configuration file, you need to search for a certain node with a particular name, e.g. in the first line, Node A must be linked to Node E and you need to find E in order to set the north link of A to E. In order to search for E, the easiest way is to put every node in an array and then scan the array for a particular node name. Define a new class called NodeList that contains an array of Node pointers that points to all the nodes in the maze. The array may be initialized by creating the nodes in the array using new operator. Then each of the node is given the nae 'A', 'B', ... The NodeList contains a member function to search for a particular node with a particular name.
Traversing the Graph
The game will traverse the graph based on the inputs given by the user. When the user is at a current room, the program will output the possible moves in the North, East, South or West directions. The user will then enter the room in the desired direction. While the program traverses the graph, it also counts the number of steps. Upon reaching the finish point, it will print out the congratulation banner and the number of steps taken.
The user interface must check for correct input value from the users. If there is any error, e.g. selecting an invalid direction, then the program must display the appropriate error message and continue to prompt for the correct input. Your program must not exit or terminate when there is an incorrect input value.
|