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

The following grid is a double-subscripted array representation of a maze. The #

ID: 3848454 • Letter: T

Question

The following grid is a double-subscripted array representation of a maze. The # symbols represent the walls of the maze, and the periods (.) represent squares in the possible paths through the maze. There's a simple algorithm for walking through a maze that guarantees finding the exit (assuming there's an exit). If there's not an exit, you arrive at the starting location again. Place your right hand on the wall to your right and begin walking forward. Never remove your hand from the wall. If the maze turns to the right, you follow the wall to the right. As long as you do not remove your hand from the wall, eventually you arrive at the exit of the maze. There may be a shorter path than the one you have taken, but you're guaranteed to get out of the maze. Write recursive function mazeTraverse to walk through the maze. The function should receive as arguments a 12-by-12 character array representing the maze and the starting location of the maze. As maze Traverse attempts to locate the exit from the maze, it should place the character X in each square in the path. The function should display the maze after each move so the user can watch as the maze is solved.

Explanation / Answer

/*function for maze matrix consider sides of the wall with the matrix index. if there is # in next index position that means moment increase by next step witha recursion function. and comtinues.

If there is no # present in the next index position there again it starts from the beginning of the matrix position.

Here lets consider matrix initial position be maze[0][0] */

mazeTraverse(int a,int b, int maze[][]){ //a and b are index identifiers, maze is a 12*12 matrix of the maze

if(maze[a][b+1]=='#'){

mazeTraverse(a,b+1,maze);

}

else if(maze[a][b+1]!='#'){

mazeTraverse(0,0,maze); //as there is no right wall beginning from from initial postion

}

else

printf("Reached destination with shortest path");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote