如何将海龟移动到顺序目标并在端点停止
how to move turtles to sequential targets and stop at endpoints
为了澄清这个问题,这里是 背景信息。
我一直在尝试让一个代理集(船只)移动到另一个代理集(目标端口),一旦船只到达,就移动到下一个目标(最短距离)。到目前为止我所拥有的虽然它不能正常工作:
ask ships
[ if distance target-port = 0
[ set target-port min-one-of ports with [who != myself] [distance myself]
face target-port ]
ifelse distance target-port < 1
[ move-to target-port ]
[ fd 1 ]
]
我还想让船只在到达路径尽头后停止移动。 (即此特定场景中的端口 0 或 2)。
下面是整个代码的示例,以便于理解:
breed [ships ship]
breed[ports port]
ships-own [current-port target-port]
to setup
clear-all
let index 0
create-ports 3
[
let loc item index [ [4 -4] [ 9 5] [ -11 11] ]
setxy (item 0 loc) (item 1 loc)
set index index + 1
set shape "circle"
set size 5
set color red - 1]
ask ports
[let s who
set label ( word " Port " s )
hatch-ships 1
[ set current-port s
set size 10
set color red
pen-down
set pen-size 1
Set target-port min-one-of ports with [ who != s] [distance myself]
set heading towards target-port
set label (word "target " target-port)
] ]
reset-ticks
end
to go
ask ships
[ if distance target-port = 0
[ set target-port min-one-of ports with [who != myself] [distance myself]
face target-port ]
ifelse distance target-port < 1
[ move-to target-port ]
[ fd 1 ]
]
end
如有任何帮助,我们将不胜感激。谢谢
对于你问题的第一部分,你只需要使用other
。
ask ships [
if (distance target-port = 0) [
let _otherports no-turtles
ask target-port [set _otherports (other ports)]
set target-port min-one-of _otherports [distance myself]
face target-port
]
ifelse (distance target-port < 1) [
move-to target-port
][
fd 1
]
]
您并没有真正提供足够的信息来回答您剩下的问题,因为您的代码会强制船只在到达当前目标后选择一个新目标。一种方法是给一艘船按顺序列出要访问的港口,然后在到达列表末尾时停止。
为了澄清这个问题,这里是
我一直在尝试让一个代理集(船只)移动到另一个代理集(目标端口),一旦船只到达,就移动到下一个目标(最短距离)。到目前为止我所拥有的虽然它不能正常工作:
ask ships
[ if distance target-port = 0
[ set target-port min-one-of ports with [who != myself] [distance myself]
face target-port ]
ifelse distance target-port < 1
[ move-to target-port ]
[ fd 1 ]
]
我还想让船只在到达路径尽头后停止移动。 (即此特定场景中的端口 0 或 2)。
下面是整个代码的示例,以便于理解:
breed [ships ship]
breed[ports port]
ships-own [current-port target-port]
to setup
clear-all
let index 0
create-ports 3
[
let loc item index [ [4 -4] [ 9 5] [ -11 11] ]
setxy (item 0 loc) (item 1 loc)
set index index + 1
set shape "circle"
set size 5
set color red - 1]
ask ports
[let s who
set label ( word " Port " s )
hatch-ships 1
[ set current-port s
set size 10
set color red
pen-down
set pen-size 1
Set target-port min-one-of ports with [ who != s] [distance myself]
set heading towards target-port
set label (word "target " target-port)
] ]
reset-ticks
end
to go
ask ships
[ if distance target-port = 0
[ set target-port min-one-of ports with [who != myself] [distance myself]
face target-port ]
ifelse distance target-port < 1
[ move-to target-port ]
[ fd 1 ]
]
end
如有任何帮助,我们将不胜感激。谢谢
对于你问题的第一部分,你只需要使用other
。
ask ships [
if (distance target-port = 0) [
let _otherports no-turtles
ask target-port [set _otherports (other ports)]
set target-port min-one-of _otherports [distance myself]
face target-port
]
ifelse (distance target-port < 1) [
move-to target-port
][
fd 1
]
]
您并没有真正提供足够的信息来回答您剩下的问题,因为您的代码会强制船只在到达当前目标后选择一个新目标。一种方法是给一艘船按顺序列出要访问的港口,然后在到达列表末尾时停止。