I heeded the advice I was given. I made my code more readable... I thought through it. I sought help from my peers and my proff, but still to no avail. I really need help. Can some lovely person please help me.
The first part works without a problem.
.Code:. struct move_record{ int horizontal; int vertical; }; struct Move{ int maze_row; int maze_col; int move_number; }; struct Curr_pos{ int row; int col; }; using namespace std; typedef deque<Move> MOVEDEQUE; /* Declaring Prototypes*/ void Read_file (char m_array[][40], int *columns, int *rows, Curr_pos &start, char *filename); void Print_m_array (char m_array[][40], int rows, int columns); bool legal_move(char [40][40],Move &); void advance_maze( Move &move, MOVEDEQUE &M, char m_array[][40]); move_record position[4] = { {-1,0}, { 1,0}, {0,-1}, { 0,1} }; int main() { Move curr_move; Curr_pos start; char Maze[40][40]; char filename[12]; int rows = 0; int columns = 0; MOVEDEQUE A; bool blocked; cout<< "Please enter the name of the maze file you want to read, or (q) to quit.\n" << endl; cout<< "(a) maze1.txt\n(b) maze2.txt\n(c) maze3.txt\n"<< endl; cin.getline (filename, 10); if (filename[0] == 'q') { return 0; } Read_file (Maze, &columns, &rows, start, filename); // printf("%d,%d \n", start.row, start.col); curr_move.maze_col = start.col; curr_move.maze_row = start.row; curr_move.move_number = 0; Print_m_array (Maze, rows, columns); Maze[curr_move.maze_row][curr_move.maze_col] = '0'; A.push_back(curr_move); blocked = false; advance_maze(curr_move, A, Maze); Print_m_array (Maze, rows, columns); return 0; }
*****The section with the problem is this:
.Code:. void advance_maze( Move &move, MOVEDEQUE &M, char m_array[][40]) { int n; n = move.move_number; bool blocked; //M.push_back(move); while (!M.empty()) { move = M.back(); M.pop_back(); printf("%c\n",m_array[move.maze_row][move.maze_col]); /*** I don't understand why it doesn't execute this if statement ... not even the first time. It shd...right? if (m_array[move.maze_row][move.maze_col] == 0) { m_array[move.maze_row][move.maze_col] = '*'; M.push_back(move); Print_m_array (m_array, move.maze_row, move.maze_col); m_array[move.maze_row][move.maze_col]= m_array [move.maze_row +position[n].vertical][move.maze_col + position[n].horizontal]; } else if (m_array[move.maze_row][move.maze_col] == 'X') { cout<< " Yah!!! Maze solved!! "<< endl; break; } if (m_array[move.maze_row][move.maze_col] == 1) { M.pop_back(); n++; m_array[move.maze_row][move.maze_col] = m_array[move.maze_row +position[n].vertical][move.maze_col+position[n].horizontal]; } if (n>3) { blocked = true; M.pop_back(); n = 0; m_array[move.maze_row +position[n].vertical][move.maze_col+position[n].horizontal]; } } if (M.empty() && blocked == true) { cout<< "Awwww... sorry, this maze cannot be solved."<< endl; } }
thanks for taking a look.



LinkBack URL
About LinkBacks


