Hill Climbing Example

Hill Climbing Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1314 times • Downloaded 110 times • Run 2 times
Download the 'Hill Climbing Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own
[
  peak? ;; indicates whether a turtle has reached a "peak",
        ;; that is, it can no longer go "uphill" from where it stands
]

to setup
  clear-all
  ;; make a landscape with hills and valleys
  ask n-of 100 patches [ set pcolor 120 ]
  ;; slightly smooth out the landscape
  repeat 20 [ diffuse pcolor 1 ]
  ;; put some turtles on patch centers in the landscape
  ask n-of 800 patches [
    sprout 1 [
      set peak? false
      set color red
      pen-down
    ]
  ]
  reset-ticks
end 

to go
  ;; stop when all turtles are on peak
  if all? turtles [peak?]
    [ stop ]
  ask turtles [
    ;; remember where we started
    let old-patch patch-here
    ;; to use UPHILL, the turtles specify a patch variable
    uphill pcolor
    ;; are we still where we started? if so, we didn't
    ;; move, so we must be on a peak
    if old-patch = patch-here [ set peak? true ]
  ]
  tick
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Hill Climbing Example Download this version
Uri Wilensky over 14 years ago Hill Climbing Example Download this version

Attached files

File Type Description Last updated
Hill Climbing Example.png preview Preview for 'Hill Climbing Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.