Agent interaction and maintaining lists of agents #31
-
Hi, I am trying to teach myself AgentPy by rebuilding the classic Wolf-Sheep predation model. So far it is going pretty well, but I had a couple questions about how I had implemented agent storage in the landscape, and agent interaction. My code is below (I removed some of the lines for brevity but all relevant code is shown), and my questions are:
In the method for wolves eating sheep, I have:
Thanks in advance for any advice! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, sorry for the late answer! I would try to create two seperate landscapes Lists like
(The comma in If you are interested, we could add the finished model to the agentpy model library! |
Beta Was this translation helpful? Give feedback.
Hi, sorry for the late answer!
I would try to create two seperate landscapes
landscape_sheep
andlandscape_wolfs
.Having a grid with mixed agents is only useful if you want to query mixed lists.
Lists like
current_sheep
would then simply belandscape_sheep.agents
.In
eat_sheep()
you can then identify sheep on the same position as follows:(The comma in
prey, = poss_prey.random()
achieves the same as.to_list()[0]
)If you are interested, we could add the finished model to the agentpy model library!