使海龟在 NetLogo 中的 2 个元素之间完成
Make turtles finish between 2 elements in NetLogo
我是 NetLogo 的新手,我正在尝试模拟一组海龟必须随机 space 将它们自己放置在目标点和墙之间,但到目前为止我'我们刚刚检索了部分代码,使它们能够将自己放置在目标点周围的各个方向(海龟具有相互交谈的能力)。
但是,我无法让它们向一侧完成...有什么提示吗?
非常感谢
我不确定您是否仍想让它们聚集在 goal-point 周围,或者只是移动到它上面。这是一种可能会得到你想要的东西的方法。它定义了一个目标点和一组安全补丁。目标点下方的海龟试图穿过目标点到达安全区域。评论中的更多详细信息/解释
设置:
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
机芯:
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
请注意,这只是一种存在明显问题的方法的简单示例(例如,如果您在一个补丁上有太多海龟,一两只海龟会在试图 "in" 到最近的地方时卡住安全区,即使它已满)。我会说,如果你能以某种方式定义你的两个安全区域,然后 运行 遇到问题,那么值得发布一个新问题来弄清楚如何解决你遇到的任何新问题。
我是 NetLogo 的新手,我正在尝试模拟一组海龟必须随机 space 将它们自己放置在目标点和墙之间,但到目前为止我'我们刚刚检索了部分代码,使它们能够将自己放置在目标点周围的各个方向(海龟具有相互交谈的能力)。
但是,我无法让它们向一侧完成...有什么提示吗?
非常感谢
我不确定您是否仍想让它们聚集在 goal-point 周围,或者只是移动到它上面。这是一种可能会得到你想要的东西的方法。它定义了一个目标点和一组安全补丁。目标点下方的海龟试图穿过目标点到达安全区域。评论中的更多详细信息/解释
设置:
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
机芯:
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
请注意,这只是一种存在明显问题的方法的简单示例(例如,如果您在一个补丁上有太多海龟,一两只海龟会在试图 "in" 到最近的地方时卡住安全区,即使它已满)。我会说,如果你能以某种方式定义你的两个安全区域,然后 运行 遇到问题,那么值得发布一个新问题来弄清楚如何解决你遇到的任何新问题。