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()
}
}
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags: