Maze Solver: AI Module, Programming Assignment, University of XYZ

Verified

Added on  2019/09/20

|2
|405
|183
Homework Assignment
AI Summary
This document presents a solution to the maze solver assignment, which involves writing code to navigate a maze. The solution utilizes functions such as `moveRight()`, `moveLeft()`, and `solveMaze()` to explore the maze and find the exit. The `solveMaze()` function uses a combination of right-hand and left-hand wall-following techniques, moving right until it hits a wall, then moving left. The code also includes functions to get the current position of the player, check if the maze is complete, and print the maze for debugging. The solution demonstrates a fundamental approach to pathfinding in a grid-based environment, incorporating the use of given functions to interact with the maze and determine the correct moves to solve it. This comprehensive solution helps students understand how to apply AI concepts in a practical programming context.
Document Page
extern int getTotalKeys();
extern int getCurrentKeys();
extern int getNumSteps(); // returns the number of steps which you have made
so far. Might be useful for debugging purposes.
extern void getCurrentPosition(int * arr); // this puts the player's row into
arr[0], and the player's column into arr[1].
extern void readMaze(); // points will be taken off if you use this.
extern void printMaze(); // prints the current maze. Might be useful for
debugging.
extern int isComplete(); //returns 1 if the maze is complete, and 0 otherwise.
Useful for loop conditions
extern int move(int newRow, int newCol); // if possible, it moves the player
to the position specified. Returns 1 if successful move, 0 otherwise. If not
possible, it prints a handy error message explaining what happened. You are
definitely allowed to comment out the print statements if you get tired of
seeing the error messages.
extern int look(int newRow, int newCol); // if possible, it tells you what's
in the square you are looking at. It also returns the integer value of what is
in the square (see maze file explanation), or -1 if the look failed. If not
possible, it prints a handy error message explaining what happened. You are
definitely allowed to comment out the print statements if you get tired of
seeing the error messages.
void solveMaze();
int moveRight();
int moveLeft();
void solveMaze(){
printMaze();
while(!isComplete()){
while(moveLeft()){
printMaze();
}
while(moveRight()){
printMaze();
}
}
}
int moveRight(){
int currentPos[2];
getCurrentPosition(currentPos);
return move(currentPos[0], currentPos[1]+1);
}
int moveLeft(){
int currentPos[2];
getCurrentPosition(currentPos);
return move(currentPos[0], currentPos[1]-1);
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]