Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing the recursive method to traverse a maze, I really don\'t eve

ID: 3624182 • Letter: I

Question

I need help writing the recursive method to traverse a maze, I really don't even know where to start I'm pretty terrible at recursion. the Method needs to go through the maze and replace all the open spaces with the number 3 and then when it gets to the bottom right corner replace it with a 7, and then change all the 3's in the correct path to 7's.

Here's hows its supposed to work:

1. If the indicated loaction has not been visited before(doesn't contain 3),is not outside the bounds of the array, or does not contain a wall, we mark the current element as visited.
2. If we are teh in the LAST element in the array(row,column),then we are done,and we mark the cell as being part of the solution by storing '7',and finally the method should exit returning true.
3. Else
a. We move down one element
b. If the previous call was not "done" , try to move one element to the left
c. If the previous call was not done, try to move one element up.
d. if not done, try moving one element to the right.

Explanation / Answer

#include<iostream>

using std::cout;

using std::cin;

void mazeTraverse(char [12][12], int *, int *);

int main()

{

char maze[12][12] = {'#','#','#','#','#','#','#','#','#','#','#','#',

'#','.','.','.','#','.','.','.','.','.','.','#',

'.','.','#','.','#','.','#','#','#','#','.','#',

'#','#','#','.','#','.','.','.','.','#','.','#',

'#','.','.','.','.','#','#','#','.','#','.','X',

'#','#','#','#','.','#','.','#','.','#','.','#',

'#','.','.','#','.','#','.','#','.','#','.','#',

'#','#','.','#','.','#','.','#','.','#','.','#',

'#','.','.','.','.','.','.','.','.','#','.','#',

'#','#','#','#','#','#','.','#','#','#','.','#',

'#','.','.','.','.','.','.','#','.','.','.','#',

'#','#','#','#','#','#','#','#','#','#','#','#',};

int xpos = 4;

int ypos = 11;

for(int i = 0; i < 12; i++)

{

for(int j = 0; j < 12; j++)

cout << " " << maze[i][j];

cout << " ";

}

cout << " Commands to play";

cout << " To go left press 4";

cout << " To go right press 6";

cout << " To go up press 8";

cout << " To go down press 2";

do

{

if ((xpos == 2) && (ypos == 0))

{

cout << " Congratulations.";

cout << " The game is over.";

cout << " You have won the game. ";

break;

}

mazeTraverse(maze, &xpos, &ypos);

}while (true);

return 0;

}

void mazeTraverse(char maze[12][12], int *x, int *y)

{

int move;

do

{

cout << " Enter your move : ";

cin >> move;

if (move == 2)

{

if (maze[*x + 1][*y] == '.')

{

*x = *x + 1;

maze[*x][*y] ='X';

break;

}

}

else

if (move == 4)

{

if (maze[*x][*y - 1] == '.')

{

*y = *y - 1;

maze[*x][*y] ='X';

break;

}

}

else

if (move == 6)

{

if (maze[*x][*y + 1] == '.')

{

*y = *y + 1;

maze[*x][*y] ='X';

break;

}

}

else

if (move == 8)

{

if (maze[*x - 1][*y] == '.')

{

*x = *x - 1;

maze[*x][*y] ='X';

break;

}

}

else

cout << "Please enter a valid move.";

} while (true);

cout << " ";

for(int i = 0; i < 12; i++)

{

for(int j = 0; j < 12; j++)

cout << " " << maze[i][j];

cout << " ";

}

}