有关此问题的说明,这里是带有背景信息的original question。
我一直试图让一个agentset(船只)向另一个agentset(目标端口)移动,一旦船只到达,就转移到下一个目标(最短距离)。到目前为止,虽然它没有正常工作,但我有什么:
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
非常感谢任何帮助。谢谢
答案 0 :(得分:0)
对于问题的第一部分,您只需使用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
]
]
你并没有真正提供足够的信息来回答你的其余问题,因为你的代码迫使船只在到达当前目标时选择一个新目标。一种方法是按顺序为船舶提供要访问的端口列表,然后在到达列表末尾时停止。