Created
February 2, 2017 03:23
-
-
Save kf0jvt/3eff246dfe6868d52281bc6e3865f0b8 to your computer and use it in GitHub Desktop.
netlogo painted desert challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
turtles-own [ chip? chip-color ] | |
patches-own [ leaves ] | |
to setup | |
clear-all | |
set-default-shape turtles "bug" | |
ask patches | |
[ if random-float 100 < density | |
[ set pcolor ((random colors) * 10) + 5 ] ] | |
create-turtles number | |
[ set chip-color ((random colors) * 10) + 5 | |
set color white | |
set chip? false | |
setxy random-xcor random-ycor | |
set size 2 ] ;; easier to see | |
reset-ticks | |
end | |
to go | |
find-chip ;; find a wood chip and pick it up | |
find-new-pile ;; find another wood chip | |
find-empty-spot ;; find a place to put down wood chip | |
end | |
to find-chip | |
if (chip-color = pcolor) ;; if wood-chip is my color | |
[ set pcolor black ;; then pick up the chip | |
set chip? true | |
set color chip-color | |
get-away | |
stop ] | |
wiggle | |
find-chip | |
end | |
to find-new-pile | |
if (pcolor = chip-color) | |
[ stop ] | |
fd 10 | |
wiggle | |
find-new-pile | |
end | |
to find-empty-spot | |
if pcolor = black ;; if find a patch without a wood chip | |
[ set pcolor chip-color ;; put down wood chip in patch | |
set chip? false | |
set color white | |
fd 20 | |
stop ] | |
rt random-float 360 | |
fd 1 | |
find-empty-spot | |
end | |
to get-away | |
rt random-float 360 | |
back 10 | |
if (pcolor = black) | |
[ stop ] ;; exit this procedure if not on a pile | |
get-away | |
end | |
to wiggle | |
fd 1 | |
rt (random-float 50 - random-float 50) | |
end | |
; Copyright 1997 Uri Wilensky. | |
; See Info tab for full copyright and license. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment