Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main()
- {
- char maze[80][80];
- int row, col, rIndex, cIndex;
- int MazeCount = 0;
- bool EndProgram = false;
- ifstream fin ("maze.dat");
- ofstream fout ("maze.out");
- Coordinate CurrentPosition;
- Stack MoveStack;
- fout << "Solutions to A-MAZE-ING Stacks Assignment" << endl;
- fout << "Name: Cody Chambers" << endl << endl;
- while(!EndProgram)
- {
- //read dimensions
- fin >> row >> col;
- if(row == -1 && col == -1)
- {
- EndProgram = true;
- fout << "End of program!!" << endl;
- exit(0);
- }
- //read maze into twoD array
- for (rIndex = 0; rIndex < row; rIndex++)
- for (cIndex = 0; cIndex < col; cIndex++)
- fin >> maze[rIndex][cIndex];
- fin >> CurrentPosition.Row >> CurrentPosition.Column;
- fin.close();
- while (maze[CurrentPosition.Row][CurrentPosition.Column] == '0')
- {
- //create west and north coordinates
- Coordinate West, North, South, East;
- West.Row = CurrentPosition.Row;
- West.Column = CurrentPosition.Column - 1;
- North.Row = CurrentPosition.Row - 1;
- North.Column = CurrentPosition.Column;
- South.Row = CurrentPosition.Row + 1;
- South.Column = CurrentPosition.Column;
- East.Row = CurrentPosition.Row;
- East.Column = CurrentPosition.Column + 1;
- //Is west available? If so, push it on the move stack
- if (MoveStack.AvailableMove(West, maze))
- {
- if (!MoveStack.Push(West))
- {
- cout << "Memory error" << endl;
- exit(0);
- }
- }
- //Is north available? If so, push it on the move stack
- if (MoveStack.AvailableMove(North,maze))
- {
- if (!MoveStack.Push(North))
- {
- cout << "Memory error" << endl;
- exit(0);
- }
- }
- if (MoveStack.AvailableMove(South,maze))
- {
- if (!MoveStack.Push(South))
- {
- cout << "Memory error" << endl;
- exit(0);
- }
- }
- if (MoveStack.AvailableMove(East,maze))
- {
- if (!MoveStack.Push(East))
- {
- cout << "Memory error" << endl;
- exit(0);
- }
- }
- maze[CurrentPosition.Row][CurrentPosition.Column] = '.';
- if (!MoveStack.Pop(CurrentPosition))
- {
- cout << "Stack Empty" << endl;
- fout << "MAZE NUMBER:" << MazeCount << endl << endl;
- for (rIndex = 0; rIndex < row; rIndex++)
- {
- for (cIndex = 0; cIndex < col; cIndex++)
- {
- fout << maze[rIndex][cIndex];
- }
- fout << endl;
- }
- fout << "There IS NOT a way out!!" << endl;
- break;
- }
- }
- if (maze[CurrentPosition.Row][CurrentPosition.Column] == 'E')
- {
- for (rIndex = 0; rIndex < row; rIndex++)
- {
- for (cIndex = 0; cIndex < col; cIndex++)
- fout << maze[rIndex][cIndex];
- fout << endl;
- }
- fout << "There IS a way out!" << endl;
- }
- else
- {
- for (rIndex = 0; rIndex < row; rIndex++)
- {
- for (cIndex = 0; cIndex < col; cIndex++)
- fout << maze[rIndex][cIndex];
- fout << endl;
- }
- fout << "There IS NOT a way out!" << endl;
- }
- fout.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement