#Clara World Help Needed! (Back Again)

1 messages ยท Page 1 of 1 (latest)

split fernBOT
#

<@&987246399047479336> please have a look, thanks.

split fernBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

I'm sorry, but I cannot see the image you mentioned. As an AI text-based model, I am unable to process or view images. However, I'll do my best to help you with your question. Could you please provide a detailed description of the problem you are facing with Clara turning at the wrong time?

patent sparrow
#

can u draw the path/approach that u want ur clara to move?

#

vs what its currently doing

#

its so hard to visualize whats going on otherwise

#

and just staring at code doesnt help much

unreal hare
#

im on mac idk how to do that

patent sparrow
#

is there no ms paint thing?

unreal hare
#

uh no

#

dont think so

patent sparrow
#

can u perhaps describe it?

unreal hare
#

yes wait one sec

#

so what happens is it turns there

#

and moves

#

and does some random stuff

#

when it is supposed to take the mushrrom to here:

#

and then it is supposed to go behind the mushrrom

patent sparrow
#

can we start with the path that u intend clara to walk?

#

cause there are obviously multiple ways to approach it

unreal hare
#

ok

#

honestly idk if moveBy function works

#

tbh

#

i was planning to firstly count the steps till the leaf

#

and thne come back push the mushroom into position

#

and then from behind push it forward the no. of steps that was calculated until the leaf

patent sparrow
#

so u first want to move just right until u see leaf? then turn around and move back to the start?

unreal hare
#

but idk if that works

#

ok so this is how it starts so u can visualise it better

patent sparrow
#

like this?

#

first red, then yellow

unreal hare
#

yeah basically

patent sparrow
#

does the first phase with the leaf work?

#

when does it start misbehaving?

unreal hare
#

but if u turn the mushroom doesn't come with you

#

so i want everything to be in position

#

and then move the mushroom and clara by "i" steps which was calculated before

#

i = distance to leaf

#

whatever u can see there are the different stages of the problem

#

so black first

#

then red

#

then yellow

#

then purple

#

and also it does work i is supposed to be 9 and it is

patent sparrow
#

yeah. perhaps u should rename i but yeah

#

distanceToLeaf for example

#

now u have to move that many tiles back again

unreal hare
#

yes

patent sparrow
#

and then 2 up, one right, one down

#

then the mushroom is in place

unreal hare
#

yeah

#

and that is the same for the 2nd world

#

too

#

and then i will push the mushroom by the distance calc. earlier

patent sparrow
#

yeah. so where is the problem now

#

up to where does ur code work

#

when does it start misbehaving

unreal hare
#

here is the code.

#

and also does moveBy(i) a valid thing like is it proven to work?

patent sparrow
#

all the methods ur using here are clara specific things

#

they dont exist in normal java

unreal hare
#

ik

patent sparrow
#

is it on the way back from the leaf?

unreal hare
#

because there is a whole list of functions or methods that have been predefined

unreal hare
#

into position

patent sparrow
#

u see how clara moves step by step though, dont u?

#

so why are u unsure

unreal hare
#

because idk why an error is occuring

patent sparrow
#

yeah but u first have to describe to me whats going on

#

bc i literally cant see clara moving

#

i only see a static image u posted

#

which doesnt tell me where clara is coming from and where in the code we are currently at

#

ill take a guess and u tell me if thats what has happened so far:

#

or was clara already above the shroom?

#

and went down again

#

or is this even before going to the leaf?

unreal hare
#

no this is after

unreal hare
patent sparrow
#

okay. lets now look at ur code

#

right now its hard to read bc u didnt follow proper indentation rules

#

please auto-format ur code

#

