EcosystemCore.mates(::Animal{S,Female}, ::Animal{S,Male}) where S<:Species = true
EcosystemCore.mates(::Animal{S,Male}, ::Animal{S,Female}) where S<:Species = true
EcosystemCore.mates(::Agent, ::Agent) = false
########## Additional functionality ##########################################
function simulate!(world::World, iters::Int; cb=()->())
for i in 1:iters
world_step!(world)
cb()
end
end
agent_count(p::Plant) = size(p)/EcosystemCore.max_size(p)
agent_count(::Animal) = 1
agent_count(as::Vector{<:Agent}) = sum(agent_count,as)
function agent_count(w::World)
function op(d::Dict,a::Agent{S}) where S<:Species
n = nameof(S)
if n in keys(d)
d[n] += agent_count(a)
else
d[n] = agent_count(a)
end
return d
end
foldl(op, w.agents |> values |> collect, init=Dict{Symbol,Real}())
end
function every_nth(f::Function, n::Int)
i = 1
function callback(args...)
# display(i) # comment this out to see out the counter increases
if i == n
f(args...)
i = 1
else
i += 1
end
end
end
Lab 02
Improvement suggestions from last year
Lab 03
⚥Sheep
forward method including overloading ofgetproperty
(andsetproperty!
) for⚥Sheep
:Improvement suggestions from last year
filter
is both slow and not super straight forward in this case. We could remove hint 1 and expand on hint 2. https://github.com/JuliaTeachingCTU/Scientific-Programming-in-Julia/blob/c77e2a58969a9350d6b2df4cc88aa432fa3d188e/docs/src/lecture_02/lab.md#L372-L377