Reputation: 63
I'm trying to read a "pointer-based" maze. The first letter in each row corresponds to the room letter...then the letters that follow are North node, East node, South node, and West node respectively. The asterisk indicates an empty room or not a valid option.
So this would be a sample input:
A E B * *
B * * * A
C G D * *
D * * * C
E I F A *
F J G * E
G K H C F
H L * * G
I * J E *
J * K F I
K * * G J
L * * H *
Notes say:
We can't assume the rooms will be in order alphabetically A - Z, We are expecting a maximum of 12 rooms and there is a space between each letter or asterisk.
Here is what I have so far:
void Maze::read_maze(string FileName) {
string line;
ifstream inStream;
inStream.open(FileName.c_str());
int test = inStream.peek();
int i = 0;
if (!(inStream.fail())) {
while (!inStream.eof() && test != EOF) {
getline(inStream, line);
Node n(line[0]);
i++;
rooms[i] = n;
if (!(line[2] == '*')) {
Node North = find_Node(line[2]);
(find_Node(line[0])).set_North(&North);
}
if (!(line[4] == '*')) {
Node East = find_Node(line[4]);
(find_Node(line[0])).set_East(&East);
}
if (!(line[6] == '*')) {
Node South = find_Node(line[6]);
(find_Node(line[0])).set_South(&South);
}
if (!(line[8] == '*')) {
Node West = find_Node(line[8]);
(find_Node(line[0])).set_West(&West);
}
}
currentRoom = find_Node('A');
} else {
cout << "Could not open the file, please choose another.\n" << endl;
exit(1);
}
}
When I begin parsing the file, my program calls the function I have that checks if the file is empty. So I think I'm reading the file in incorrectly.
Upvotes: 1
Views: 539
Reputation: 106
Can you not use a debugger to check the values as the program runs? If not, then try a
cost << line << endl;
After the getline, to verify the actual data read in for each line.
Upvotes: 1