Reference no: EM132268008
Mini Project - Mouse and Cheese
Introduction - A biological research firm wants you to build a simulation of a mouse trying to find a piece of cheese in a maze. In the function you will write, you will have a representation of the mouse, cheese, and obstacles in a maze. In this representation:
- The number 0 represents an empty space without a mouse, cheese, or an obstacle.
- The number 1 represents the mouse.
- The number 2 represents the cheese.
- The number 3 represents obstacles.
An example of this is shown below:
You can create this example with the following code:
x = zeros(10,10);
x(2, 2) = 1;
x(9, 8) = 2;
x(3, 3) = 3;
x(5, 3) = 3;
x(5, 6) = 3;
x(7, 4) = 3;
x(8, 6) = 3;
Feel free to use this example to test your code, but do note that the code you will write should work on a matrix of any size.
You can also visualize a matrix by using the imagesc(matrixName) command, where matrixName is the name of the matrix you want to visualize. Note that for this project, when you visualize a matrix in this way, mice will be blue, obstacles will be yellow, and cheese will be green. Empty spaces will be purple.
Procedure - You should write a function that takes one input, a maze with the locations of obstacles, mouse, and cheese already in place. Your code should return two outputs:
- cheeseFound, a Boolean variable that says whether the mouse found the cheese.
- finalState, a matrix of the last state of the maze.
Your code should simulate the mouse going through the maze by iterating through the sequence of moves it makes. The mouse has the following set of rules:
1. The mouse always knows the vertical and horizontal distance between itself and the cheese because of its excellent sense of smell. Your program should perform the appropriate commands to determine how far the mouse is from the cheese at the start, and then update that distance as the mouse moves.
2. The mouse only moves vertically and horizontally (up, down, left, or right).
3. The mouse must move within the maze by increments of 1 space.
4. The mouse cannot leave the maze.
5. The mouse always knows the last move it made, and cannot move back to the previous square it was just in.
Attachment:- Assignment File.rar