Question: Write 3 functions that simulate the activity of a mouse moving in a room. The room is described by a N times N matrix. Each

 Write 3 functions that simulate the activity of a mouse moving

Write 3 functions that simulate the activity of a mouse moving in a room. The room is described by a N times N matrix. Each location in the matrix has one of 3 values: 0 = empty space, 1 = cheese, 2 = mouse Each turn the mouse moves using the following rules: If there is cheese next to the mouse (up, down, left or right), the mouse moves on top of one of the adjacent cheeses and eats it, removing that cheese. If there is no cheese next to the mouse, the mouse moves in a random direction, up, down, left or right. The mouse cannot leave the room. You should write 3 functions: Make Room - takes as input the size, N, of the room and the number of pieces of cheese, C. Returns as output the N times N matrix called Room that has one mouse and C pieces of cheese randomly placed. Also, returns as output mrow, mcol, which are the row and column of the mouse. Move Mouse - takes as input the matrix Room, the number of pieces of cheese, C, and the row and column of the mouse, mrow and mcol. Moves the mouse according to the rules given above. Returns the updated room called New Room, and the updated mouse row and column, called new row and newton and the updated number of pieces of cheese, new C. Simulate - takes as input the size N of the room and the number of pieces of cheese, C. Creates a room by calling Make Room. Then repeatedly calls Move Mouse, outputs the Room matrix to the screen, and asks the user to press return to continue, until all the cheese is eaten

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!