0
votes

I'm new in NetLogo and this may be a too obvious question, but I don't see how to test if what I am doing is right.

I'm making a selection of an agent of breed1 (turtles) based on its distance to breed2 (crocodiles). I would like the crocodile to choose one turtle randomly from the ones around it, but with a higher probability to be chosen the closer the turtle is. Thus, I am using rnd extension and distance command.

My question is if the distance command is referring to the right agent (i.e. distance between the crocodile and the turtles):

ask crocodiles [
   let potential_preys turtles in-radius max_distance
   let selected_prey rnd:weighted-one-of potential_preys [ (1 - ( distance ? / max_distance ) ) ]        
   ask selected_prey [    
     scape
   ]
]
2

2 Answers

1
votes

Before I get to your question, there is another problem I noticed with your code.

I had never realized this before, but NetLogo's semantics can make it tricky to model actual turtles! (At least when other breeds are involved.)

What I mean by this is that turtles refer to all turtles in the model, regardless of their breed. It means that, in your case, crocodiles are included in turtles, so when you say:

let potential_preys turtles in-radius max_distance

...crocodiles can be included in the potential preys!

Getting around this is easy enough, though: just choose another name for the breed that represent actual turtles in your model, e.g.:

breed [ tortoises tortoise ]

And then you can write:

let potential_preys tortoises in-radius max_distance

And now, for your question regarding distance, I think what you want is the distance to myself, where myself would be the crocodile that is selecting its prey. The myself primitive refers to the agent in the "outer" context of the block where you use it, i.e., the "calling" agent.

This gives you something like:

let selected_prey rnd:weighted-one-of potential_preys [
  1 - (distance myself / max_distance)
]
0
votes

Haha, I didn't thought about the turtles detail, indeed... ^^ Anyway it was an example, not the actual name of my breeds, so no problem, but thanks for noticing it!

Regarding the question itself, I also think myself will do, so I'll keep it like this, but now with higher confidence :D

Thanks Nicolas!