Well..i didn't want to drive anyone off by pasting all the code. However I think that's what I have to do now. My program solves a maze... or attempts to...using standard library template deques.
This first part is fine.
.Code:. 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; curr_move.move_number = 0; 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; Print_m_array (Maze, rows, columns);
I don't get any errors , however when I print out the 'solved maze' I just get back what I read in...which is unsolved. Debugging doesn't help either...when it get's to that part...it just exits without my permission.
.Code:. while( Maze[curr_move.maze_row][curr_move.maze_col] != 'X' && !blocked) { if (!legal_move(Maze, curr_move)) { curr_move.move_number ++; if (curr_move.move_number > 3) { curr_move.move_number = 0; ///(advance_peg(move)) move back in the deque to the previous move; A.pop_back(); } } if (legal_move == true) { A.push_back(curr_move); curr_move.move_number = 0; advance_maze(curr_move, A, Maze); } /*Update the move number . Place * after a valid move in the maze curr_move.move_number ++; Maze[curr_move.maze_row][curr_move.maze_col] = '*'; curr_move.maze_row = curr_move.maze_row ++; curr_move.maze_col = curr_move.maze_col ++;*/ if (A.empty()) { blocked = true; } if (blocked == true) { A.pop_back(); /* reset the position ie set the current position to the previous value, /** what I just poped back.*/ } else { A.pop_back(); Print_m_array (Maze, rows, columns); } } return 0; }
This is what my advance_maze function and my legal fuction look like......
.Code:. bool legal_move(char Maze[40][40], Move &move) { int n; n = move.move_number; if (Maze[move.maze_row + position[n].move_left] [move.maze_col + position[n].move_down] == 0 && Maze[move.maze_row + position[n].move_right] [move.maze_col + position[n].move_up] == 0) return true; else return false; } void advance_maze( Move &move, MOVEDEQUE &M, char m_array[][40]) { m_array[move.maze_row][move.maze_col] = '*'; move.maze_row = move.maze_row + 1; move.maze_col = move.maze_col + 1; }
Why am I not getting a solved maze ? Am I using the wrong algorithm? or I'm I still being silly? Please tell me.
thanks



LinkBack URL
About LinkBacks


