neighbors

 

neighbors reports an agentset that contains the eight patches that surround an agent's current patch in the north, northeast, east, southeast, south, southwest, west, and northwest directions. Both turtles and patches are allowed to use this reporter. For example, if we wanted to create a model in which a fire spread from one patch to its neighbors, we would write the following code:

ask patches [
    if pcolor = red [
        ask neighbors [
            if pcolor = green [
                set pcolor red
            ]
        ]
    ]
]

Things to keep in mind when using neighbors:

In the model example below, we have green patches that represent vegetation and some brown bugs that eat this vegetation. You can see this as bugs on a leaf. At each tick, our bugs eat a little bit of the patch that they are on. If a bug finishes all the grass on one patch, it moves to a neighboring patch and continues eating.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the neighbors primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the neighbors primitive:
 
 
Similar primitives:
neighbors4

Reports an agentset containing the four neighboring patches in cardinal directions (north, west, south, east).

Read more
patch-ahead

Reports the single patch that is the given distance “ahead” of this turtle

Read more
turtles-here

Reports the agentset of all the turtles on a caller's patch.

Read more
patches

Reports an agentset that contains all the patches in a model.

Read more
 
Learn another primitive: