Reputation: 73
I'm working on a Predator-Prey model but I have a unique spawning mechanic that I'm trying to work in.
The idea is that when a wolf encounters sheep, there is a probability of the sheep escaping (I already have this part coded in). If the sheep is killed, n number of lambs are created. If the sheep escapes, k number of lambs are created. After t periods, the lambs become prey. n, k, and t will all be sliders on the interface side.
I'm pretty new to agent-based modeling and Netlogo coding, so any advice would be really appreciated.
This is the current code for the hunting:
to catch-sheep ;; wolf procedure
let prey one-of sheep-here
if prey != nobody and random 100 < kill-probability
[ ask prey [ die ]
Upvotes: 1
Views: 97
Reputation: 1295
Using your code to add some code and see if that works for you.
When a sheeps is killed create a random number of new sheeps, in the code below use your slide variable instead of 10.
I use the primitive function hatch to do all the work.
to catch-sheep ;; wolf procedure
let prey one-of sheep-here
if prey != nobody and random 100 < kill-probability
[ ask prey [ die ]
;;Here we create new sheeps upon prey death
let rd-num random 10 ;; 1 to 10 sheeps will appear
hatch-sheep rd-num [ set color blue
set xcor 9 ;; Initialize your new sheeps ]
]
Let us know of any questions you might have! Happy coding.
Upvotes: 0
Reputation: 9620
Presumably k>n, so you can have all adult sheep hatch
n lambs, and then catch-sheep
, and then have all remaining adult sheep hatch k-n lambs. This requires distinguishing between lambs and adults, so you may want to add an age
attribute.
However, I suspect you will want to switch to probabilities of hatching a lamb each tick, rather than a number of lambs hatched each tick.
Upvotes: 0