'Netlogo: update a list after each movement
I need help with the following problem. I have turtles located in 3 different zones A, B, C. They have some properties
turtle-own[place-to-go]
patch-own[n-of-empty-places]
Turtles move to one patch selecting the larger number from a list of place-to-go [n-of-empty-places in A n-of-empty-places in B n-of-empty-places in C].
What I would like to know is how to update the n-of-empty-places after each movement. For example, if the first turtle heads to area A, since n-of-empty-patches in A is the largest number in the list, the second turtle will select from a list that is [n-of-empty-patches in A -1 n-of-empty-patches in B n-of-empty-patches in C].
Any help?
Solution 1:[1]
I see you are trying to use a list to store numbers of vacancies of all zones. As a side note, an alternative would be to use 3 numeric variables instead of the list. Anyway, what you should note is that the list you described is not a patches-own variable. Rather, it is a global variable, because it is accessible to all entities everywhere.
Here is a suggestion:
globals [n-of-empty-places]
We assume n-of-empty-places
to be a list with 3 items associated with zones A, B and C, respectively.
patches-own [zone]
We assume that the zone of each patch is assigned in the code to be one of "A", "B" or "C".
Then in the main function of the code we can ask a recently moved turtle to update the global variable n-of-empty-places
according to the zone of its new patch. Suppose this turtle is called turtle-x
. Note that we can ask a turtle to tell us the properties of the patch it is standing on. Also suppose the auxiliary variable zone-index
has been declared before:
ask turtle-x [
set zone-index position zone ["A" "B" "C"]
set n-of-empty-places replace-item zone-index n-of-empty places (item zone-index n-of-empty-places - 1)
]
I suggest you look up item
, replace-item
and position
in NetLogo dictionary (http://ccl.northwestern.edu/netlogo/docs/index2.html).
Good luck
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Saeed |