let expert = Character()
world.place(expert, facing: .north, atColumn: 4, row: 0)
let ein = Expert()
world.place(ein, facing: .north, atColumn: 0, row: 4)
var 數(shù)據(jù) = 0
for i in 1 ... 3 {
? ? ein.turnLockUp()
}
func 判斷() {
? ? if totalGems > 數(shù)據(jù) {
? ? ? ? if expert.isOnGem {
? ? ? ? ? ? expert.collectGem()
? ? ? ? ? ? 數(shù)據(jù) += 1
? ? ? ? }
? ? }
? ?
? ?
? ? }
func QQ() {
? ? for i in 1 ... 6 {
? ? ? ? 判斷()
? ? ? ? if expert.isBlocked {
? ? ? ? ? ? expert.jump()
? ? ? ? } else if expert.isBlocked {
? ? ? ? ? ? expert.moveForward()
? ? ? ? }
? ? }
}
func 直走() {
? ? for i in 1 ... 6 {
? ? ? ? 判斷()
? ? ? ? if expert.isBlocked {
? ? ? ? ? ? expert.jump()
? ? ? ? } else? {
? ? ? ? ? ? expert.moveForward()
? ? ? ? }
? ? }
}
func 左前() {
? ? 判斷()
? ? expert.turnLeft()
? ? expert.moveForward()
? ? expert.turnLeft()
}
func 右前() {
? ? 判斷()
? ? expert.turnRight()
? ? expert.moveForward()
? ? expert.turnRight()
}
func 回頭() {
? ? 判斷()
? ? for i in 1 ... 2 {
? ? ? ? expert.turnRight()
? ? }
}
while totalGems !=? ? 數(shù)據(jù) {
? ?
? ? QQ()
? ? 左前()
? ? 直走()
? ? 右前()
? ? QQ()
? ? 回頭()
? ? QQ()
? ? 左前()
? ? 直走()
? ? 右前()
? ? QQ()
? ? 回頭()
? ?
}