2
我想要做的一件事就是让一群乌龟四处走动,但是当到达目的地时,乌龟会在继续前等待一定数量的蜱虫。也有可能使海龟根据其目的地(不同的斑块颜色)等待不同数量的滴答。这是一个使乌龟品种或全球变量来计算蜱数量的情况吗?有希望的相关代码如下。让龟等待x数量的蜱
我想要做的一件事就是让一群乌龟四处走动,但是当到达目的地时,乌龟会在继续前等待一定数量的蜱虫。也有可能使海龟根据其目的地(不同的斑块颜色)等待不同数量的滴答。这是一个使乌龟品种或全球变量来计算蜱数量的情况吗?有希望的相关代码如下。让龟等待x数量的蜱
你是对的,这可以通过让海龟计算它们在补丁上的滴答数来完成。另外这必须是一个海龟变量,而不是全局变量,因为每个龟都会有这个
的方法,我用不同的值是这样的:
ticks
(记录迄今为止已经传递的滴答数量的全局变量)转换为龟变量,如ticks-since-here
。这就像一个时间戳。在每个连续的滴答检查当前时间ticks
全局变量和ticks-since-here
乌龟变量之间的差异。如果这变得比蜱的数量更多,龟允许留在补丁上,让它选择并移动到新的目的地。
品种[游客游客]
globals [ number-of-visitors ]
visitors-own [
; visitors own destination
destination
ticks-since-here
]
to go
ask visitors [
move
]
tick
end
to move
; Instructions to move the agents around the environment go here
; comparing patch standing on to dest, if at dest then choose random new dest
; then more forward towards new dest
ifelse (patch-here = destination)
[
if ticks - ticks-since-here > ticks-to-stay-on-patch patch-here
[
set ticks-since-here 0
set destination one-of patches with
[
pcolor = 65 or pcolor = 95 or pcolor = 125 or pcolor = 25 or pcolor = 15 or pcolor = 5
]
]
]
[
face destination
forward 1
if (patch-here = destination)
[
set ticks-since-here ticks
]
]
end
to-report ticks-to-stay-on-patch [p]
if [pcolor] of p = 65
[
report 6
]
if [pcolor] of p = 95
[
report 5
]
if [pcolor] of p = 125
[
report 4
]
if [pcolor] of p = 25
[
report 3
]
if [pcolor] of p = 15
[
report 2
]
if [pcolor] of p = 5
[
report 1
]
end
to setup-people
;;;; added the following lines to facilitate world view creation
ask patches
[
set pcolor one-of [65 95 125 25 15 5]
]
set number-of-visitors 100
;;;;
create-visitors number-of-visitors
[
ask visitors
[
; set the shape of the visitor to "visitor"
set shape "person"
; set the color of visitor to white
set color white
; give person a random xy
setxy (random 50) (random 50)
; set visitors destination variable
set destination one-of patches with
[
pcolor = 65 or pcolor = 95 or pcolor = 125 or pcolor = 25 or pcolor = 15 or pcolor = 5
]
]
]
end
我曾尝试以下,但它似乎1个滴答,而不是乌龟住蜱的x天内倒计时。 http://stackoverflow.com/questions/19993631/netlogo-how-to-make-turtles-stop-for-a-set-number-of-ticks-then-continue – SamP