我正在Netlogo上创建一个创建迷宫的项目,我想对它进行编码,这样如果移动的乌龟在另一个地方撞到一只不动的乌龟(代表类似障碍物的东西),那么它就会打开一个我将创造的“迷你游戏”。然而,当我包括更多的海龟并在我的按钮中使用问龟0以便其他海龟不移动并保持障碍时,一切都开始滞后。我如何能够使用全局变量来解决问题?
答案 0 :(得分:2)
这是使用两个品种的相同模型:
breed [Walls wall]
patches-own [is-wall]
breed [Humans person]
Humans-own [target]
to setup
clear-all
set-default-shape Walls "tile brick"
set-default-shape Humans "person"
set-patch-size 25
create-humans 1 [
set heading 90
set color white
move-to patch -5 -5
set target one-of patches with [not any? walls-here]
ask target [set pcolor green]]
set-walls
reset-ticks
end
to set-walls
ask n-of 10 patches with [not any? humans-here]
[
set pcolor red
sprout-walls 1
[
set color brown
]
]
end
to go
ask humans [
ifelse pcolor != green
[
ifelse [pcolor] of patch-ahead 1 != red
[
Your-Move-Function
]
[
Your-Bounce-Function
]
leave-a-trail
]
[
stop
]
]
tick
end
to Your-Move-Function
let t target
face min-one-of all-possible-moves [distance t]
fd 1
end
to Your-Bounce-Function
let t target
face min-one-of all-possible-moves [distance t]
end
to-report all-possible-moves
report patches in-radius 1 with [not any? walls-here and distance myself <= 1 and distance myself > 0 and plabel = "" ]
end
to leave-a-trail
ask patch-here [set plabel ticks]
end