i am trying to randomly pick 2 turtles of the same breed - but i´m struggling with how to do it. I have 10 different breeds. My code should first randomly pick a turtle of any breed and then pick randomly one of the same breed than the first one. But i really don´t know how to do it. Can anybody tell me how to do this? From other programming languages i´d expect, that i can store a turtle object in a variable (which works)
let source one-of turtles
and then somehow get the breed as an attribute of my source
turtle like this (whick doesn´t work)
let source-breed source.getBreed
Can anybody help me please?
Example: breed [cats cat] breed [dogs dog] ;; turtle code: if breed = cats [ show "meow!" ] set breed dogs show "woof!"
breed is a special primitive that can only be placed in the top of a netlogo code tab. Using breed , you can define custom kinds or breeds of turtles.
As you can see in NetLogo's documentation, each turtle has a breed
variable that references the agent set containing all turtles of that breed. You can use of
to access a turtle variable, or refer to it in the context of an ask
block.
Here is an example:
breed [ mice mouse ]
breed [ cats cat ]
breed [ dogs dog ]
to go
clear-all
create-mice 10
create-cats 10
create-dogs 10
let source one-of turtles
show word "We picked: " source
show word "The source breed is: " [ breed ] of source
ask source [
let other-turtle one-of other breed
show word "Here is another turtle of the same breed: " other-turtle
]
end
Note the use of other
in the expression one-of other breed
, which means "one other turtle of my breed" (not "a turtle of another breed".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With