Search code examples
distancenetlogoneighbours

NetLogo: select a patch with neighbors having certain qualities?


I want to let my turtle move to certain patch and make a "splotch". The central patch = my turtle location, can be selected randomly, however satisfy two conditions:

  • has to be in a certain distance from turtle's actual position
  • has to surrounded (neighbors in certain radius) by patches with specific quality

The reason is to create kind of "buffers" around my turtle's position, with aim to obstruct the close proximity of my clumps.

Please, how can I satisfy these two conditions?

As far, I have:

to go
 ask turtles [                 
   ; select one of patches in specific distance, and 
   ; surrounded by patches with no magenta color
   let aaa one-of patches with [distance myself > 3 and   
       all? neighbors with [pcolor != magenta]] 
                      ; how to write this condition above ?? 
                      ; and how replace "neighbors" by "in-radius"??
   move-to aaa
   ask neighbors [           ; create clump of magenta patches
     set pcolor magenta ]
   ask patch-here [          ; set central patch to magenta
     set pcolor magenta ]
 ]

enter image description here


Solution

  • You're almost there; you just need to reread the documentation for all? and any?.

    let _candidates patches with [distance myself > 3]
    set _candidates _candidates with [
      not any? (patches in-radius 3 with [pcolor = magenta])
    ]
    let aaa one-of _candidates
    

    If it is possible that there will be no candidates, you should guard against that.