Mouse in a Maze - A Computer Simulation

Nov 30, 2022
 

Computer models and simulations are often used to gain insight and understanding of real-world systems.  In our Mouse in a Maze project, we put a virtual mouse in a maze and let it wander randomly until it finds the piece of cheese.  In this simulation, there will be a "shortest path" that the mouse can take if it gets very lucky and always moves in a direction that puts it closer to the cheese.  However, since the movement is purely random, there also exists the possibility that the mouse will never reach the cheese!

By allowing the simulation to run a number of times and keeping track of how many moves the mouse makes before reaching the cheese, we can calculate an average.  We can then adjust the model to give the mouse some kind of feedback to help inform its next decision.  If the mouse has some way to separate "good" moves from "bad" moves, will it reach the cheese faster?

In math, the distance between two points can be calculated by:

This is known as the distance formula.  It is an application of the Pythagorean Theorem where the difference in the x-coordinates is the length of one side of a right triangle, and the difference in the y-coordinates is the length of the other side.

We can let the distance from the mouse to the cheese represent the mouse's ability to smell the cheese.  If the mouse moves in a direction that takes it farther from the cheese, the aroma will be less strong.  We can program the mouse to return to its previous point and choose its next direction again.  Of course, without any other rules, the mouse could choose the same direction, so there's no guarantee that this new algorithm will always result in fewer moves!

The simulation could be further adapted to let the mouse "remember" which direction resulted in a move that took it farther from the cheese, or it could be changed to let the mouse try to "predict" whether a move is a "good" move by calculating the distance from all possible next moves and only considering those where the aroma is stronger.  (This might simulate the mouse sniffing the air to get a sense of what direction to go.)

By analyzing the change in the average number of moves for each different algorithm, a programmer might be able to draw some conclusions about which optimizations have the greatest impact.  Maybe just being able to smell the cheese doesn't reduce the number of moves enough to justify the effort.

The results from a simulation like this are applicable to many contexts that have nothing to do with mice and cheese.  There are many types of applications where finding a short path between one point and another is advantageous - video games with wandering enemies trying to get the hero, GPS systems that provide driving directions, etc.  Lessons learned from working on this project can be applied to others as well.

Stay connected with news and updates!

Join our mailing list to receive the latest news and updates from our team.
Don't worry, your information will not be shared.

We hate SPAM. We will never sell your information, for any reason.

To learn more about how we can help you integrate STEM education at your campus or homeschool, contact us for a consultation. 

Schedule a Consultation