netlogo植绒程序沿特定颜色的补丁

时间:2017-09-21 14:14:54

标签: netlogo

我最近才开始使用netlogo,我试图调整植绒模型,以反映沿着定义的街道网络的游行团体移动。植绒过程正在进行,但我很难将运动限制在街道网络中,这是黑色斑块。

我已经从GIS扩展程序中定义了街道补丁

ask patches
  [ ifelse gis:intersects? streets self [
    set street? true
    ]
    [
      set street? false
    ]
  ]
  ask patches with [ street? ]
  [ set pcolor black ]

我试图让乌龟使用以下示例避免某些补丁,但结果是乒乓运动

if [pcolor] of patch-ahead 3 = gray + 4 [set heading heading - 180] 

我不确定是否有更好的方法可以使用下面发布的植绒代码让乌龟沿着黑色街道补丁移动。

to move-serapis
  ask serapis [ process ]
    repeat 5 [ ask serapis [ fd 0.2 ] display ]
  tick
end

to process                           
  find-serapidmates
  if any? serapidmates
    [ find-serapis-neighbor
      ifelse distance serapis-neighbor < .5
        [ separate ]
        [ align
          cohere ]
  ]
end

to find-serapidmates                
  set serapidmates other serapis in-radius 12 ;vision
end

to find-serapis-neighbor 
  set serapis-neighbor min-one-of serapidmates [distance myself]
end

to separate  ;; turtle procedure
  turn-away ([heading] of serapis-neighbor) 19.5
end

to align  ;; turtle procedure
  turn-towards average-serapidmates-heading 19.75
end

to-report average-serapidmates-heading                   
  let x-component sum [dx] of serapidmates
  let y-component sum [dy] of serapidmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end

to cohere                                                 
  turn-towards average-heading-towards-serapidmates 10
end

to-report average-heading-towards-serapidmates  ;; turtle procedure
  let x-component mean [sin (towards myself + 180)] of serapidmates
  let y-component mean [cos (towards myself + 180)] of serapidmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end

to turn-towards [new-heading max-turn]                    
  turn-at-most (subtract-headings new-heading heading) max-turn
end

to turn-away [new-heading max-turn]  
  turn-at-most (subtract-headings heading new-heading) max-turn
end

to turn-at-most [turn max-turn]  
  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end 

0 个答案:

没有答案