使海龟在NetLogo的两个元素之间完成
我是NetLogo的新手,我试图模拟一组海龟必须从一个随机空间进入目标点和墙壁之间,但到目前为止,我刚刚检索了一部分代码,使它们能够在目标点周围的各个方向上进行自我定位(海龟有能力相互说话) 然而,我无法让他们朝着其中一边结束。。。有什么提示吗使海龟在NetLogo的两个元素之间完成,netlogo,Netlogo,我是NetLogo的新手,我试图模拟一组海龟必须从一个随机空间进入目标点和墙壁之间,但到目前为止,我刚刚检索了一部分代码,使它们能够在目标点周围的各个方向上进行自我定位(海龟有能力相互说话) 然而,我无法让他们朝着其中一边结束。。。有什么提示吗 非常感谢我不确定您是否仍然希望让他们聚集在目标点周围,或者只是移动到目标点上方。这里有一个方法可以得到你想要的。它定义了一个目标点和一组安全补丁。目标点下方的海龟试图通过目标点移动到安全区域。更多详情/解释请参见评论 设置: globals [ goal
非常感谢我不确定您是否仍然希望让他们聚集在目标点周围,或者只是移动到目标点上方。这里有一个方法可以得到你想要的。它定义了一个目标点和一组安全补丁。目标点下方的海龟试图通过目标点移动到安全区域。更多详情/解释请参见评论 设置:
globals [ goal-spot safe-patches ]
to setup
ca
; Set the wall
ask patches with [ pycor = max-pycor ] [ set pcolor blue ]
; Set the goal-patch
set goal-spot patch 0 0
ask goal-spot [ set pcolor green ]
; Set up a triangular safe-patches zone
let check ( [pycor] of goal-spot - [pxcor] of goal-spot ) - 1
let gpx [pxcor] of goal-spot
set safe-patches patches with [
pycor > [pycor] of goal-spot and
pycor < max-pycor and
( ( pxcor < gpx and pycor + pxcor > check ) or
( pxcor >= gpx and pycor - pxcor > check ) ) ]
; Make some turtles
let n-turtles 255
if n-turtles > count safe-patches [
set n-turtles count safe-patches
]
crt n-turtles [
set shape "person"
set color green
move-to one-of patches with [ pycor < [pycor] of goal-spot and pycor < max-pycor]
if pycor <= [pycor] of goal-spot [
set color red
]
]
ask turtles [pd]
reset-ticks
end
globals[目标点安全补丁]
设置
ca
; 筑墙
使用[pycor=max pycor][set pcolor blue]询问补丁
; 设定目标补丁
将目标点设置为0
询问球门位置[设置P颜色为绿色]
; 建立一个三角安全区
让我们检查([pycor]球门点-[pxcor]球门点)-1
让目标点的gpx[pxcor]
使用设置安全修补程序[
pycor>[pycor]进球点和
pycor<最大pycor和
((pxcor检查)或
(pxcor>=gpx和pycor-pxcor>检查))]
; 做些乌龟
让n-海龟255
如果n-海龟>计算安全补丁[
设置n-海龟计数安全补丁
]
乌龟[
设置形状“人”
设置颜色为绿色
移动到目标点[pycor<[pycor]和pycor 如果皮科尔,你能再解释一下你所说的“在球门和墙之间”是什么意思吗在你第一张图片的背景中?我假设墙是最上面的蓝线,但是目标点在哪里,你想让海龟去哪里?谢谢你的回答,卢克!目标点是第一张图片中的绿色区域,所以海龟会被随机放置在max pxcor和max pycor周围,目标是它们朝着一个方向移动“安全区”,在这种情况下,它将位于顶部蓝线(墙)和“目标点”(绿色区域)之间,在我的模拟中,它将代表他们标记为“安全”的点(将其视为他们必须排队才能离开的紧急出口)。现在的问题是,只有不到一半的海龟会被标记为安全。谢谢你的帮助!这肯定让我开始了,非常感谢!!最后一个问题,如果我有两个球门补丁,而不是一个(比如一个上面有墙,另一个右手边有墙),你会对球门位置做两次所有说明吗(比如一次使用goal-spot-1,另一次使用goal-spot-2)或者是否有其他方法来执行某种“for”循环?(例如:首先将目标补丁设置为绿色,然后{设置goal-spot(patches with[pcolor=green]),然后对goal-spot中的补丁运行相同的指令?)@Arduino-我对我的答案做了一些补充-看一看!
to go
; Any turtles that are not on the safe spot, or share a patch
ask turtles with [not member? patch-here safe-patches or any? other turtles-here] [
let target nobody
; If below the goal spot, target it. If not, target a free safe patch
ifelse pycor < [pycor] of goal-spot [
set target goal-spot
] [
set target min-one-of ( safe-patches with [
not any? other turtles-here ] ) [distance myself
]
]
; Face target, move to it.
if target != nobody [
face target
move-to patch-ahead 1
]
]
; Stop when all turtles are safe and on their own patch
if not any? turtles with [
not member? patch-here safe-patches or
any? other turtles-here
] [
stop
]
tick
end
globals [ goal-spots safe-patches ]
to setup
ca
; Set the walls
ask ( patch-set
patches with [ pycor = max-pycor ]
patches with [ pxcor = max-pxcor ]
)
[
set pcolor blue
]
let possible-safe patches with [ pcolor = black ]
; Set up two triangular safe-patches
crt 1 [
set heading 0
fd 7
set goal-spots patch-here
set safe-patches possible-safe in-cone 20 90
set heading 90
setxy 7 0
set goal-spots ( patch-set goal-spots patch-here )
set safe-patches (
patch-set
safe-patches
possible-safe in-cone 20 90 )
die
]
ask safe-patches [
set pcolor green - 4
]
; Make some turtles
let n-turtles 100
if n-turtles > count safe-patches [
set n-turtles count safe-patches
]
crt n-turtles [
set shape "person"
set color green
move-to one-of patches with [ pycor < 0 and pxcor < 0 ]
set color red
]
ask turtles [pd]
reset-ticks
end
to go
; Any turtles that are not on the safe spot, or share a patch
ask turtles with [not member? patch-here safe-patches or any? other turtles-here] [
let target nobody
; If below the goal spot, target it. If not, target a free safe patch
ifelse not member? patch-here safe-patches [
set target min-one-of goal-spots [ distance myself ]
] [
set target min-one-of ( safe-patches with [
not any? other turtles-here ] ) [distance myself
]
]
; Face target, move to it.
if target != nobody [
face target
move-to patch-ahead 1
]
]
; Stop when all turtles are safe and on their own patch
if not any? turtles with [
not member? patch-here safe-patches or
any? other turtles-here
] [
stop
]
tick
end