(hit the auto format key in ur IDE)

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // TODO: Write your code below
    int i = 0;
    int n = i + 1;
    while (!onLeaf()) {
      move();
      i++;
      if (onLeaf()) {
        turnRight();
        turnRight();
        break ;
      }
    }
    for (int k = 0; i < n; k++) {
      move();
      if (treeFront()) {
        turnRight();
        break ;
      }
    }
    while (!treeFront()) {
      move();
      if (treeFront()) {
        turnRight();
        move();
        turnRight();
        move();
        break ;
      }
    }
    if (mushroomFront()) {
      turnRight();
      move();
      turnLeft();
      move();
      turnLeft();
    }
    while (!onLeaf()) {
      move();
      if (onLeaf()) {
        break ;
      }
    }
  }
}```
split fernBOT
# unreal hare ```java class MyClara extends Clara { /** * In the 'run()' method you can w...

Detected code, here are some useful tools:

Formatted code
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // TODO: Write your code below
    int i = 0;
    int n = i + 1;
    while (!onLeaf()) {
      move();
      i++;
      if (onLeaf()) {
        turnRight();
        turnRight();
        break ;
      }
    }
    for (int k = 0; i < n; k++) {
      move();
      if (treeFront()) {
        turnRight();
        break ;
      }
    }
    while (!treeFront()) {
      move();
      if (treeFront()) {
        turnRight();
        move();
        turnRight();
        move();
        break ;
      }
    }
    if (mushroomFront()) {
      turnRight();
      move();
      turnLeft();
      move();
      turnLeft();
    }
    while (!onLeaf()) {
      move();
      if (onLeaf()) {
        break ;
      }
    }
  }
}
patent sparrow
#

also, u should get into the habit of adding newlines and comments to separate and explain/document each section/phase of the code

#

then its also easier to understand for others

unreal hare
#

ok

patent sparrow
#

okay. looking at ur code, there are multiple things that are incorrect and have to be corrected

#

i think its better if we rewrite it together

#

but dont worry

#

okay? ๐Ÿ™‚

#

start by moving in front of the leaf, nothing else. no turning whatsoever yet

#

(and count the distance)

#

we do it step by step, phase by phase

unreal hare
#

ok

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // TODO: Write your code below
    int i = 0;
    int n = i + 1;
    while (!onLeaf()) {
      move();
      i++;
    }
  }
}```
split fernBOT
unreal hare
#

for counting the distance

patent sparrow
#

yes. so now please rename i to distanceToLeaf

#

and remove n

#

not sure why u introduced n, its not doing anything

#

and add a comment that explains what this phase does:

#
// Move to leaf
unreal hare
#

yep done

#

ok now to go back?

patent sparrow
#

please share the code

#

and yes, the next step is to move back to exactly the spot we started at

#

in a new phase/block

#

so put a newline and a new comment

#

before starting the next block of code

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // TODO: Write your code below
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move(); // Move to leaf
      distanceToLeaf++;
    }
  }
}```
split fernBOT
unreal hare
#

ok what i have so far

patent sparrow
#

the comment should be above the entire block

#

the block is this:

#

this block of code is responsible for moving to the leaf

unreal hare
#

ok done

patent sparrow
#

okay cool

#

empty line after the red block

#

and then create a new block thats responsible for walking back

unreal hare
#

when i do this

#

it says that error

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
 // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    if(onLeaf()) {
        turnRight();
        turnRight();
        moveBy(distanceToLeaf);
    }
  }
}```
split fernBOT
unreal hare
#
/* PERMITTED COMMANDS
   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
   
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
 // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    if(onLeaf()) {
        turnRight();
        turnRight();
        break;
    }
    }
    while(!treeFront()) {
        move();
    }
  }
}```
split fernBOT
# unreal hare ```java /* PERMITTED COMMANDS move, turnLeft, turnRight, treeLeft, treeRight,...

Detected code, here are some useful tools:

Formatted code
/* PERMITTED COMMANDS
 move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
 JAVA
 if, while, for
 */
 
 class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  while (!onLeaf()) {
    move();
    distanceToLeaf++;
    if (onLeaf()) {
      turnRight();
      turnRight();
      break ;
    }
  }
  while (!treeFront()) {
    move();
  }
}
}
unreal hare
#

