Skip to content
Snippets Groups Projects
Commit 820d7a7d authored by xo30xoqa's avatar xo30xoqa
Browse files

Gave the Wolpertinger something to do...

parent c9136d3f
Branches
Tags
No related merge requests found
......@@ -49,7 +49,7 @@ optional arguments:
name of the map file
-o, --outdir OUTDIR location of the output directory
-l, --loglevel LOGLEVEL
verbosity: "debug", "info", or "errors"
verbosity: "debug", "info", or "quiet"
-r, --runtime RUNTIME
duration in days that the simulation will run
(type: Int64)
......
......@@ -107,7 +107,7 @@ function parsecommandline()
arg_type = String
required = false
"--loglevel", "-l"
help = "verbosity: \"debug\", \"info\", or \"errors\""
help = "verbosity: \"debug\", \"info\", or \"quiet\""
arg_type = String
required = false
"--runtime", "-r"
......@@ -122,13 +122,3 @@ function parsecommandline()
args
end
"""
readtiffmapfile(filename)
Read in a TIFF map file and return it as an array.
"""
function readtiffmapfile(filename)
tiff = GeoArrays.read(filename)
space = GridSpace(size(tiff)[1:2], periodic=false)
#TODO this requires GeoArrays
end
......@@ -11,8 +11,10 @@ and instantiate the AgentBasedModel object.
"""
function initialise(config::String=PARAMFILE)
initsettings(config)
Random.seed!(param("core.seed"))
setupdatadir()
landcover = GeoArrays.read(param("core.mapfile"))
#TODO load field map
space = GridSpace(size(landcover)[1:2], periodic=false)
properties = Dict{Symbol,Any}(:day=>0,
:landcover=>landcover)
......@@ -25,7 +27,6 @@ function initialise(config::String=PARAMFILE)
model
end
"""
stepsimulation!(model)
......@@ -40,19 +41,17 @@ function stepsimulation!(model::AgentBasedModel)
#TODO
end
"""
finalise(model)
Wrap up the simulation. Output all remaining data and exit.
"""
function finalise(model::AgentBasedModel)
@info "Simulation ran. Nothing happened. But it will!"
@info "Simulation ran. Things are beginning to happen!"
#TODO
genocide!(model)
end
"""
simulate(config)
......
......@@ -13,8 +13,8 @@ initialise their population and update each individual.
"""
struct Species
name::String
initpop::Function # takes one argument: model
update::Function # takes two arguments: animal, model
initpop!::Function # takes one argument: model
update!::Function # takes two arguments: animal, model
end
"""
......@@ -31,6 +31,7 @@ by the `species` struct passed by them during initialisation.
energy::Int32
end
# This dict stores the definitions for all species that can be simulated
let specieslist = Dict{String, Species}()
"""
registerspecies(species)
......@@ -59,8 +60,9 @@ Update an animal by one day.
"""
function stepagent!(animal::Animal, model::AgentBasedModel)
animal.age += 1
animal.species.update(animal,model)
animal.species.update!(animal,model)
if animal.energy <= 0
@debug "$(animal.species.name) $(animal.id) has died."
kill_agent!(animal, model)
end
end
......@@ -71,8 +73,9 @@ end
Initialise the model with all simulated animal populations.
"""
function initnature!(model::AgentBasedModel)
#The config file determines which species are simulated in this run
for s in param("nature.targetspecies")
getspecies(s).initpop(model)
getspecies(s).initpop!(model)
end
end
......@@ -2,7 +2,7 @@
###
### 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 rather endangered...
### Although I dare say the Wolpertinger is probably rather endangered...
###
"""
......@@ -12,8 +12,8 @@ Initialise a population of Wolpertingers in random locations around the landscap
"""
function initwolpertinger!(model::AgentBasedModel)
species = getspecies("Wolpertinger")
worldsize = size(model.landcover)[1:2]
popsize = round(worldsize[1]*worldsize[2]/1000)
x, y = size(model.landcover)
popsize = Int(round((x*y)/10000))
for i in 1:popsize
add_agent!(Animal, model, species, hermaphrodite, 0, 100)
end
......@@ -27,8 +27,15 @@ Wolpertingers are rather stupid creatures, all they do is move around randomly
and occasionally reproduce by spontaneous parthogenesis...
"""
function updatewolpertinger!(w::Animal, model::AgentBasedModel)
#TODO
@debug "The Wolpertinger is a mysterious animal..." w.id
# 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!))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment