【发布时间】:2017-07-11 19:39:15
【问题描述】:
我正在尝试在 Netlogo 中建立一个世界,其中有两个品种,但每个补丁只有一只乌龟:
breed [supras supra]
breed [subs sub]
turtles-own [age]
subs-own [status]
to setup
clear-all
;; Color the patches so they're easier to see
ask patches [ set pcolor random-float 2 ]
;; num-turtles patches will sprout one turtle each
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-subs 1
]
]
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-supras 1
]
]
;; Set breed colors and own-variables
ask subs [
set color blue
set shape "dot"
]
ask supras [
set color pink
set shape "dot"
]
reset-ticks
end
to go
ask turtles [
fd 1
]
tick
end
这似乎可行,但我不能完全确定它在技术上是否正确。编写什么测试可以确保我在初始化时没有包含多个海龟的补丁?
【问题讨论】:
-
我认为你的代码是可靠的——如果你想确认你可以通过在你的
setup程序的末尾添加类似if any? patches with [ count turtles-here > 1 ] [ setup ]的东西来检查——如果有的话,这将重新运行你的设置程序带有两个以上turtles-here的补丁。显然,如果您稍后在setup中包含更多海龟,那么该检查将不再有效。 -
酷,谢谢!我尝试了您的建议,然后在我的设置方法结束时尝试了
if any? patches with [ count turtles-here > 1 ] [ output-print "reset" ],只要我等待,它似乎就没有打印reset。对我来说已经足够了。 -
正确。您还可以通过将
> 1更改为> 0并观察setup运行到无穷大来确认它是否有效,但您必须使用工具> 停止来停止它。
标签: netlogo