我目前有一个代理集(端口)孵化另一个代理集(发货)。 这个想法是让船舶面向最接近其当前位置的港口。
[let target min-one-of ports [distance myself]
face target]
。
不幸的是,这使得船只面向当前位置,因为它们在给定的港口被孵化。如果没有办法排除他们孵化的端口 - 我有一个位置索引(端口),并可能将目标设置为索引中的以下项目,但我不知道如何实现这一点。有什么建议吗?
完整代码示例
breed [ships ship]
breed[ports port]
to setup
let index 0
create-ports 3
[ let loc item index [ [459 -324] [670 -233] [677 -356] ]
setxy (item 0 loc) (item 1 loc)
set index index + 1
set shape "circle"
set size 5
set color red - 1]
ask ports
[ hatch-ships 1
[ set size 10
set color red
pen-down
set pen-size 1
let target min-one-of other ports [distance myself]
face target] ]
reset-ticks
end
答案 0 :(得分:1)
您可以将阴影端口的who值指定为当前端口,并将其目标端口定义为不是当前端口的关闭端口。
breed [ships ship]
breed[ports port]
ships-own [currentPort targetPort]
to setup
clear-all
let index 0
create-ports 3
[
; let loc item index [ [459 -324] [670 -233] [677 -356] ]
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 S " Port " s )
hatch-ships 1
[ set currentPort s
set shape "sailboat side"
set size 10
set color red
pen-down
set pen-size 1
Set targetPort min-one-of ports with [ who != s] [distance myself]
set heading towards targetport
set label (word "target " targetport)
] ]
reset-ticks
end