Question: fix the following code using the right hand rule in C + + so the rat would seceesfully exit the maze: #include using namespace std;
fix the following code using the right hand rule in C so the rat would seceesfully exit the maze: #include
using namespace std;
const int ROWS ;
const int COLS ;
void printMazeconst char mazeCOLS int xLoc, int yLoc;
bool isValidMoveconst char mazeCOLS int x int y;
void moveRightint& x int& y int& facing;
void moveForwardint& x int& y int& facing;
void moveLeftint& x int& y int& facing;
void moveBackwardint& x int& y int& facing;
int main
char mazeROWSCOLS
############
###
#######
######
#####
########
######
#######
###
##########
###
############;
int xLoc ; Starting point
int yLoc ;
int facing ; up right, down, left
while true
printMazemaze xLoc, yLoc;
if xLoc && yLoc
cout "Congratulations! The maze has been solved.
;
break;
Try to move forward
moveForwardxLoc yLoc, facing;
if isValidMovemaze xLoc, yLoc
mazexLocyLoc;
continue;
Try to move right
moveRightxLoc yLoc, facing;
if isValidMovemaze xLoc, yLoc
mazexLocyLoc;
continue;
Try to move left
moveLeftxLoc yLoc, facing;
if isValidMovemaze xLoc, yLoc
mazexLocyLoc;
continue;
If unable to move in any direction, backtrack
moveBackwardxLoc yLoc, facing;
mazexLocyLoc;
return ;
void printMazeconst char mazeCOLS int xLoc, int yLoc
for int i ; i ROWS; i
for int j ; j COLS; j
if i xLoc && j yLoc
cout X;
else
cout mazeij;
cout
;
cout
Hit return to see next move
;
cin.get;
bool isValidMoveconst char mazeCOLS int x int y
return x && x ROWS && y && y COLS && mazexy#;
void moveRightint& x int& y int& facing
switch facing
case : up
y;
break;
case : right
x;
break;
case : down
y;
break;
case : left
x;
break;
void moveForwardint& x int& y int& facing
switch facing
case : up
x;
break;
case : right
y;
break;
case : down
x;
break;
case : left
y;
break;
void moveLeftint& x int& y int& facing
switch facing
case : up
y;
break;
case : right
x;
break;
case : down
y;
break;
case : left
x;
break;
void moveBackwardint& x int& y int& facing
switch facing
case : up
x;
break;
case : right
y;
break;
case : down
x;
break;
case : left
y;
break;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
