breed [dogs dog] breed [cats cat] globals  turtles-own [ sex age ] dogs-own [ has-ball? ] cats-own [ has-scratching-post? claw-length ]
to go tick ask turtles [ set age age + 1 ] ask dogs [ if has-ball? [ fetch ] ] ask cats [ if has-scratching-post? [ scratch ] ] ask turtles [ ; this will make an error if has-scratching-post? [ scratch ] ] end
Good idea: Check that the right breed is calling the function:
to do-cat-stuff if not is-cat? self [ print (word "Error: turtle " self " is not a cat.") stop ] if has-scratching-post? [ scratch ] end
Or, if you’re using
jg-tif.nls, you can do this:
to do-cat-stuff test-that (word "do-cat-stuff: turtle " self " should be a cat.") expect-that is-cat? self is-true if has-scratching-post? [ scratch ] end
If you have breeds, there will still always be
ask turtles [...] will ask all breeds of turtle.
ask dogs [...] will only ask the dogs.
turtles- commands have a breed-specific version:
if any? turtles-here [ ask turtles-here [forward 10] ] if any? dogs-on neighbors and any? cats in-radius 5 [ ask dogs-on neighbors [ chase min-one-of cats [distance myself] ] ]
You can change the breed of a turtle or link with
ask one-of cats [ set breed dog ] ask one-of friendships [ set undirected-link-breed enmities ]
You can specify the default shape of new individuals of a breed (doesn’t affect any already created)
set-default-shape turtles "circle" create-cats 1 ; default turtle shape set-default-shape cats "cat" set-sefault-shape dogs "dog" create-cats 1 ; has "cat" shape ask one-of cats [ set breed dogs ] ; cat becomes a dog and changes shape to "dog"
Note: some shapes, like “cat” and “dog” must be imported into the model from the shapes library, using the shapes editor
|Subordinate or alpha||20%|
Frequency of breeding depends on ratio of population to carrying capacity:
When population is 100% of carrying capacity, probability of breeding is 10%
to go if ticks >= years-to-simulate or not any? dogs [ if ticks < years-to-simulate [ set time-to-extinction ticks set extinct? true ] stop ] step ; "step" does all the work of mating, aging, dispersing, dying, etc. end to get-p-extinct [ n-runs ] let n-extinct 0 repeat n-runs [ setup while [ticks < years-to-simulate and not extinct?] [ go ] if extinct? [ set n-extinct n-extinct + 1 ] ] set p-extinction n-extinct / n-runs end