In this Problem you will teach Clara some advanced navigation skills. In her pursuit of leafy happiness Clara often has to escape from a maze. In Clara’s world, a maze might look like what is seen in Figure 1. A tasty juicy leaf always marks the exit to the maze. So Clara’s job is to navigate the corridors of the maze until she finds the leaf indicating the exit. Once this happens – Clara is finally allowed to eat the leaf and stop her search. The result of this is shown in Figure 2. The program you create must be general enough to solve any maze in Clara’s world, and not just the one pictured here. You can test this by opening all example worlds supplied with this exercise and making sure that Clara can solve all the mazes without modifying the code for every specific case. There are several strategies you could use for solving a maze. When Theseus needed to escape from the Labyrinth of Crete, he adopted—at the suggestion of King Minos’s daughter Ariadne, whom Theseus promptly abandoned on the next island he reached—the strategy of unwinding a ball of string as he explored the maze. You could devise a similar strategy for Clara, in which leaves serve the same function. The mazes in Clara’s world, however, are rather simple and she might also confuse the leaf that marks the exit with one of those she deposits during search. So the approach of Theseus is not an efficient choice for this exercise. Instead, you should use a simpler strategy called the right-hand rule, in which you begin by putting your right hand on the adjacent wall and then go through the maze without ever taking your hand off the wall. Another way to express this strategy is to proceed through the maze one step at a time, always taking the rightmost available path. Clara’s resulting orientation in the end is not important. But what is important is that in the end she eats the leaf and stops at the same location as where she found the leaf. The same result can be achieved by taking the leftmost available path (instead of going right), but it is important that in your solution you are taking the rightmost available path instead. You can count on the fact that there is only one leaf present in each of the mazes.

University/Course: WSU

Uploaded: November 4, 2024

Files: 1

✓ Solution:

/* PERMITTED COMMANDS
   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
class MyClara extends Clara { 
void run() {
// we move until we reach to the leaf
while (!onLeaf()) {
if (treeRight() && !treeFront()) {
                move();
continue;
            }
if (!treeRight()) {
                turnRight();
                move();
continue;

🔒 Whatsapp us for the full file.