This plan/alogorithm isn’t the “best” possible one, but it is definitely one of the easiest. We’ll call it the “Turn Right Algorithm”.
For this algorithm we need to look at our maze in a slightly different way, as a grid.
If we split up the maze into different squares, it helps us to take our problem in smaller pieces. First we have our robot check if there is a wall in front of it in a given grid square. If there is, it will turn left and drive forward, if there isn’t, it will turn right and drive forward (even if it’s into another wall) into the next grid square. Then the process repeats for each square it goes into.
If you really want to see this in action, try doing this yourself on some scratch paper! (Doing this is a great way to practice solutions for complex problems, many programmers and engineers practice on paper first all the time!)
Suprisingly enough, this is all it will take to solve the maze! Our robot will not always take the quickest route, but in every maze, it will eventually find it’s way to the exit. Again, it’s not the “best” solution, but it’s still a solution and that’s all that matters. If any ideas for better plans/algorithms, come to your head, feel free to try them out on your own! Improving upon and creating new alogrithms is a skill even the most advanced engineers and programmers are always trying make better and better.
See if you can figure out the code for this plan/algorithm on your own. It sounds easy, but it’s still a bit challenging. Whenever you are ready to see parts of the solution, move on to the next page.