NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

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

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Wall Following 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?

The turtles in this example follow walls made out of colored patches. Some turtles try to keep the wall on their right; others keep the wall on their left.

HOW IT WORKS

Consider a turtle that wants to keep a wall on its right. If there is no wall immediately to its right, but there is a wall behind it on the right, it must turn right in order not to lose the wall. If there's a wall directly in front of the turtle, it keeps turning left until there's free space in front of it. Then it can move forward.

THINGS TO NOTICE

The turtles always stay on patch centers and never move diagonally.

If there isn't a wall next to a turtle when it is born, it just moves forward until it finds one.

EXTENDING THE MODEL

The walk procedure will get stuck in an infinite loop if a turtle finds itself surrounded by walls on all four sides. The setup procedure detects such turtles and kills them off, so the model won't get stuck. How would you change walk not to have this problem? (You might need to do so in a model where the walls could move and grow.)

NETLOGO FEATURES

Turtles use the patch-right-and-ahead primitive to look at patches around themselves, relative to the direction the turtle is facing.

(back to the NetLogo Models Library)