ok it has gone to this position now

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
 // Move to leaf
    int distanceToLeaf = 0;
    int limitDistance = distanceToLeaf + 1;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    if(onLeaf()) {
        turnRight();
        turnRight();
        break;
    }
    }
    while(!treeFront()) {
        move();
    if(treeFront()) {
        turnRight();
        move();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnLeft();
        move();
        turnLeft();
        break;
    }
    }
    for(int j = 0; distanceToLeaf < limitDistance; j++) {
        move();
    }
  }
}```
split fernBOT
# unreal hare ```java class MyClara extends Clara { /** * In the 'run()' method you can w...

Detected code, here are some useful tools:

Formatted code
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    int limitDistance = distanceToLeaf + 1;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
      if (onLeaf()) {
        turnRight();
        turnRight();
        break ;
      }
    }
    while (!treeFront()) {
      move();
      if (treeFront()) {
        turnRight();
        move();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnLeft();
        move();
        turnLeft();
        break ;
      }
    }
    for (int j = 0; distanceToLeaf < limitDistance; j++) {
      move();
    }
  }
}
unreal hare
#

is this not a valid solution to this problem

patent sparrow
#

yeah bc its wrong

#

and u didnt really seem to get my point about making ur code more readable with the blocks

#

cause u still put all blocks together and without comment

#

see, ur code should be like this:

// Move to leaf
...

// Move back
...
#

clear comment and an empty line separating the phases

#

as for moving back, it consists of:

  1. turn around
  2. walk back distanceToLeaf many tiles
#

and ur mixing responsibilities

#

the // Move to leaf part was done already. its not supposed to turn

#

we write the code block-wise so that u can finish a block piece by piece

unreal hare
#

ok

unreal hare
patent sparrow
#

i didnt say to use it

#

u can write a simple for loop

#

(similar to "print hello world 5 times")

split fernBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘

unreal hare
#

hello

#

can anyone help me out by continuing on from this thread?

#

sorry it has been kinda long

split fernBOT
#

Please don't ask to ask, nor only say hello, just ask your actual question right away, thanks cat_thumbs_up

If you want to read about the details of why this is better, check out:
https://dontasktoask.com/

Don't ask to ask, just ask

patent sparrow
#

thats spoonfeeding. please dont do that, its against our rules

#

if u want to help, please guide them to the solution step by step and let them solve it

#

dont provide the solution. thats less helpful than u might think

#

no worries

#

that said, im just waiting for OP to ask an actual question. like, what exactly is unclear

#

cause we have been interrupted last time (if u scroll up)

#

@unreal hare

unreal hare
#

oops sorry

#

my bad

#

it is just that for this problem how would i finish approaching the end which is bringing the mushroom on top of the leaf when all else is done?

unreal hare
#
/* PERMITTED COMMANDS
   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
   
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
 // Move to leaf
    int distanceToLeaf = 0;
    int limitDistance = distanceToLeaf + 1;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    if(onLeaf()) {
        turnRight();
        turnRight();
        break;
    }
    }
    while(!treeFront()) {
        move();
    if(treeFront()) {
        turnRight();
        move();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnRight();
        move();
        turnLeft();
        move();
        turnLeft();
        break;
    }
    }
    for(int j = 0; distanceToLeaf < limitDistance; j++) {
        move();
    }
  }
}```
split fernBOT
# unreal hare ```java /* PERMITTED COMMANDS move, turnLeft, turnRight, treeLeft, treeRight,...

Detected code, here are some useful tools:

Formatted code
/* PERMITTED COMMANDS
 move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
 JAVA
 if, while, for
 */
 
 class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  int limitDistance = distanceToLeaf + 1;
  while (!onLeaf()) {
    move();
    distanceToLeaf++;
    if (onLeaf()) {
      turnRight();
      turnRight();
      break ;
    }
  }
  while (!treeFront()) {
    move();
    if (treeFront()) {
      turnRight();
      move();
      move();
      turnRight();
      move();
      turnRight();
      move();
      turnRight();
      move();
      turnLeft();
      move();
      turnLeft();
      break ;
    }
  }
  for (int j = 0; distanceToLeaf < limitDistance; j++) {
    move();
  }
}
}
patent sparrow
#

ur code is not what i told u to write though

#

it feels like u ignored the advice

unreal hare
#

or should i reinvent a different method then

unreal hare
#

let me check

