#Clara World Help Needed! (Back Again)
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
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?
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
im on mac idk how to do that
is there no ms paint thing?
can u perhaps describe it?
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
can we start with the path that u intend clara to walk?
cause there are obviously multiple ways to approach it
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
so u first want to move just right until u see leaf? then turn around and move back to the start?
yeah basically
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
yeah. perhaps u should rename i but yeah
distanceToLeaf for example
now u have to move that many tiles back again
yes
yeah
and that is the same for the 2nd world
too
and then i will push the mushroom by the distance calc. earlier
yeah. so where is the problem now
up to where does ur code work
when does it start misbehaving
for some reason it turns right at that exact spot
here is the code.
and also does moveBy(i) a valid thing like is it proven to work?
if its a clara built-in method, it likely works
all the methods ur using here are clara specific things
they dont exist in normal java
ik
which phase is that
is it on the way back from the leaf?
because there is a whole list of functions or methods that have been predefined
i think after counting i and then coming back and trying to push the mushroom
into position
because idk why an error is occuring
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?
no this is after
that is correct
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)
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 ;
}
}
}
}```
Detected code, here are some useful tools:
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 ;
}
}
}
}
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
ok
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
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++;
}
}
}```
Detected code, here are some useful tools:
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++;
}
}
}
for counting the distance
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
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
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++;
}
}
}```
Detected code, here are some useful tools:
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++;
}
}
}
ok what i have so far
the comment should be above the entire block
the block is this:
this block of code is responsible for moving to the leaf
ok done
okay cool
empty line after the red block
and then create a new block thats responsible for walking back
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);
}
}
}```
Detected code, here are some useful tools:
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);
}
}
}
/* 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();
}
}
}```
Detected code, here are some useful tools:
/* 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();
}
}
}
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();
}
}
}```
Detected code, here are some useful tools:
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();
}
}
}
is this not a valid solution to this problem
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:
- turn around
- walk back
distanceToLeafmany 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
ok
no i dont think moveBy is permitted
i didnt say to use it
u can write a simple for loop
(similar to "print hello world 5 times")
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 ๐
hello
can anyone help me out by continuing on from this thread?
sorry it has been kinda long
Please don't ask to ask, nor only say hello, just ask your actual question right away, thanks 
If you want to read about the details of why this is better, check out:
https://dontasktoask.com/
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
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?
yh sorry bout that
/* 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();
}
}
}```
Detected code, here are some useful tools:
/* 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();
}
}
}
or should i reinvent a different method then
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
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();
}
}
}```
Detected code, here are some useful tools:
/* 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();
}
}
}
i will restart and start step by step agaun
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
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++;
}
}
}```
Detected code, here are some useful tools:
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++;
}
}
}
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();
}
}
}```
Detected code, here are some useful tools:
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();
}
}
}
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
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();
// Count No. of Squares
distanceToLeaf++;
}
// Move back
if(onLeaf()) {
turnRight();
turnRight();
}
}
}```
Detected code, here are some useful tools:
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();
}
}
}
u have to learn to properly intent ur code
sorry where does the empty line have to go
yeah that is one thing i struggle at
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
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();
}
}
}```
it becomes so unreadable that u eventually cant read it anymore
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
if (onLeaf()) {
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
if (onLeaf()) {
turnRight();
turnRight();
}
}
}```
sorry im a bit dense ๐
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?
okay. let me visualize
the description again btw
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
yep ok
so. no if ๐
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();
}
}```
u killed the newline
damn this auto formatting
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
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
now a new block for the while(!treeFront) part
good point
no
- ur attempt is wrong, no while loop
- no new block, our current block says
// Move back, have we moved back already? no
lets step back. please write me code that prints hello 5 times, with a loop
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
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();
}
}
}```
u didnt hit the auto-format key again
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
isnt this a for loop?
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
ok so for loop for writing hello 5 times
yes
and dont forget to run it to verify that it works
dont just write code, run ur code
in clara world?
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
I did
oops sorry
i used python functions in java
and it printed 6 times
so it has to be i < 5 then
now add at the beginning of ur main method
int x = 5;
and then modify the loop so it prints it x-times
yep still works the same
okay. memorize what u just learned. lets go back to ur code
after turning around clara, write code that moves left 5 times
(with a loop)
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
are u not coding in a proper IDE locally on ur computer?
intellij, eclipse, netbeans, vsc, ...
uh no
big oof
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
please delete line 17-20. they are wrong
in line 16, u will now write code to move left 5 times
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();
}
}
}```
Detected code, here are some useful tools:
oh yep in one line
please pay more attention
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();
}
}
}```
Detected code, here are some useful tools:
remove the comment and empty line
we are still in the // Move back block
dont start a new section
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();
}
}
}```
Detected code, here are some useful tools:
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?
but now u hardcoded it
it has to work for any board
think about what u coded so far
uh yep
do u have the count available already somewhere?
yeah distanceToLeaf
code please
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();
}
}
}```
Detected code, here are some useful tools:
right in front of the tree
yep
so newline and a fresh comment
our next block will be:
// Move above mushroom
so we want to be here: https://i.imgur.com/814hXG9.png
nothing else yet
no pushing
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
yes. but the starting point and mushroom position is always the same
isnt it
so this part is always the same now
yeah
so it will be a list of a few static movements that u will now do
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();
}
}```
very good ๐
ok so new block
next block. empty line, comment:
// Push mushroom
its a simple one, i know
but its the next logical step
is it just static movements?
sure
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();
}
}```
Detected code, here are some useful tools:
not sure what kind of movement ur doing there
so do i need to restart?
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
but it is in the correct position right?
yes. u just did more already
because now do we just do the same for loop again?
please adjust the comment
yes i did
good
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();
}
}```
Detected code, here are some useful tools:
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 
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
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
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();
}
}
}```
Detected code, here are some useful tools:
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++
๐
i was thinking of this before
congrats
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
๐
i knew what to do with the code but the place and order where i put the code was wrong
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
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
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 ๐
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();
}
}
}
}
}```
Detected code, here are some useful tools:
/* 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();
}
}
}
}
}
/* 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)
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 ๐