Clara has approached a forest as shown in Figure 1. She knows that there is a leaf somewhere behind her, but the forest prevents her from getting to it. Your goal is to make Clara walk around the entire forest and collect her reward (meaning to eat the tasty leaf). A dotted line shown in Figure 2. resembles the required trajectory of Clara’s movement. Your solution must be generic enough to handle all supplied example worlds. The easiest way to approach this is to have Clara put her "hand" on the right wall of trees and then follow it.

University/Course: WSU

Uploaded: November 2, 2024

Files: 1

✓ Solution:

/* PERMITTED COMMANDS
   move, stop, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, else, &&, ||, ! */
   
class MyClara extends Clara { 
    /**
     * In the ‘act()’ function you can write your program for Clara 
     */
    void act() {
        // TODO: Write your code below
        if(onLeaf()){
        removeLeaf();
        stop();
        } else if (!treeRight()){
         turnRight();

 

🔒 Whatsapp us for the full file.