patent sparrow
#

and ur rushing ahead again

#
// Move to leaf
...

// Move back
...
#

this is what we have stopped at

#

and u never finished this part

#

so id suggest we do that

unreal hare
#

ok

#
/* PERMITTED COMMANDS
   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
   
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
 // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    if(onLeaf()) {
        turnRight();
        turnRight();
        break;
    }
    }
    while(!treeFront()) {
        move();
    }
  }
}```
split fernBOT
# unreal hare ```java /* PERMITTED COMMANDS move, turnLeft, turnRight, treeLeft, treeRight,...

Detected code, here are some useful tools:

Formatted code
/* PERMITTED COMMANDS
 move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
 JAVA
 if, while, for
 */
 
 class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  while (!onLeaf()) {
    move();
    distanceToLeaf++;
    if (onLeaf()) {
      turnRight();
      turnRight();
      break ;
    }
  }
  while (!treeFront()) {
    move();
  }
}
}
unreal hare
#

i will restart and start step by step agaun

patent sparrow
#

well yeah. that code doesnt look like what i just posted

#
// Move to leaf
...

// Move back
...
#

u have no newline, no second comment

#

and the first block does way more than just moving to the leaf

#

it also turns around

#

which it shouldnt do

unreal hare
#

ok

#
class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  while (!onLeaf()) {
    move();
    distanceToLeaf++;
  }
}
}```
split fernBOT
patent sparrow
#

so far so good

#

now empty line, comment

#

and then we walk back

unreal hare
#
class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  while (!onLeaf()) {
    move();
    // Count No. of Squares
    distanceToLeaf++;
  }
  // Moves Clara back to starting direction
  if(onLeaf()) {
    turnRight();
    turnRight();
  }
}
}```
split fernBOT
patent sparrow
#

please pay more attention. i asked u to write it like that:

#
// Move to leaf
...

// Move back
...
#

im sorry if im nitpicking now. but u have a track record of going off-track and by that confusing urself

#

so its important that u follow it 1:1 now

unreal hare
#

ok

patent sparrow
#

ur missing the empty line and ur comment is different

#

so please adjust that

unreal hare
#
class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Move to leaf
  int distanceToLeaf = 0;
  while (!onLeaf()) {
    move();
    // Count No. of Squares
    distanceToLeaf++;
  }
  
// Move back
  
if(onLeaf()) {
    turnRight();
    turnRight();
  }
}
}```
split fernBOT
patent sparrow
#

u have to learn to properly intent ur code

unreal hare
#

sorry where does the empty line have to go

unreal hare
patent sparrow
#

why? u have an IDE

#

hit the auto-format key

#

ive told u that before

#

one source of ur constant confusion is bc u write super messy code

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      // Count No. of Squares
      distanceToLeaf++;
    }
    // Move back
    if (onLeaf()) {
      turnRight();
      turnRight();
    }
  }
}```
patent sparrow
#

it becomes so unreadable that u eventually cant read it anymore

unreal hare
#

ok

patent sparrow
#

add a newline to separate the two blocks

#

and remove the extra comment u added

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    // Move back
    if (onLeaf()) {
      turnRight();
      turnRight();
    }
  }
}```
patent sparrow
#

newline please

#

u must visually separate the blocks

#

otherwise its unreadable

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    if (onLeaf()) {
      turnRight();
      turnRight();
    }
  }
}```
patent sparrow
#

okay, finally ๐Ÿ™‚

#

good

unreal hare
#

sorry im a bit dense ๐Ÿ’€

patent sparrow
#

now. lets start moving back

#

first of all, why is there an if?

#

is it ever possible that ur there without a leaf being there?

unreal hare
#

no

#

but u dont have to go back onto the leaf

patent sparrow
#

okay. let me visualize

unreal hare
#

the description again btw

patent sparrow
#

at the start of // Move back, this is the situation:

#

what is the next action?

#

turning left/right twice

#

why do u make it conditional?

#

there is no condition here

#

its supposed to always turn twice

unreal hare
#

yep ok

patent sparrow
#

