#Java help with Clara
19 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @coral goblet! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Please format your code to make it more readable.
For java, it should look like this:
```โโโ`โjava
public void foo() {
}
โโโ`โ```
why not just
while(!onLeaf()){
if(!treeRight()){
turnRight();
}
if(!treeFront()){
move();
} else {
turnLeft();
}
}
?
no need to check left
because this will go backwards if only the left side is open
which always works
no
ah hold on
suppose this kind of corridor
+---+---+
| |
+ + +
|๐| ^ |
+---+---+
treeFront() false, move() (^)
treeFront() true, turnRight() (>)
treeFront() true, turnRight() (v)
treeFront() false, move() (v)
treeFront() true, turnRight() (<)
treeFront() true, turnRight() (^)
returned to start
fixed
anyways it could be improved though, you have duplicate checks
if there is a wall to the right you just loop indefinitely
then it would not execute turnRight() and instead check whether it could go forward
it needs to go backwards if there's no other way