NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary

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

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Hill Climbing 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 example shows how to make turtles climb hills -- or descend into valleys -- using the uphill, uphill4, downhill, and downhill4 commands. The same technique is useful for modeling any kind of creature that follows a gradient in its environment.

THINGS TO NOTICE

These commands always make the turtle move to the center of a patch.

uphill and downhill make the turtle look at all eight neighboring patches (including diagonal neighbors). uphill4 and downhill4 only look at the four neighboring patches (to the north, south, east, and west).

With the uphill and downhill commands, diagonal moves are longer (1.414...) than vertical or horizontal moves (1.0). If you use the uphill4 and downhill4 commands, all moves are the same length (1.0).

If there is a tie between neighboring patches, NetLogo breaks the tie randomly.

THINGS TO TRY

In the go procedure in the Code tab, change uphill to uphill4, downhill, or downhill4 and observe the results.

NETLOGO FEATURES

If you look at the entry for uphill in the NetLogo Dictionary, it shows some code that does the exact same thing as the primitive does. If you need to do something that is similar to the primitive, but different in so way, you could use that code as a starting point.

(back to the NetLogo Models Library)