Something went wrong on our end
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
wolpertinger.jl 1.46 KiB
### Persephone - a socio-economic-ecological model of European agricultural landscapes.
###
### This file holds the code for the Wolpertinger (https://en.wikipedia.org/wiki/Wolpertinger).
### NOT FOR ACTUAL USE! This is of course only a test species ;-)
### Although I dare say the Wolpertinger is probably rather endangered...
###
"""
initwolpertinger!(model)
Initialise a population of Wolpertingers in random locations around the landscape.
"""
function initwolpertinger!(model::AgentBasedModel)
species = getspecies("Wolpertinger")
x, y = size(model.landscape)
popsize = Int(round((x*y)/10000))
for i in 1:popsize
add_agent!(Animal, model, species, hermaphrodite, 0, 100)
end
@debug "Hid $(popsize) Wolpertingers for gullible tourists to find."
end
"""
updatewolpertinger(animal, model)
Wolpertingers are rather stupid creatures, all they do is move around randomly
and occasionally reproduce by spontaneous parthogenesis...
"""
function updatewolpertinger!(w::Animal, model::AgentBasedModel)
# walk in a random direction
direction = Tuple(rand([-1,1], 2))
walk!(w, direction, model; ifempty=false)
w.energy -= rand([1, 10])*5
# reproduce every once in a blue moon
if rand() < 0.01
@debug "Wolpertinger $(w.id) has reproduced."
add_agent!(w.pos, Animal, model, getspecies("Wolpertinger"), hermaphrodite, 0, 100)
end
end
registerspecies(Species("Wolpertinger", initwolpertinger!, updatewolpertinger!))