NetLogo banner

 Home
 Download
 Help
 Resources
 Extensions
 FAQ
 NetLogo Publications
 Contact Us
 Donate

 Models:
 Library
 Community
 Modeling Commons

 User Manuals:
 Web
 Printable
 Chinese
 Czech
 Farsi / Persian
 Japanese
 Spanish

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Random Grid Walk Example

[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web

WHAT IS IT?

This code example is a demo of a basic random walk, constrained to lie on a grid. At each step, the yellow turtle changes its heading randomly, but always in multiples of 90, so the turtle is always facing due north, east, south, or west. At each step, the turtle always lands on the center of a patch.

Two slightly different kinds of walk are demonstrated:

  • In WALK1, the turtle's heading at each time step is completely random.

  • In WALK2, the turtle never makes an immediate about face (180 degree turn). Thus, it will tend to proceed in one direction for longer. This is more similar to how a person or animal might wander.

THINGS TO NOTICE

The monitors show that the turtle's xcor and ycor are always exact multiples of 1.0. That means that the turtle is always on a patch center.

RELATED MODELS

Random Walk Example - shows a freer random walk which does not follow a grid

(back to the NetLogo Models Library)