Java StarLogo
2.0
english
`turtle`
turtles-own [maxheight maxhead]

to go
  setmaxheight height
  repeat 4           ;compare current height to heights around you
    [if (height-towards 0 1) > maxheight
      [setmaxheight (height-towards 0 1)
       setmaxhead heading]
     rt 90]
  seth maxhead       ;turn toward highest nearby peak
  repeat walklength [jump (min (2 / height) 10) wiggle]      ;then travel based on walklength
  scale-color blue height 16 0
end

to wiggle
  rt (random 10)
  lt (random 10)
end


`observer`
patches-own [height]
 
to setup
  ca
  crt 1
  repeat hilliness               ;create foundations for hills
    [ask-turtles 
        [setxy (random screen-height) (random screen-width)
        setc 30
        repeat 35 [stamp color seth random 360 fd 1]]]
  ask-turtles [die]
  ask-patches [if pc = 30 [set height ((random 50) + 25)]]      ;create hills through diffusion
  repeat 45 [diffuse height .9]
  ask-patches [scale-pc brown (int (height)) 0 10]
  crt num-turtles
  ask-turtles [setxy (random screen-height) (random screen-width) setc 95]
end

to averageheight
  output ((sum-of-turtles [height]) / count-turtles)
end


`information`
For use with the Adventures in Modeling book, by Vanessa Colella, Eric Klopfer, and Mitchel Resnick published by Teachers College Press, 2001.  

For more information, see  
<http://education.mit.edu/starlogo/adventures>  

Challenge 9: King of the Hill  
In this project, turtles use the "towards" command to try to reach the highest peak in the land. The patches have scaled their colors based on the values of their height variables. The "hilliness" slider controls the amount of variation in the height of the patches. The turtles head towards the highest nearby peak by looking around themselves in four directions, turning towards the highest peak, and going forward a distance based on the  "walklength" slider. The "averageheight" monitor displays  the average height which all of the turtles have reached.


`interface`
SLCanvas
top-left 4 211

SLSlider
top-left 60 36
width-height 98 25
name "slider2"
variable "num-turtles"
min-value 0
max-value 100
current-value 100
slider-number 1
show-name? false

SLMonitor
top-left 180 36
width-height 98 36
name "averageheight"
list-to-run "averageheight"
digits 1
delay 1.0
monitor-number 1
show-name? true
whichip 6
onewhichip 7

SLSlider
top-left 26 36
width-height 98 25
name "slider1"
variable "hilliness"
min-value 1
max-value 30
current-value 15
slider-number 0
show-name? false

SLSlider
top-left 232 36
width-height 98 25
name "slider2"
variable "walklength"
min-value 0
max-value 50
current-value 16
slider-number 2
show-name? false

SLButton
turtle-or-observer? turtle
top-left 138 43
width-height 84 30
name "button2"
line-to-run "go"
forever? true
button-number 3
show-name? false
whichip 4

SLButton
turtle-or-observer? observer
top-left 97 43
width-height 84 30
name "button1"
line-to-run "setup"
forever? false
button-number 2
show-name? false
whichip 5


`turtle shapes`
[encoded data, 5330 characters]
qqqqqqqaoR8DO5wb3dkOFQAAFQ7Z

`template`
null

`settings`
patch-size 6
num-shapes 256
screen-half-width 35
screen-half-height 35
interface-window-xcor 385
interface-window-ycor 92
interface-window-size 674 436
output-window-xcor 0
output-window-ycor 0
output-window-width 300
output-window-height 219
info-window-xcor 109
info-window-ycor 193
info-window-width 500
info-window-height 419
control-center-xcor 61
control-center-ycor 186
control-center-width 285
control-center-height 415
turtle-command-center-height 150
observer-command-center-height 150

`string table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`symbol table`
H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA==

`double table`
[encoded data, 52325 characters]
B9lKnmOsnQAAAACdrA==

`list table`
H4sIAAAAAAAAAE2NvQqAMBCDkyIInYSC4OLi7OLjuLj6ev48oDkJ2sLHJZeSA9AC
KAQoIEYxEdy9C7+IwfkcM6Ec4vQuyP6/wV16fZU3lWalP6++S3O1T+btVnZbd+5O
vpnxe0aH7/MBkPaCZtwAAAAAAADc

`bytecodes`
H4sIAAAAAAAAAH1T207DMAx10gujHU3pBTrYw2D7ij0h3nnhCzag6ibBirYOxD/C
P+EkTtMVsUiVncQ+ds5xIVw8fTXlc/1S7hZ38C3XDwAMwNuVzf4d3Tdo1y1+jPzC
JZ8Bm6Hh0h+TLYCNHWCxj5YrC7lP8RiQx+Q7FB8AyyOAzKFzl3IK2nvoD1U4iFNt
p77dc8ItwN6pswRYxggDe4kv23r67ETXUf4AffM+xExdwueEad4bEIbJC8lifzf9
noZ0d0Y2ApYiX/GY9oIsF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