so. no if ๐Ÿ™‚

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
      turnRight();
      turnRight();
    }
}```
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    // Move back
    turnRight();
    turnRight();
  }
}```
unreal hare
#

damn this auto formatting

patent sparrow
#

use ur IDE to format

#

not the discord bot

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
  }
}```
#

ok

patent sparrow
#

u can also tell it to auto-format on-save

#

alright.

#

so, now u have to actually walk back

#

all ur previous attempts on this were completely off

unreal hare
#

now a new block for the while(!treeFront) part

patent sparrow
#

good point

patent sparrow
#
  1. ur attempt is wrong, no while loop
#
  1. no new block, our current block says // Move back, have we moved back already? no
unreal hare
#

no we havent sorry

#

we have just turned around

patent sparrow
#

lets step back. please write me code that prints hello 5 times, with a loop

unreal hare
#

for(int i = 0; i>x; i++;)

#

i think that is it

patent sparrow
#

full code

#

and run it

#

i feel like ur never testing ur code

#

but just writing

#

u have to run ur code constantly to verify that the current step works

#

otherwise ull end up with code that has hundreds of bugs in it

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
      turnRight();
      turnRight();
    
    // Walk back
    for(int walkBackDistance = 0; distanceToLeaf < walkBackDistance; walkBackDistance++) {
      move();
    }
  }
}```
patent sparrow
#

and this is also not what i asked u to write

#

im sorta tired of putting u back on track

#

please stop running into the opposite direction

patent sparrow
#

i asked u to write a loop that prints hello 5 times

#

and i asked u to remember to always auto-format ur code

#

ur wasting my and also ur own time by doing other stuff

#

eventually ill be out of time and u have to wait again

unreal hare
#

ok so for loop for writing hello 5 times

patent sparrow
#

yes

#

and dont forget to run it to verify that it works

#

dont just write code, run ur code

unreal hare
#

in clara world?

patent sparrow
#

run it locally

#

u can also write a new program, i dont care

unreal hare
#

ok

#
for (int i = 0; i < 6; i++) {
  print("Hello")
}```
patent sparrow
#

and dont forget to run it to verify that it works
dont just write code, run ur code

#

i doubt u did that, did u

unreal hare
#

I did

patent sparrow
#

this code doesnt even compile

#

i doubt u ran it

unreal hare
#

sorry yes it doesnt

patent sparrow
#

so... fix it

#

or is sth unclear?

unreal hare
#

oops sorry

#

i used python functions in java

#

and it printed 6 times

#

so it has to be i < 5 then

patent sparrow
#

now add at the beginning of ur main method

int x = 5;

and then modify the loop so it prints it x-times

unreal hare
#

yep still works the same

patent sparrow
#

after turning around clara, write code that moves left 5 times

#

(with a loop)

unreal hare
#

sorry before that so i dont frustate u again i just wanna know where on the screen i would auto format the code

#

because IDE means this software right

patent sparrow
#

intellij, eclipse, netbeans, vsc, ...

unreal hare
#

uh no

patent sparrow
#

big oof

unreal hare
#

sorry should have specified taht

#

i could switch to one now

patent sparrow
#

or u learn how to format urself

#

each time u write {, ur supposed to indent once

#

and each time u write }, u reduce it again by one level

#

u can also see that visualizued with the vertical white lines in ur screenshot

#

and u can also see that u did a mistake in line 14 and 15

#

its supposed to be one more to the left

unreal hare
#

oh yep

#

ok

#

so everything is in line

patent sparrow
#

please delete line 17-20. they are wrong

#

in line 16, u will now write code to move left 5 times

unreal hare
#

yep ok

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
      turnRight();
      turnRight();

    // Walk back
    for (int i = 0; i < 5; i++) {
      move();
    }  
  }
}```
split fernBOT
unreal hare
#

oh yep in one line

patent sparrow
#

please pay more attention

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();

    // Walk back
    for (int i = 0; i < 5; i++) {
      move();
    }  
  }
}```
split fernBOT
patent sparrow
#

remove the comment and empty line

#

we are still in the // Move back block

#

dont start a new section

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < 5; i++) {
      move();
    }  
  }
}```
split fernBOT
patent sparrow
#

alright

#

now, how often do u have to move to get back to ur starting point?

#

5 times? 10 times?

#

do u have the count available already somewhere?

unreal hare
#

9

#

just changed it

patent sparrow
#

but now u hardcoded it

#

it has to work for any board

#

think about what u coded so far

unreal hare
#

uh yep

patent sparrow
#

do u have the count available already somewhere?

unreal hare
#

yeah distanceToLeaf

patent sparrow
#

good

#

so. walk back distanceToLeaf-many tiles

unreal hare
#

yep

#

ok done

#

and checked too it works

patent sparrow
#

code please

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < distanceToLeaf; i++) {
      move();
    }  
  }
}```
split fernBOT
patent sparrow
#

okay, good

#

now, where exactly does clara stand now

#

do u have a screenshot?

unreal hare
#

right in front of the tree

patent sparrow
#

alright

#

now, we start a new block

#

since we are done moving back

unreal hare
#

yep

patent sparrow
#

so newline and a fresh comment

#

our next block will be:

#
// Move above mushroom
#

nothing else yet

#

no pushing

unreal hare
#

yes

#

so both worlds have the same dimesions like vertically so we could also do the same for both

#

that is world 2

#

idk if that is correct logic though

patent sparrow
#

the code u write works for any board

#

thats the point of the exercise

unreal hare
#

oh ok yep

#

so no hardcoding

patent sparrow
#

yes. but the starting point and mushroom position is always the same

#

isnt it

#

so this part is always the same now

unreal hare
#

yeah

patent sparrow
#

so it will be a list of a few static movements that u will now do

unreal hare
#

ok

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < distanceToLeaf; i++) {
      move();
    }

    // Move above mushroom
    turnRight();
    move();
    move();
    turnRight();
    move();
    turnRight();
  }
}```
patent sparrow
#

very good ๐Ÿ™‚

unreal hare
#

ok so new block

patent sparrow
#

next block. empty line, comment:
// Push mushroom

#

its a simple one, i know

#

but its the next logical step

unreal hare
#

is it just static movements?

patent sparrow
#

sure

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < distanceToLeaf; i++) {
      move();
    }

    // Move above mushroom
    turnRight();
    move();
    move();
    turnRight();
    move();
    turnRight();

    // Push mushroom
    move();
    turnRight();
    move();
    turnLeft();
    move();
    turnLeft();
  }
}```
split fernBOT
patent sparrow
#

not sure what kind of movement ur doing there

unreal hare
patent sparrow
#

ah yeah

#

okay

#

u did more already

#

thats fine

unreal hare
#

so do i need to restart?

patent sparrow
#

perhaps lets adjust the comment then:

#
// Move mushroom and go left to it
#

since u did more already

#

i only intended u to do one move()

#

but its okay

unreal hare
#

but it is in the correct position right?

patent sparrow
#

yes. u just did more already

unreal hare
#

because now do we just do the same for loop again?

patent sparrow
#

please adjust the comment

unreal hare
#

yes i did

patent sparrow
#

good

unreal hare
#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < distanceToLeaf; i++) {
      move();
    }

    // Move above mushroom
    turnRight();
    move();
    move();
    turnRight();
    move();
    turnRight();

    // Move mushroom and go to the left of it
    move();
    turnRight();
    move();
    turnLeft();
    move();
    turnLeft();
  }
}```
split fernBOT
patent sparrow
#

now u have to push the shroom back to the leaf

#

new section, comment // Push mushroom on leaf

#

how often do u have to push it? u know it cat_thumbs_up

unreal hare
#

ok so what i am thinking is do we make a variable where it is distanceToLeaf - 1

#

as the palce i have to push it is 8 places

#

or -1 from 9

#

so then do the for loop thing again

patent sparrow
#

just adjust ur loop condition

#
int x = 5;
for (...) {
  System.out.println("Hello");
}

what to write to make it print hello x-1 times instead of x-times?

#

there are many ways

unreal hare
#

ok

