Netlogo-每个补丁只创建一个海龟
我试图在办公空间区域创造海龟,指定的灰色补丁代表它们的隔间。然而,当海龟们被创造出来时,在一个小隔间里,它们之间会有一些重叠 如何确保每个隔间只创建一只海龟?(在***下查找代码) 这是我的代码:Netlogo-每个补丁只创建一个海龟,netlogo,Netlogo,我试图在办公空间区域创造海龟,指定的灰色补丁代表它们的隔间。然而,当海龟们被创造出来时,在一个小隔间里,它们之间会有一些重叠 如何确保每个隔间只创建一只海龟?(在***下查找代码) 这是我的代码: breed [programmers programmer] globals [] patches-own [ a-space b-space c-space d-space a-cubicle b-cubicle c-cubicle d-cubicle cubi
breed [programmers programmer]
globals []
patches-own [
a-space
b-space
c-space
d-space
a-cubicle
b-cubicle
c-cubicle
d-cubicle
cubicle?]
programmers-own [
speed
team-name
motivation
myCubicle
teammates
projects
counter ]
to setup-environment
ask patches with [ pycor mod 2 = 0 and pxcor = -16] [ set pcolor grey ]
ask patches with [ pycor mod 2 = 0 and pxcor = 16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor = -16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor = 16] [ set pcolor grey ]
ask patches with [ pycor = 0] [ set pcolor red ]
ask patches with [ pxcor = 0] [ set pcolor red ]
ask patches [
set a-space patches with [(pxcor > -14) and (pxcor < 0) and (pycor > 0) and (pycor < 14)]
set b-space patches with [(pxcor < 14) and (pxcor > 0) and (pycor > 0) and (pycor < 14)]
set c-space patches with [(pxcor < 14) and (pxcor > 0) and (pycor < 0) and (pycor > -14)]
set d-space patches with [(pxcor > -14) and (pxcor < 0) and (pycor < 0) and (pycor > -14)]
set a-cubicle patches with [(pycor mod 2 = 0) and (pxcor mod 2 = 0) and (pxcor >= -16) and (pycor <= 16) and (pxcor < 0) and (pycor > 0)]
set b-cubicle patches with [(pycor mod 2 = 0) and (pxcor mod 2 = 0) and (pxcor <= 16) and (pycor <= 16) and (pxcor > 0) and (pycor > 0)]
set c-cubicle patches with [(pycor mod 2 = 0) and (pxcor mod 2 = 0) and (pxcor <= 16) and (pycor >= -16) and (pxcor > 0) and (pycor < 0)]
set d-cubicle patches with [(pycor mod 2 = 0) and (pxcor mod 2 = 0) and (pxcor >= -16) and (pycor >= -16) and (pxcor < 0) and (pycor < 0)] ]
ask patches with [pcolor = grey] [set cubicle? true]
end
to setup-programmers
create-programmers Number_Of_Programmers [
set shape "person"
ask n-of (Number_Of_Programmers / 4) programmers [set team-name "A"]
ask n-of (Number_Of_Programmers / 4) programmers [set team-name "B"]
ask n-of (Number_Of_Programmers / 4) programmers [set team-name "C"]
ask n-of (Number_Of_Programmers / 4) programmers [set team-name "D"]
; *** WHAT I'M TRYING TO DO WOULD GO HERE ***
ask programmers with [team-name = "A"] [ set color blue] if other turtles-on patch-here [ move-to one-of a-cubicle with [cubicle? = true] set myCubicle patch-here]
ask programmers with [team-name = "B"] [ set color green move-to one-of b-cubicle with [cubicle? = true] set myCubicle patch-here]
ask programmers with [team-name = "C"] [ set color pink move-to one-of c-cubicle with [cubicle? = true] set myCubicle patch-here]
ask programmers with [team-name = "D"] [ set color yellow move-to one-of d-cubicle with [cubicle? = true] set myCubicle patch-here]
ask programmers [set teammates programmers with [color = [color] of myself]]
set projects (list)
set motivation 100
set counter 0
]
end
to setup
clear-all
reset-ticks
setup-environment
setup-programmers
end
to go
lose-or-gain-motivation
socialize
complete-program
tick
end
bride[程序员]
全局[]
补丁自己[
a-空间
b-空间
C空间
d-空间
a隔间
b隔间
c形隔间
d形隔间
隔间?]
程序员拥有[
速度
队名
动机
我的隔间
队友
项目
柜台]
设置环境
使用[pycor mod 2=0和pxcor=-16][set pcolor grey]询问补丁
使用[pycor mod 2=0和pxcor=16][set pcolor grey]询问补丁
使用[pxcor mod 2=0和pycor=-16][set pcolor grey]询问补丁
使用[pxcor mod 2=0和pycor=16][set pcolor grey]询问补丁
使用[pycor=0][set pcolor red]询问修补程序
使用[pxcor=0][set pcolor red]询问修补程序
询问补丁[
使用[(pxcor>-14)和(pxcor<0)以及(pycor>0)和(pycor<14)]设置a空间面片
使用[(pxcor<14)和(pxcor>0)以及(pycor>0)和(pycor<14)]设置b空间面片
使用[(pxcor<14)和(pxcor>0)以及(pycor<0)和(pycor>-14)]设置c空间面片
使用[(pxcor>-14)和(pxcor<0)以及(pycor<0)和(pycor>-14)]设置d空间面片
使用[(pycor mod 2=0)和(pxcor mod 2=0)以及(pxcor>=-16)和(pycor 0)]设置a柜贴片
用[(pycor mod 2=0)和(pxcor mod 2=0)以及(pxcor 0)]设置b隔间贴片
用[(pycor mod 2=0)和(pxcor mod 2=0)和(pxcor=-16)以及(pxcor>0)和(pycor<0)]设置c柜贴片
用[(pycor mod 2=0)和(pxcor mod 2=0)和(pxcor>=-16)和(pycor>=-16)以及(pxcor<0)和(pycor<0)]设置d隔间贴片
使用[pcolor=grey][set-Cubble?true]询问补丁
结束
设置程序员
创建程序员人数[
设置形状“人”
询问n-of(程序员数量/4)程序员[设置团队名称“A”]
询问n-of(程序员数量/4)程序员[设置团队名称“B”]
询问n-of(程序员数量/4)程序员[设置团队名称“C”]
询问n-of(程序员数量/4)程序员[设置团队名称“D”]
我要做的就是到这里来***
询问程序员[team name=“A”][set color blue]是否有其他海龟在这里补丁[移动到A-Cubble中的一个,使用[Cubble?=true]在这里设置MyCubble补丁]
请程序员使用[team name=“B”][将颜色设置为绿色,并使用[Cubble?=true]将MyCubble补丁设置为此处]
请程序员使用[team name=“C”][将颜色设置为粉红色,并使用[Cubble?=true]在此处设置MyCubble补丁]
请程序员使用[team name=“D”][将颜色设置为黄色,并使用[Cubble?=true]将MyCubble补丁设置为此处]
询问程序员[用[color=[color]自己设置队友程序员]]
设置项目(列表)
设定动机100
设置计数器0
]
结束
设置
清除所有
重置滴答声
设置环境
安装程序员
结束
外带
失去或获得动力
社交
完整程序
打上钩
结束
在NetLogo中创建海龟代理有三种不同的方法。如果您希望一个补丁中不超过一只海龟,最简单的方法是选择一个子集补丁(使用n-of-XXX补丁
),并让它们发芽
海龟。在您的情况下,类似的方法可能会起作用:
替换创建程序员人数\u程序员
与
在NetLogo中创建海龟代理有三种不同的方法。如果您希望一个补丁中不超过一只海龟,最简单的方法是选择一个子集补丁(使用
n-of-XXX补丁
),并让它们发芽
海龟。在您的情况下,类似的方法可能会起作用:
替换创建程序员人数\u程序员
与
请使用代码格式({}图标)而不是引号来显示问题中的代码。我对它进行了编辑,以便您可以看到差异。此外,您应该只显示与问题相关的代码。请使用代码格式({}图标)而不是引号来显示问题中的代码。我对它进行了编辑,以便您可以看到差异。另外,您应该只显示与您的问题相关的代码。我尝试过这样做,我得到了“SPROUT希望此输入是一个数字,但得到了一个turtle agentset”,然后我尝试删除程序员:>[SPROUT 1,但后来我得到了“您不能在修补程序上下文中使用形状,因为形状仅限于turtle/link。”for>set SHAPE“person”请参阅修订版-缺少一个破折号我尝试过,得到了“SPROUT期望此输入是一个数字,但得到了一个turtle agentset”,然后我尝试删除程序员:>[SPROUT 1,但后来我得到了“您不能在补丁上下文中使用形状,因为形状仅为turtle/link。”对于>设置形状“person”,请参阅修订版-缺少破折号
ask n-of Number_Of_Programmers patches with [cubicle?]
[ sprout-programmers 1