Is it possible to use "min-one-of" and "in-cone"/"in-radius" in the same let procedure?

26 Views Asked by At

In my model, I'm trying to make one turtle (bat) move to another type of turtle (bugs) by searching within a radius first. I want the bat to be able to scan its radius (vision) and then detect the closest bug within this area, and then move towards it.

I've tried this code below (with vision-radius and vision-angle being sliders):

let prey min-one-of bugs in-cone vision-radius vision-angle
  ask bats [move-to prey]

However, min-one-of returns an error saying that it needs an agentset and a number block to work. So then have tried the following code:

let prey min-one-of bugs [in-cone vision-radius vision-angle]
  ask bats [move-to prey]

This code returns an error, due to "in-cone" needing to have an input on the left, which is bugs.

I didn't know if it was possible to use min-one-of and in-radius/in-cone together or if there is another way to create this procedure?

1

There are 1 best solutions below

0
lmf0845 On

min-one-of returns an error because it is missing the reporter. in-cone vision-radius vision-angle creates the agentset the minimum should be reported for. min-one-of additionally needs a reporter as it is not specific to the distance. it could report the agent with the minimum of any reporter, e.g. xcor. To have the nearest agent you need to create the reporter for the distance -> [distance myself].

You will also have to check that prey will not be empty.

Here is the code that should solve what you were looking for

to hunt
  ask bats [
    let prey min-one-of bugs in-cone vision-radius vision-angle [distance myself]
    if prey != nobody [move-to prey]
  ]
end