Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool notSolved = true;
- int path = 0;
- row = 0;
- col = 0;
- rowStack.push(row);
- colStack.push(col);
- while (notSolved){
- //(from perspective of person looking at maze on screen)
- if (maze[row--][col] == 0){//if you can go up, go down
- rowStack.push(row);
- colStack.push(col);
- path++;
- }
- else if (maze[row][col++] == 0){//else if you can go right, try to go right
- rowStack.push(row);
- colStack.push(col);
- path++;
- }
- else if (maze[row++][col] == 0){//else if you can go down, try to go down
- rowStack.push(row);
- colStack.push(col);
- path++;
- }
- else if (maze[row][col--] == 0){//else if you can go left, try to go left
- rowStack.push(row);
- colStack.push(col);
- path++;
- }
- if(row == (size - 1) && col == (size - 1)){//if we reached an exit
- cout << "Solution Path:" << endl;
- for (int i = 0; i < path; i++){
- cout << "row:" << rowStack.top() << " col:" << colStack.top() << endl;
- rowStack.pop();
- colStack.pop();
- }
- notSolved = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement