patch-ahead

 

patch-ahead reports the single patch that is the given distance ahead of the asking turtle. You can think of it as the turtle looking at a patch in front of it. For example, if we were creating a highway traffic model and wanted our cars to only move if there was no other car in front of them, we would write the following code:

ask cars [
    set heading 90
    if count turtles-on patch-ahead 1 = 0 [
        forward 1
    ]
]

Things to keep in mind when using patch-ahead:

In the model example below, we have some gray patches that represent a road and a red patch that represents a stop sign. Our car moves on the road towards east as long as the pcolor of the patch-ahead 1 is gray. If not, our car does not move, which means that it stops at the stop sign.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the patch-ahead primitive:
 
 
Similar primitives:
neighbors

Reports an agentset containing the eight neighboring patches.

Read more
in-radius

Reports members of an agentset within a certain radius of an agent.

Read more
in-cone

Reports members of an agentset within a "cone-of-vision" of an agent.

Read more
nobody

A special value that helps checking if an agent exists or not.

Read more
 
Learn another primitive: