为了澄清这个问题,这是带有背景信息的原始问题。
我一直试图让一个代理组(船只)向另一个代理组(目标端口)移动,一旦船只到达,就移动到下一个目标(距离最短)。到目前为止,尽管它无法正常工作,但我所拥有的:
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
任何帮助将不胜感激。谢谢