1
votes

I'm trying to do the following in netlogo: I have four agents in netlogo with a random heading and a variable (random 1-99). The agents search the closest agent with "let nearest-turtle min-one-of other turtles [ distance myself ]"

The agent with the highest variable (for example 90 versus 10) will calculate the difference between the variables (for example 90-10 =80). This difference is used as a probability with the statement "random 100 < 80". When the random number is lower than the difference, the agent with the highest value will force his heading on the turtle with the lower value. My problem is that when the agent with the highest value loses the die, he has to copy the heading of the agent with the lower value. I don't know how to do this: "myself" does not work. I'm stuck.

1
I think you need to show more code. - Dave Schweisguth

1 Answers

1
votes

It's hard without seeing your code, but this is a complete working example based on your code. It works and does not throw errors.

globals [larger smaller]
turtles-own [num]

to test
  create-turtles 50
  [ setxy random-xcor random-ycor
    set num random 100
  ]

  ask turtles
  [ let nearest-turtle min-one-of other turtles [ distance myself ]
    let closed-agent-num [num] of nearest-turtle
    ifelse [num] of nearest-turtle > num
      [ set larger nearest-turtle
        set smaller self ]
      [ set smaller nearest-turtle
        set larger self]
    ifelse random 100 < [num] of larger - [num] of smaller
      [ ask smaller [ set heading [heading] of larger] ]
      [ ask larger [ set heading [heading] of smaller] ]
  ]
end

I suspect there are much better ways using tricky referencing, but this is relatively easy to read.