Swift — Corners of the World

This was the first level to truly stump me. Since I couldn’t come up with a solution myself, I turned to others. Below are two that helped me out.

The lesson I took away from this is that it’s not just the item needed to do an action to (ie get a gem or toggle a switch), but rather take a step back and see that all that’s needed is to get to a square and then do something to whatever is on that square. It’s more conceptual, but it helps to remove the barrier of distraction focusing on the things vs patterns of movement.

Objective: Turn each portal on and off as needed to retrieve all gems and turn each switch on, preferably by finding and utilizing a uniform pattern.

1C2D9258-DEBC-4735-8E0E-D1B120E8A2AE.png

Solution 1, courtesy of Jyjy Game

func turnAround () {
turnLeft()
turnLeft()
}
func collectToggle () {
if isOnGem {
collectGem()
} else if isOnClosedSwitch {
toggleSwitch()
}
}
func moveActTurn () {
moveForward()
collectToggle()
turnAround()
}
func solveHalf () {
moveActTurn()
moveForward()
turnLeft()
moveActTurn()
}
func solveOtherHalf () {
moveActTurn()
moveForward()
turnRight()
moveForward()
collectToggle()
}
orangePortal.isActive = false
turnRight()
moveForward()
moveForward()
solveHalf()
orangePortal.isActive = true
moveForward()
orangePortal.isActive = false
solveHalf()
moveForward()
solveOtherHalf()
moveForward()
greenPortal.isActive = false
moveForward()
solveHalf()
greenPortal.isActive = true
moveForward()
greenPortal.isActive = false
solveHalf()
moveForward()
solveOtherHalf()

Solution 2, courtesy of Ziyad Allawi

var gemCount = 0
var togCount = 0
orangePortal.isActive = false
greenPortal.isActive = false
while gemCount != 6 || togCount != 6 {
if !isBlockedLeft {
turnLeft()
}
if isBlocked {
turnLeft()
turnLeft()
} else {
moveForward()
}
if isOnGem {
collectGem()
gemCount += 1
}
if isOnClosedSwitch {
toggleSwitch()
togCount += 1
}
if togCount == 5 && !isOnOpenSwitch {
greenPortal.isActive = false
orangePortal.isActive = false
}
}

 
53
Kudos
 
53
Kudos

Now read this

“Everything I know about business in one minute.”

by William Drenttel Focusing on making a partnership work is more profitable than focusing on making money. Love your employees more than you love your clients.  The best new business is your current business. Price projects by... Continue →