#
class MyClara extends Clara {
  /**
   * In the 'run()' method you can write your program for Clara
   */
  void run() {
    // Move to leaf
    int distanceToLeaf = 0;
    while (!onLeaf()) {
      move();
      distanceToLeaf++;
    }
    
    // Move back
    turnRight();
    turnRight();
    for (int i = 0; i < distanceToLeaf; i++) {
      move();
    }

    // Move above mushroom
    turnRight();
    move();
    move();
    turnRight();
    move();
    turnRight();

    // Move mushroom and go to the left of it
    move();
    turnRight();
    move();
    turnLeft();
    move();
    turnLeft();

    // Push mushroom on leaf
    int x = distanceToLeaf - 1;
    for (int i = 0; i < x; i++) {
      move();
    }
  }
}```
split fernBOT
patent sparrow
#

a bit odd to write it

#

id suggest one of the following:

#
int i = 0; i < distanceToLeaf - 1; i++
int i = 1; i < distanceToLeaf; i++
int i = 0; i <= distanceToLeaf; i++
unreal hare
#

ok thanks

#

it worked tysm

patent sparrow
#

๐ŸŽ‰

unreal hare
#

i was thinking of this before

patent sparrow
#

congrats

unreal hare
#

but with ur guidance of indenting and blocks i figured out where to put it

#

and logically put it

#

i think that was my problem

patent sparrow
#

๐Ÿ‘

unreal hare
#

i knew what to do with the code but the place and order where i put the code was wrong

patent sparrow
#

i guess u just have to break it down step by step

#

and think more about what u write

#

and trying it out

#

like, if u do each part step by step, constantly visualize whats going on, ... it will eventually come together correctly

#

instead of attempting to write everything at once and then realizing that nothing works

#

at which point its also hard to find bugs bc its too overwhelming

unreal hare
#

ok

#

yeah i will try do that for the next problem

#

ig my teacher never taught me this properly

#

he kinda just threw us into this

split fernBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘

unreal hare
#

hi there im back again i will actually listen word from word this time. also this is my last challenge.

#
/* PERMITTED COMMANDS
   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
   
class MyClara extends Clara { 
    /**
     * In the 'run()' method you can write your program for Clara 
     */
    void run() {
        // Get in front of mushroom
        turnRight();
        while(!treeFront()) {
            int columnNumber = 0;
            move();
        if(treeFront()) {
            columnNumber++;
        if(columnNumber % 2 == 0) {
            turnRight();
            move();
            turnRight();
        }
        else {
            turnLeft();
            move();
            turnLeft();
        }
        }
        }
    }
}```
split fernBOT
# unreal hare ```java /* PERMITTED COMMANDS move, turnLeft, turnRight, treeLeft, treeRight,...

Detected code, here are some useful tools:

Formatted code
/* PERMITTED COMMANDS
 move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
 JAVA
 if, while, for
 */
 
 class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Get in front of mushroom
  turnRight();
  while (!treeFront()) {
    int columnNumber = 0;
    move();
    if (treeFront()) {
      columnNumber++;
      if (columnNumber % 2 == 0) {
        turnRight();
        move();
        turnRight();
      }
      else {
        turnLeft();
        move();
        turnLeft();
      }
    }
  }
}
}
unreal hare
#
/* PERMITTED COMMANDS
 move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
 JAVA
 if, while, for
 */
 
 class MyClara extends Clara {
 /**
 * In the 'run()' method you can write your program for Clara
 */
void run() {
  // Get in front of mushroom
  turnRight();
  while (!treeFront()) {
    int columnNumber = 0;
    move();
    if (treeFront()) {
      columnNumber++;
      if (columnNumber % 2 == 0) {
        turnRight();
        move();
        turnRight();
      }
      else {
        turnLeft();
        move();
        turnLeft();
      }
    }
  }
}
}```
#

this is the description for the problem

#

so i have to detect where the mushroom is first and then i think take it back to the leaf

#

and when i have the chance i think clara would need to calculate the height and width of the field so it can go back to the leaf and place it there

#

but first i have tried to make a block where clara goes through the first section column by column in an alternating pattern (haven't thought of how i will make it to the tunnel though)

split fernBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