Farsi / Persian
NetLogo Models Library:
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.
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.
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.
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.)
Turtles use the
patch-right-and-ahead primitive to look at patches around themselves, relative to the direction the turtle is facing.