Swift — Rivers to Cross

Objective: Place monster on a specific square and facing a specific direction, and then complete the maze by collecting all gems.
1BBC9703-A4DE-4DFC-9DB4-48954FABB4A8.png

I didn’t much issues with this one, and so I challenged myself to recreate entirely new algorithm using less code — did it with 25% less lines!

Take 1

let expert = Expert()
world.place (expert, facing: .south, atColumn:1, row:8)
func gemGoLock() {
for i in 1…4 {
expert.collectGem()
expert.moveForward()
}
}
gemGoLock()
expert.turnLockDown()
expert.turnLeft()
gemGoLock()
expert.turnLockUp()
expert.turnRight()
gemGoLock()
expert.collectGem()

Take 2

let expert = Expert()
world.place (expert, facing: .south, atColumn:1, row:8)
for i in 1…12 {
expert.collectGem()
expert.moveForward()
if expert.isBlocked && expert.isBlockedRight {
expert.turnLockDown()
expert.turnLeft()
}
if expert.isBlocked && expert.isBlockedLeft {
expert.turnLockUp()
expert.turnRight()

 
2
Kudos
 
2
Kudos

Now read this

on quarterly evals

Quarterly evaluations are meta-scrums. Managers should be guided by the simple principles of scrum when assessing each of their team members, which are: What did you do yesterday? What will you be doing today? What are your roadblocks?... Continue →