Netlogo:询问半径内的补丁,而不是中心补丁本身
我希望使用半径内的面片制作东西,但不包括代理本身的面片,即中心面片,因此我从模型库中修改了我自己的示例:Netlogo:询问半径内的补丁,而不是中心补丁本身,netlogo,Netlogo,我希望使用半径内的面片制作东西,但不包括代理本身的面片,即中心面片,因此我从模型库中修改了我自己的示例: to splotch ask turtles [ ask one-of patches in-radius 2 with [not any? turtles-here] [ set pcolor [ color ] of myself ] ] tick end 但是这段代码也排除了海龟的其他补丁,所以应该是这样的 to splotch ask t
to splotch
ask turtles [
ask one-of patches in-radius 2 with [not any? turtles-here] [
set pcolor [ color ] of myself
]
]
tick
end
但是这段代码也排除了海龟的其他补丁,所以应该是这样的
to splotch
ask turtles [
ask one-of patches in-radius 2 [not self][
set pcolor [ color ] of myself
]
]
tick
end
但这段代码不起作用,我也不知道该怎么做 您需要
其他
原语。但是,other
排除了相同类型的代理,您希望海龟排除补丁。因此,您需要获得相关的补丁,以ask
theother
补丁。这里有一种方法:
to testme
clear-all
create-turtles 3 [setxy random-xcor random-ycor]
splotch
end
to splotch
ask turtles
[ let mycolor color
ask patch-here
[ ask other patches in-radius 4
[ set pcolor mycolor
]
]
]
end
如果您想要更像以前那样的方式,可以创建一个局部变量来存储修补程序,然后按如下方式排除它:
to splotch
ask turtles
[ let mypatch patch-here
ask patches in-radius 4 with [self != mypatch]
[ set pcolor [color] of myself
]
]
end
您需要
other
原语。但是,other
排除了相同类型的代理,您希望海龟排除补丁。因此,您需要获得相关的补丁,以ask
theother
补丁。这里有一种方法:
to testme
clear-all
create-turtles 3 [setxy random-xcor random-ycor]
splotch
end
to splotch
ask turtles
[ let mycolor color
ask patch-here
[ ask other patches in-radius 4
[ set pcolor mycolor
]
]
]
end
如果您想要更像以前那样的方式,可以创建一个局部变量来存储修补程序,然后按如下方式排除它:
to splotch
ask turtles
[ let mypatch patch-here
ask patches in-radius 4 with [self != mypatch]
[ set pcolor [color] of myself
]
]
end