Here is the problem:
I need to compare a value inside turtles-own
, which is best-food
, with the other agents in the same agentset but I don't know how to make the agent ask his teammates about this value and I need them to compare with each other' best-food value constantly throughout the simulation. (so that they can obtain the highest value of food)
if it is in Java, it is something like this=
if agent1.best-food > agent2.best-food
then agent1 go to agent2
but in netlogo, I can't do it like this. can someone help me?
here is the code:
food_quality
= food agent found on World
food_quality_found
= the value of food_quality is kept in turtles-own
best-food
= each agent save their food-quality-found in best-food; then all agents compare which one has the highest value and this comparison happen in an agentset.
ask myteamset [
set food-quality-found food-quality
set best-food food-quality-found
set location patch-here
set loca-best-food location]
ask myteamset[
if best-food != 0 ; I need them to compare constantly so "!=0" need to be substitute with his teammates' best-food, but I don't know how to ask other teammates in same agentset about this value
[
if (best-food < food-quality-found) ;to make sure best-food always have the highest value.
[set best-food food-quality-found
set location patch-here
set loca-best-food location]
if best-food > best-food ;
this is not correct logically because all of them compare their own best-food value, but I have no idea on how to ask other turtles their best-food and compare it with mine.. [
set g random 100
if (g >= probability_teammates_to_go)
[ move-to loca-best-food]]
if (patch-here is loca-best-food) ;how to write if with patches?
[set i random 100
if (i >= probability_to_ignore) ;after agent arrives at best-food, they still need to choose whether or not they want to stay there.
[ fd 0.25 ]
I have tried let best-food-turtle (turtles with-max [food-quality-found])
but it doesn't compare the value with all his teammates, rather just to this one specific agent, which is wrong...
Thank you in advance.