Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetLogo get the breed of a turtle

Tags:

netlogo

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?

like image 366
user3005072 Avatar asked Jun 20 '14 19:06

user3005072


People also ask

How do I change the breed in NetLogo?

Example: breed [cats cat] breed [dogs dog] ;; turtle code: if breed = cats [ show "meow!" ] set breed dogs show "woof!"

Is NetLogo a breed?

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.


1 Answers

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".)

like image 116
Nicolas Payette Avatar answered Oct 12 '22 01:10

Nicolas Payette