(2020-08-16 22:54:24) 持续更新中

变量

跟踪记录

1
2
3
4
5
var gemCounter = 0 
moveForward()
moveForward()
collectGem()
gemCounter = 1

使值增大

1
2
3
4
5
6
7
8
9
var gemCounter = 0
while !isBlocked {
moveForward()
if isOnGem {
collectGem()
}

gemCounter += 1
}

使值递增

1
2
3
4
5
6
7
8
9
10
11
var gemCounter = 0
while !isBlocked || !isBlockedRight {
moveForward()
if !isBlockedRight {
turnRight()
}
if isOnGem {
collectGem()
gemCounter += 1
}
}

寻找七颗宝石

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var gemCounter = 0
while gemCounter < 7 {
if !isBlocked {
if isOnGem {
collectGem()
gemCounter += 1
} else {
moveForward()
}
} else {
turnLeft()
turnLeft()
}
}

三颗宝石,四个开关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var gemCounter = 0
var toggleCounter = 0
while toggleCounter < 4 {
if isBlocked {
if isBlockedLeft {
turnRight()
} else {
turnLeft()
}
} else {
if isOnGem && gemCounter < 3{
collectGem()
gemCounter += 1
} else if isOnClosedSwitch {
toggleSwitch()
toggleCounter += 1
} else {
moveForward()
}
}
}

检查等值

1
2
3
4
5
6
7
8
9
10
11
12
let switchCounter = numberOfSwitches
var gemCounter = 0
while gemCounter < switchCounter {
if isOnGem {
collectGem()
gemCounter += 1
}
if isBlocked {
turnRight()
}
moveForward()
}

清点开关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var gemCounter = 0 
var switchCounter = 0
while (!isOnClosedSwitch) {
if isOnGem {
collectGem()
gemCounter += 1
} else if isBlocked {
turnRight()
}
moveForward()
}
while switchCounter < gemCounter {
if isOnClosedSwitch {
toggleSwitch()
switchCounter += 1
} else if isBlocked {
turnRight()
}
moveForward()
}

收集指定总数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let totalGems = randomNumberOfGems
var gemCounter = 0
while gemCounter < totalGems {
if !isBlocked {
if isOnGem {
collectGem()
gemCounter += 1
}
moveForward()
} else if isBlocked && isBlockedRight{
turnLeft()
} else {
turnRight()
}
}

类型

关闭传送门

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for i in 1 ... 2 {
moveForward()
}
var closed_Switch = 3
greenPortal.isActive = false
while closed_Switch != 0 {
moveForward()
if isBlocked {
for i in 1 ... 2 {
turnRight()
}
} else if !isBlockedRight{
turnRight()
}
if isOnClosedSwitch {
toggleSwitch()
closed_Switch -= 1
}
}

开关传送门

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var gemNum = 7
var SwitchNum = 1
var turnRound = 0

while (gemNum !=` 0 || SwitchNum != 0) {
if turnRound%2==0 {
purplePortal.isActive = false
}
if !isBlocked {
if isOnGem {
collectGem()
gemNum -= 1
} else if isOnClosedSwitch {
toggleSwitch()
SwitchNum -= 1
}
moveForward()
}
if isBlocked {
for i in 1 ... 2 {
turnRight()
}
turnRound += 1
}
if turnRound%2==1 {
purplePortal.isActive = true
}
}

设定正确的传送门

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var turnRound = 0
var gemNum = 4

while gemNum != 0 {
if turnRound%2==0 {
bluePortal.isActive = false
pinkPortal.isActive = false
} else {
bluePortal.isActive = true
pinkPortal.isActive = true
}
if !isBlocked {
if isOnGem {
collectGem()
gemNum -= 1
}
moveForward()
} else {
for i in 1 ... 2 {
turnRight()
}
turnRound += 1
}
}

世界四角

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var switchNum = 0
var gemNum = 0
var turnRound = 0
while switchNum != 6 || gemNum != 6 {
if !isBlockedRight {
turnRight()
}
if turnRound%2 == 0 {
greenPortal.isActive = false
orangePortal.isActive = false
} else if turnRound%3 == 0{
greenPortal.isActive = true
orangePortal.isActive = true
}
if !isBlocked {
if isOnGem {
collectGem()
gemNum += 1
} else if isOnClosedSwitch {
toggleSwitch()
switchNum += 1
}
moveForward()
}
if isBlocked && isBlockedRight{
for i in 1 ... 2 {
turnRight()
}
turnRound += 1
}
}

随机宝石遍布各处

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var totalGems = randomNumberOfGems

var ActiveNum = 0
while totalGems != 0 {
if ActiveNum%2==0 {
pinkPortal.isActive = false
bluePortal.isActive = false
} else {
pinkPortal.isActive = true
bluePortal.isActive = true
}
if !isBlocked {
if isOnGem {
collectGem()
totalGems -= 1
}
moveForward()
} else {
for i in 1 ... 2 {
turnLeft()
}
ActiveNum += 1
}

}

初始化

初始化你的专家

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let expert = Expert()
var gemNum = 0
var goNum = 0
var lockNum = 0
while gemNum != 3 {
if expert.isOnGem {
expert.collectGem()
gemNum += 1
}
func go_HalfWay() {
for i in 1 ... 3 {
expert.moveForward()
}
}
if !expert.isBlocked {
go_HalfWay()
goNum += 1
if lockNum != 1 {
expert.turnLockUp()
lockNum += 1
}
if goNum == 4 {
expert.turnLeft()
}

} else {
for i in 1 ... 2 {
expert.turnLeft()
}
}
}

训练你的专家

1
2
3
4
5
6
7
8
9
10
11
12
expert.moveForward()
expert.turnLockUp()
character.moveForward()
character.collectGem()
character.moveForward()
character.turnRight()
character.moveForward()
character.moveForward()
expert.turnLockDown()
expert.turnLockDown()
character.moveForward()
character.collectGem()

使用不同类型的实例

1
2
3
4
5
6
7
8
9
10
11
12
expert.moveForward()
expert.turnLockUp()
character.moveForward()
character.collectGem()
character.moveForward()
character.turnRight()
character.moveForward()
character.moveForward()
expert.turnLockDown()
expert.turnLockDown()
character.moveForward()
character.collectGem()

需要两个搭档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let exper = Expert()
let character = Character()
var step = 0
while (step<15) {
if expert.isBlocked {
if expert.isBlockedLeft {
expert.turnRight()
} else {
expert.turnLeft()
}
} else if !expert.isBlocked {
if step==5 {
expert.turnLeft()
expert.turnLockDown()
expert.turnLockDown()
expert.turnRight()
expert.moveForward()
step += 1
} else if step==15 {
expert.turnLeft()
expert.turnLockUp()
expert.turnRight()
expert.moveForward()
step += 1
} else {
expert.moveForward()
step += 1
}
}
}
character.moveForward()
character.moveForward()
character.collectGem()
character.moveForward()
character.moveForward()
character.toggleSwitch()