Reputation: 197
I want to implement a scenario that all agents in NetLogo simulation should report the number of agent in their neighbour upto 3 patches in radius. And then top 3 of them having largest number of agents in its radius should 'set is-leader? true ' . As i am using ' turtles-own [ is-leader? ] ' .
to setup
ca
ask n-of 30 patches [sprout 1 [
set size .8
]
]
end
to go
fd 0.5
lt random 20
choose-leader
end
to choose-leader
end
Upvotes: 0
Views: 88
Reputation: 1113
try like this:
turtles have variable "is-leader?" set to false.
turtles at each tick move in the random way you decided, then set their "is-leader?" variable to false
the procedure choose-leader is executed. It chooses the 3 turtles with the higher number of neighbors in radius 3 and set their "is-leader?" to true.
code:
turtles-own[
is-leader?
]
to setup
ca
ask n-of 30 patches [sprout 1 [set size .8 set is-leader? false]]
end
to go
ask turtles[
fd 0.5
lt random 20
set is-leader? false
]
choose-leader
end
to choose-leader
ask max-n-of 3 turtles [count turtles in-radius 3] [set is-leader? true]
end
Upvotes: 2