I am building a model for a predator prey system and I am incorporating a small basic machine learning internal model in the predator.
Predators have 4 strategies (strat is the variable), at the start of the day they select a strat and at the end of each day they check if they had a successful hunt with that strat.
I have another variable that predators own called best-strat which I want to be copied from the last successful strat
my code is the following
to recall-hunts
if ticks = 98 [ifelse hunt-today = 1 [set last-hunt "success"] [set last-hunt "failure"]]
end
to evaluate-hunt
if ticks = 99 [if last-hunt = "success" [set best-strat best-strat = strat]
if last-hunt != "success" [set strat one-of strategies]
stop]
end
to strategy
if ticks = 1 [ifelse best-strat = "NA" [set strat one-of strategies] [set strat strat = best-strat]]
stop
end
I want the predator to evaluate if they had a good hunt with a given strat and then select the strat which worked best for them previously, if no best strat then simply pick a random one.
strat is a variable which selects from the strategies list ("strat1" "strat2" "strat3" "strat4")
every thing is working except my code to copy the current strat into best-strat at the end of the day if a hunt was successful. At the moment it sets to "false" so something is breaking i guess.