我是NetLogo的新手,我希望这是一个简单的问题。我创建了两个品种[ redteam redsoldier]
& [blueteam bluesoldier]
我要做的是让不同的品种在特定的补丁中产生。所以红队只能在窗口的一半(红色区域)中随机产生,而蓝队则在另一个(蓝色区域)中随机产生,但是在尝试多个if和while语句和其他东西后,海龟只产生于屏幕中心。
有什么想法吗?
globals [
red-patches
blue-patches
]
;; note patches could not be set to only green as this partly clashed with soldiers uniform
breed [ redteam redsoldier]
breed [ blueteam bluesoldier]
to setup
clear-all
setup-turtles
setup-patches
reset-ticks
end
to setup-turtles
create-redteam 10
[
set shape "person soldier" ;;need to import person soldier shape!
setxy random-pxcor random-pycor
set size 1.5
]
create-blueteam 10
[
set shape "person soldier"
setxy random-pxcor random-pycor
set size 1.5
]
end
to setup-patches
;; create red territory
set red-patches patches with [pycor < 0]
ask red-patches [ set pcolor green - 3 ]
;; create blue territory
set blue-patches patches with [pycor > 0]
ask blue-patches [ set pcolor green - 2 ]
end
答案 0 :(得分:3)
一种简单的方法是使用sprout
。
以下是setup-turtles
的新版本(需要在 setup-patches
之后调用):
to setup-turtles
ask n-of 10 red-patches [
sprout-redteam 1 [
set shape "person soldier"
set size 1.5
]
]
ask n-of 10 blue-patches [
sprout-blueteam 1 [
set shape "person soldier"
set size 1.5
]
]
end