如何随机选择 3 个程序之一?
请看下面:
to move
ifelse random-float 100 < 70
[move-forward]
[move-left move-right move-back] ;; To randomly select one of these 3 procedures to execute.
end
谢谢你。我对语法很陌生。
网络徽标 6:
run one-of (list [-> move-left]
[-> move-right]
[-> move-back])
网络徽标 5:
run one-of (list task move-left
task move-right
task move-back)
也许不是太优雅,但这可能有效:
to move
ifelse random-float 100 < 70
[move-forward]
[let n random 3
ifelse n = 0
[move-left]
[ifelse n = 1
[move-right]
[move-back]]]
end