总算想到一种稳能稳定迟到所有金币,并找门离开的方法。可惜就是时钟刻用的有些多了
直接上代码:
前置汇编别名:
| 别名 | 十进制 |
|---|---|
| ADD | 68 |
| AND | 67 |
| IMMEDIATE | 0 |
| JG | 199 |
| JL | 194 |
| JMP | 196 |
| JZ | 193 |
| MOV | 128 |
| OR | 64 |
| SUB | 69 |
| io | 6 |
| r0 | 0 |
| r1 | 1 |
| r2 | 2 |
| r3 | 3 |
| r4 | 4 |
| r5 | 5 |
| src | 8 |
代码:(附带一些注释,尝试尝试自己理解吧 ;) )
const turn_left 0
const go 1
const turn_right 2
const wait 3
const interact 4
const shoot 5
const detect MOV|io*src|r3
const execute MOV|r0*src|io
# init dir.
turn_left
execute
# step forward
go
execute
# interact with coins if it is
IMMEDIATE|8
MOV|r0*src|r1
MOV|io*src|r2
SUB
IMMEDIATE|35
JZ
# chk if right has path
turn_right
execute
IMMEDIATE|27
detect
JZ # if Y, go this way priorly
# if N, chk if front has way
turn_left
execute
IMMEDIATE|27
detect
JZ # if Y, meaning OK going forward
# if N, chk if left has way
turn_left
execute
IMMEDIATE|27
detect
JZ # if Y, meaning it's a left turn
# but if N, meaning it's end of path
# turn back
turn_left
execute
# chk if i have collected all the coins
IMMEDIATE|4
MOV|r0*src|r1
MOV|r4*src|r2
SUB
IMMEDIATE|44 # if Y, go for door chk
JZ
IMMEDIATE|2 # if N, ret
JMP
# coin interaction & update cnt(r4)
go
execute
IMMEDIATE|1
MOV|r0*src|r1
MOV|r4*src|r2
ADD
MOV|r3*src|r4
IMMEDIATE|10 # goto right turn "if"
JMP
# so i have all the coins,
# chk if door is there
IMMEDIATE|4
MOV|r0*src|r5 # load org dir nums
turn_left
execute
IMMEDIATE|3
MOV|r0*src|r1
MOV|io*src|r2
SUB
# time to get out of the f**king maze!
IMMEDIATE|63
JZ # woc, 63 is almost out of range!
# ...or if it's not the door,
# try another dir until all four
# dir has been tried (r5: 4 to 0)
IMMEDIATE|1
MOV|r0*src|r2
MOV|r5*src|r1
SUB
MOV|r3*src|r5
IMMEDIATE|46
JG
IMMEDIATE|2 # door is not here, ret
JMP
interact # open the door!
execute
2870

被折叠的 条评论
为什么被折叠?



