relevant comments and indentations should be included.
Modified Code:
#include <stdio.h>
#include <stdlib.h>
/ function main /
int mazeTraverse(char mazePtr[12][12], int currentRow, int currentColumn);
void printMaze(char maze[12][12], const int currentRow, const int currentColumn);
int main(void) {
int startrow = 2, startcoloumn = 0, state = 0;
/ 12 by 12 array /
char maze[12][12] = {
};
printf("The maze\n********\n");
printMaze(maze, 12, 12);
/**
** below lines will pause the execution and clear the screen.So it is better to comment it
**/
//system("pause");
//system("cls");
//printf("\n");
state = mazeTraverse(maze, startrow, startcoloumn);
if (state == 0) {
printf("\nPlayer found the exit!\n\n");
}
system("pause");
return 0;
}
int startingFlag = 1, direction = 0;
enum Stat {
OVER,
NOT_OVER
};
/ function main core /
int mazeTraverse(char maze[12][12], int currentRow, int currentColumn) {
int gameOver(const int currentRow, const int currentColumn);
int move(char maze[12][12], int currentRow, int currentColumn, int * currentDirection);
enum Stat State;
/ check if game is over /
State = gameOver(currentRow, currentColumn);
if (State == OVER && startingFlag == 0) {
printMaze(maze, currentRow, currentColumn);
return OVER;
}
/ indicate player is ready /
if (startingFlag == 1) {
/ print initial maze /
printf("Player's ready\n**************\n");
printMaze(maze, currentRow, currentColumn);
/**
** below lines will pause the execution and clear the screen.So it is better to comment it
**/
//system("pause");
//system("cls");
if (currentRow == 0) {
direction = 1;
} else if (currentRow == 11) {
direction = 0;
} else if (currentColumn == 0) {
direction = 2;
} else if (currentColumn == 11) {
direction == 3;
}
startingFlag = 0;
}
/**
** below lines will clear the screen.So it is better to comment it
**/
//system("cls");
/ seek for next move /
/**
** move function needs four parameters
** that are maze, ¤tRow, ¤tColumn, &direction
** but before only three parameters are passed. That's why it prints an error
**/
move(maze, ¤tRow, ¤tColumn, &direction );
mazeTraverse(maze, currentRow, currentColumn);
return OVER;
}
/*seek for next move*/
enum Direction {
NORTH,
SOUTH,
EAST,
WEST
};
int move(char maze[12][12], int currentRow, int currentColumn, int * currentDirection) {
int posibble[4] = {
0
};
int counter = 0;
enum Direction Seek;
Seek = * currentDirection;
/*move player in respect to current direction*/
maze[ currentRow][ currentColumn] = '.';
if (Seek == NORTH) {
/ print direction /
printf("direction = NORTH\n");
/ move north /
* currentRow -= 1;
} else if (Seek == SOUTH) {
/ print direction /
printf("direction = SOUTH\n");
/ move south /
* currentRow += 1;
} else if (Seek == EAST) {
/ print direction /
printf("direction = EAST\n");
/ move east /
* currentColumn += 1;
} else if (Seek == WEST) {
/ print direction /
printf("direction = WEST\n");
/ move west /
* currentColumn -= 1;
}
//print each move
printMaze(maze, currentRow, currentColumn); // print maze with player current position
/*analyse for next direction*/
//seek posibble direction
printf("Seek next direction...\n\n");
if (maze[ currentRow - 1][ currentColumn] == '.' && Seek != SOUTH) {
printf("NORTH is possible\n");
posibble[0] = 1;
counter++;
}
if (maze[ currentRow + 1][ currentColumn] == '.' && Seek != NORTH) {
printf("SOUTH is possible\n");
posibble[1] = 1;
counter++;
}
if (maze[ currentRow][ currentColumn + 1] == '.' && Seek != WEST) {
printf("EAST is possible\n");
posibble[2] = 1;
counter++;
}
if (maze[ currentRow][ currentColumn - 1] == '.' && Seek != EAST) {
printf("WEST is possible\n");
posibble[3] = 1;
counter++;
}
printf("\n");
if (counter == 1) {
if (posibble[1] == 1) { / south /
* currentDirection = 1;
} else if (posibble[2] == 1) { / east /
* currentDirection = 2;
} else if (posibble[0] == 1) { /*north */
* currentDirection = 0;
} else if (posibble[3] == 1) { / west /
* currentDirection = 3;
}
} else if (counter == 2) {
if (posibble[2] == 1 && posibble[3] == 1) {
if (Seek == SOUTH) { * currentDirection = 3;
} else if (Seek == NORTH) { * currentDirection = 2;
}
} else if (posibble[0] == 1 && posibble[1] == 1) {
if (Seek == EAST) { * currentDirection = 1;
} else if (Seek == WEST) { * currentDirection = 0;
}
} else if (posibble[0] == 1 && posibble[3] == 1) { / NORTHWEST /
* currentDirection = 0;
} else if (posibble[0] == 1 && posibble[2] == 1) { / NORTHEAST /
* currentDirection = 2;
} else if (posibble[1] == 1 && posibble[2] == 1) { / SOUTHEAST /
* currentDirection = 1;
} else if (posibble[1] == 1 && posibble[3] == 1) { / SOUTHWEST /
* currentDirection = 3;
}
} else if (counter == 3) {
if (Seek == NORTH) { * currentDirection = 2;
} else if (Seek == SOUTH) { * currentDirection = 3;
} else if (Seek == EAST) { * currentDirection = 1;
} else if (Seek == WEST) { * currentDirection = 0;
}
} else if (counter == 0) {
//dead end
if (Seek == NORTH) { * currentDirection = 1;
} else if (Seek == SOUTH) { * currentDirection = 0;
} else if (Seek == EAST) { * currentDirection = 3;
} else if (Seek == WEST) { * currentDirection = 2;
}
}
}
/*check if game is over*/
int gameOver(const int currentRow,
const int currentColumn) {
if (currentRow == 0 || currentRow == 11 || currentColumn == 0 || currentColumn == 11) {
return OVER;
} else {
return NOT_OVER;
}
}
/*print current maze*/
void printMaze(char maze[12][12],
const int currentRow,
const int currentColumn) {
int mazeRow, mazeColumn;
printf("\n ");
for (mazeRow = 0; mazeRow < 12; mazeRow++) {
for (mazeColumn = 0; mazeColumn < 12; mazeColumn++) {
if (mazeRow == currentRow && mazeColumn == currentColumn) {
maze[mazeRow][mazeColumn] = 'X';
}
printf("%2c", maze[mazeRow][mazeColumn]);
}
printf("\n ");
}
printf("\n");
} / end programme /
Output:
The maze
********
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Player's ready
**************
# # # # # # # # # # # #
# . . . # . . . . . . #
X . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. X # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# X . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . X . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . X # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # X # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # X # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . X . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . X . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# X . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . X . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . X . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . X # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # X # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # X # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # X # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . X . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . X . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . X . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
WEST is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # X # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . X # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# X . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . X # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # X # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . X . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# X . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . X . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . X . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . X . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . X . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . X . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
SOUTH is possible
EAST is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # X # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
SOUTH is possible
direction = SOUTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . X # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . X . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . X . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . X . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . X . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# X . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . X . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . X . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . X . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . X . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . X # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # X # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . X . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
EAST is possible
WEST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . X . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
EAST is possible
direction = EAST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . X # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # X # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # X # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . .
# # # # . # . # X # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # X # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
NORTH is possible
direction = NORTH
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . X # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . X . # . #
# . . . . # # # . # . .
# # # # . # . # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #
Seek next direction...
WEST is possible
direction = WEST
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . X . . # .
relevant comments and indentations should be included. Q1: (Recursive Maze Traversal) (75 points) The following grid...
Hey everyone, I have a programing projest from teacher, but I don't understand what is says.....Anyone can help? (Maze Traversal) The following grid of #s and dot ( . ) is a double-subscripted array representation of a maze. # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . ...
This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#) and dots(.) is a 2D array representation of a maze # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . #...
Code a program and reads a maze file and exits non-zero if the maze is not valid. Or outputs the maze in a frame if it is good. The name of the file containg the maze is the only command-line parameter to this program. Read that file with the stdio functions, and close it propperly. A maze is a rectangular array of characters. It is encoded in the file in 2 parts: header line The header has 2 decimal intergers...
PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and mark a path out of the maze, which is represented by a 20x20 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically or horizontally in any direction that contains a 0; you may not move into a square with a 1. If you move into the square with...
Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares, such as the following one: X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Figure...
I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up to you, but at a minimum, you should have a Maze class with appropriate constructors and methods. You can add additional classes you may deem necessary. // This program fills in a maze with random positions and then runs the solver to solve it. // The moves are saved in two arrays, which store the X/Y coordinates we are moving to. // They are...
Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...
Write the following functions, as defined by the given IPO comments. Remember to include the IPO comments in your submission. Be sure to test your code -- you can use the examples given for each function, but you should probably test additional examples as well -- and then comment-out or remove your testing code from your submission!. We will be testing your functions using a separate program, and if your own testing code runs when we load your file it...
In this question, you will test, using a backtracking algorithm, if a mouse can escape from a rectangular maze. To ensure consistency of design, start your solution with maze_start.c. The backtracking algorithm helps the mouse by systematically trying all the routes through the maze until it either finds the escape hatch or exhausts all possible routes (and concludes that the mouse is trapped in the maze). If the backtracking algorithm finds a dead end, it retraces its path until it...
c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....