guys this the the answer for this question:
var gemCounter = 0
var switchCounter = 0
func direction() {
if isBlocked && isBlockedLeft {
turnRight()
} else if isBlocked && isBlockedRight {
turnLeft()
}
}
func gemVar() {
if isOnGem {
collectGem()
gemCounter += 1
}
}
func switchVar() {
if isOnClosedSwitch {
toggleSwitch()
switchCounter += 1
}
}
while !isBlocked || !isBlockedLeft || !isBlockedRight && switchCounter != 4{
moveForward()
direction()
if gemCounter < 3 {
gemVar()
} else if switchCounter < 4{
switchVar()
}
}
Post
Replies
Boosts
Views
Activity
I think this is the answer. I've checked it already. it works!
while !isOnOpenSwitch {
moveForward()
if isBlocked && isBlockedRight {
turnLeft()
}
if isBlocked && isBlockedLeft {
turnRight()
}
if isBlocked && !isBlockedRight {
turnLeft()
}
while isOnGem {
collectGem()
}
while isOnClosedSwitch {
toggleSwitch()
moveForward()
}
}