...it's the same program i've been trying to finish for weeks now. I still can't get it to work properly.
Can some loving person please help. I know this is qiute a bit of code to spiel....but this is just to help the kind one to undersand my algorithm.
Please.....
In the main I read the maze and print it( no problem with that). Then using the advance_maze function. Like so....
.Code:. int main() { Move curr_move; Curr_pos pos; char Maze[40][40]; char filename[12]; int rows = 0; int columns = 0; MOVEDEQUE A; 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, pos, filename); curr_move.maze_col = pos.col; curr_move.maze_row = pos.row; curr_move.move_number = 3; Print_m_array (Maze, rows, columns); A.push_back(curr_move); advance_maze(curr_move, A, Maze, &rows, &columns); Print_m_array (Maze, rows, columns); return 0; }
This is the part that is not working well.
.Code:. void advance_maze( Move &move, MOVEDEQUE &M, char m_array[][40], int *columns, int *rows) { int n; n = move.move_number; int nxtrow = 0; int nxtcol = 0; bool blocked; bool foundnxt_step; //Move current_m; //M.push_back(move); blocked = false; foundnxt_step = false; while (!M.empty()) { // move = M.back(); // M.pop_back(); //M.push_back(move); if (m_array[move.maze_row][move.maze_col] == '0' || m_array[move.maze_row][move.maze_col] == 'E' ) { m_array[move.maze_row][move.maze_col] = '*'; nxtrow = move.maze_row + position[n].vertical; nxtcol = move.maze_col + position[n].horizontal; move.maze_row = nxtrow; move.maze_col = nxtcol; for (; n<4;n++) { if ( nxtrow < *rows && nxtcol < *columns && m_array[move.maze_row][move.maze_col] == '0') { M.push_back(move); // m_array[move.maze_row][move.maze_col] = '*'; //move.maze_row = nxtrow; //move.maze_col = nxtcol; foundnxt_step = true; for (; n<4 && foundnxt_step == true; ) { m_array[move.maze_row][move.maze_col] = '*'; nxtrow = move.maze_row + position[n].vertical; nxtcol = move.maze_col + position[n].horizontal; move.maze_row = nxtrow; move.maze_col = nxtcol; if(m_array[move.maze_row][move.maze_col] != '0') { foundnxt_step = false; move = M.back(); //m_array[move.maze_row][move.maze_col] = '0'; n = 0; } else { M.push_back(move); //m_array[move.maze_row][move.maze_col] = '*'; } } /*if (m_array[nxtrow][nxtcol] != '0') { foundnxt_step = false; n=0; }*/ } else if (m_array[move.maze_row][move.maze_col] == 'X') { M.pop_back(); cout<< " Yah!!! Maze solved!! "<< endl; break; } if (foundnxt_step == false) { //M.pop_back for (; n<4 && foundnxt_step == false; n++ ) { //n++; nxtrow = move.maze_row + position[n].vertical; nxtcol = move.maze_col + position[n].horizontal; move.maze_row = nxtrow; move.maze_col = nxtcol; if (m_array[move.maze_row][move.maze_col] == '0')/// Why does it complain about a stack { /// overflow here? foundnxt_step = true; ///M.push_back(move); //n =0; } } if (n>3 && m_array[nxtrow][nxtcol] != '0') { blocked = true; M.pop_back(); move = M.back(); } } } } } if (M.empty() && blocked == true) { cout<< "Awwww... sorry, this maze cannot be solved."<< endl; } }
Thanks for taking a peek.!Really i'm very grateful.



LinkBack URL
About LinkBacks


