如何使海龟按顺序移动到位置列表中

时间:2015-09-03 21:08:01

标签: list indexing distance netlogo closest

我的目标是让代理集(命名为ship)在另一个代理集(命名端口并在索引中列出)中孵化,其中包含代表路径起点和终点的2个位置。要按照给定的顺序开始移动船舶/前往第三个代理集(称为路径点并在index1中列出)。 但是,如果一个港口比另一个航点更接近当前航点,则转而移至港口。一旦船只到达另一个港口,我也希望它们停下来。

目前我的模型仅使用两个代理集(船舶和港口)但是我想包括第三组(称为航路点)以防止船舶在所有位置(港口和航路点)孵化并使船舶移动在到达起点或终点(港口)之前沿着航路点(如踏脚石)行进的顺序。

以下是我的代码示例:

breed [ships ship]
breed [ports port]
breed [waypoints waypoint]
ships-own [target-port
  current-port]

to setup
ca

 let index 0  
 create-ports 2
 [ let loc item index [ [0 -32] [32 0] ] 
   setxy (item 0 loc) (item 1 loc) 
   set index index + 1  
   set shape "circle" 
   set size 2
   set color red - 1]   

 let index1 0 
 create-waypoints 2
 [let loc item index1 [[12 -3] [14 -26]]
   setxy (item 0 loc) (item 1 loc)
   set index1 index1 + 1
   set shape "circle"
   set size 1
   set color red - 1]

 ask ports
[  let s who
   hatch-ships 1
 [ set current-port s
   set size 1
   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  
  ] 
]
   reset-ticks 
end

to go 

;(obey-elevation)
ask ships 
[   if (distance target-port = 0) 
 [  let other_ports no-turtles
    ask target-port [set other_ports (other ports)]
    set target-port min-one-of other_ports [distance myself]
    face target-port
 ]
  ifelse (distance target-port < 1) 
  [ move-to target-port
  ]
    [fd 1
    ]
]

  tick
end

非常感谢任何帮助。

0 个答案:

没有答案