Swift — Twin Peaks

Objective: Character collects all gems until count is equal to randomized total, while expert moves platform as needed.
FCD9951B-4132-49B9-BF76-01BB932ADC84.png

Not only was this a very challenging level, utilizing all skills practiced until now, it also tested some erroneous assumptions I falsely introduced.

At first, I assumed that gems may also appear along the entire length of the platform, which they did not; gems only ever appeared on the ends.

Secondly, I assumed platform must be raised to an even level with each row, which it does not; only must get within jumping level. (Thanks, Samantha!)

Difference between mine and hers? 47 lines vs 31 — mine has 50% more!!

My solution

let expert = Expert()
let character = Character()
var gemCount = 0
world.place (expert, facing: north, atColumn:1, row:3)
world.place (character, facing: north, atColumn:5, row:0)
func rowRun() {
for i in 1…6 {
if character.isOnGem {
gemCount += 1
character.collectGem()
}
character.jump()
}
}
func turnLock(up:Bool, turns: Int) {
if up == true {
for i in 1…turns {
expert.turnLockUp()
}
} else {
for i in 1…turns {
expert.turnLockDown()
}
}
expert.turnRight()
}
func leftFace() {
character.turnLeft()
character.moveForward()
character.turnLeft()
}
func rightFace() {
character.turnRight()
character.moveForward()
character.turnRight()
}
expert.moveForward()
rowRun()
turnLock(up:true, turns:3)
leftFace()
rowRun()
rightFace()
rowRun()
turnLock(up:false, turns:3)
rightFace()
rowRun()
leftFace()

Samantha’s solution

let expert = Expert()
let character = Character()
var gemCount = 0
func moveLong() {
for i in 1…6 {
if character.isOnGem {
character.collectGem()
gemCount += 1
}
character.jump()
}
}
func moveShort() {
for i in 1…2 {
if character.isOnGem {
character.collectGem()
gemCount += 1
}
character.jump()
}
}
world.place (expert, facing: north, atColumn:1, row:4)
world.place (character, facing: north, atColumn:3, row:0)
expert.turnLock(up:true, numberOfTimes:2)
while gemCount < totalGems {
moveLong()
character.turnRight()
moveShort()
character.turnRight()
}

 
12
Kudos
 
12
Kudos

Now read this

My Ideal Day, Everyday

You know that really great feeling at the end of a day when things could not have gone more perfect? Maybe it was the weather or a reandom interaction, but often times I feel like the various parts of my day just clicked together in the... Continue →