Hi,

this little function is finally able to solve the maze. However it prints out all the moves (even the once that lead nowhere). I can't figure out where to pop of the moves in order to print out only the right moves that lead to the end of the maze.

.Code:. bool SolveMaze(char array[][40], position pos) { stack<position> s; position curr_pos, next_pos; bool checked[40][40]; for(int i = 0; i < LENGTH; i++) for(int j = 0; j < WIDTH; j++) { checked[i][j] = false; } s.push(pos); while(!s.empty()) { curr_pos = s.top(); s.pop(); if(array[curr_pos.x][curr_pos.y] == 'X') return true; // visit the current position if(array[curr_pos.x][curr_pos.y] == '0' || array[curr_pos.x][curr_pos.y] == 'E') { if(array[curr_pos.x][curr_pos.y] == '0') array[curr_pos.x][curr_pos.y] = '*'; else if(checked[curr_pos.x][curr_pos.y] == true) return false; if(checked[curr_pos.x][curr_pos.y] == false) { next_pos.x = curr_pos.x; next_pos.y = curr_pos.y + 1; s.push(next_pos); next_pos.x = curr_pos.x; next_pos.y = curr_pos.y - 1; s.push(next_pos); next_pos.x = curr_pos.x + 1; next_pos.y = curr_pos.y; s.push(next_pos); next_pos.x = curr_pos.x - 1; next_pos.y = curr_pos.y; s.push(next_pos); } else { checked[curr_pos.x][curr_pos.y] = true; } } } return false; }

Can someone please help me?

Thanks.