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