Here is what I want to do:
I want a team consists of 3 turtles in a group.
All turtles need to store their own ID and teammatesID inside the variable called teammatesID. (Imagine you want to create a group, you will put your name and your friends' name in a list, that's why this variable need to store ownID, I am bad in explaning things..)
Instead of just showing
(agentset,3 turtles)
, I need them to be able to show all teammates ID.After they have gathered all 3 members, they will get
teamID
.
The problem here is I don't know how to make these turtles store their own ID and teammatesID in variable called teammatesID. In a group, they supposed to have 3 different members. These teammates are not supposed to be from the same group. And how to give them teamID
after
they get all members.
Here is my coding:
global
[ teamID]
turtles-own
[
myID
teammatesID
]
to setup
clear-all
set-default-shape turtles "arrow"
create-turtles 10
ask turtles [ set myID who]
reset-ticks
setup-group
end
to setup-group
set teamID []
let agent one-of other turtles
let nearestNeighbor one-of other turtles in-radius 1
set teamID = 0
ask agent with [ teammatesID < 3]
[ ask nearestNeighbor with [teammatesID < 3]
[ ;set teammatesID = myID ; here is the problem, I need to make sure they did not save the same turtle in one group.
show teammatesID]]
ask agent with [teammatesID > 3]
set teamID fput teamID teamID
end
I appreciate your extra time here. Thank you.
If teams are random, I don't think you need a loop for this as
ask
will call the turtles in a random order anyway.I think you should still make use of agentsets here as it makes certain things easier. For example, once turtles know their
(agentset,3 turtles)
, you can easily query that agentset for themyID
s or whatever variable you're after.I'm not entirely clear on the purpose of
teamID
so I may be off base here, but I don't think you want it as a global variable if theteamID
s are to be unique to each group of three turtles. You'll probably want it to be aturtles-own
variable as well.Here is an example that incorporates the above ideas. With this setup:
And the
setup-groups
procedure (more detail in comments):Let me know if that's kind of what you're after, hope it helps.
Edit- As per your comments:
To get sequential team numbers, you can make use of a simple counter that gets assigned to a team and then incremented for the next one- modified
setup-groups
would look like:The second question may be worth a new question on its own, depending on how in depth you're hoping to get, but here is one very simplistic approach where you just get all unique team IDs and have one turtle with that ID have their team move together:
Edit 2: NetLogo 5-friendly version