CS108L Spring 2014 Week 7: Sample Program 1: Saving Nemo Model ;; Saving Nemo ;; November 17 2013 ;; ;; Notes: ;; 1. Deep blue is 102 ;; 2. Setting the values for energy loss and gain can be confusing. Make sure that the students do not set the initial energy ;; to greatter than the reproduction energy! ;; 3. Have the students save the model frequently because if the program gets stuck, you may have to clode NetLogo. NetLogo ;; DOES NOT autosave and there is a likelyhood that the program will run amok ;; 4. Need to have Reset-ticks at the end of the setup procedure and tick at the end of the go procedure ;; 5. Turning patches green during the go procedure should happen rarely (I used 1 in 1000 probability) breed [fishes fish] ;; creating the fish breed fishes-own [Fenergy] ;; creating the fish variable for energy Document1 globals [emptyWaterColor] ;; not required you can use the color number in each set pcolor command below to setup clear-all set emptyWaterColor 102 ;; 102 is deep blue - you can just use the number later if you want create-fishes numfish_atStart ;; creates the inital number of fish with the required properties [ set color red set size 4 setxy random-xcor random-ycor set Fenergy 10 set shape "fish" ] ask patches ;; creates your water world with plankton [ ifelse random 100 < 1 [ set pcolor green ] [ set pcolor emptyWaterColor ;; can use the color number for deep blue, 102 ] ] reset-ticks ;; NEED for plotting end to go ask fishes [ FishWiggle FishEat FishDie FishHatch ] ask patches ;; create plankton rarely [ if pcolor = emptyWaterColor ;; can use the color number for deep blue, 102 [ if random 1000 < 1 [ set pcolor green ] Document1 ] ] tick end to FishWiggle ;; fish wiggle to move and loose energy while they do that right random 45 left random 45 forward 1 set Fenergy Fenergy - 0.1 end to FishEat ;; Fish gain energy by eating plankton if pcolor = green [ set Fenergy Fenergy + 1 set pcolor emptyWaterColor ;; can use the color number for deep blue, 102 ] end to FishHatch ;; fish have babies if their energy reaches a certain value and loose energy if they do if Fenergy > 15 [ set Fenergy Fenergy - 3 hatch 1 [ set Fenergy 10 forward 3 ] ] end to FishDie ;; fish die if they have no energy if Fenergy <= 0 [ die ] end Document1
© Copyright 2026 Paperzz