I am writing a predator-prey simulator (for no good reason) and I have hit the wall with functional design. The simulator is that of a grid on which the fish and the sharks go about their business, the fish moves, grows and procreates and so do the sharks. The sharks also hunt and eat the fish. The time is discrete (in chronons) so it is a discrete-time multi-agent simulation. I currently have three data types -- World, Fish, and Shark.
The simple way to make the World go round is described in the book as following (in my own words).
Each turn, iterate over the list of agents and apply sense/act function which in turn will return a revised world, something like let world' = List.fold (World.fish world) ~init:world ~f:Fish.act
. I have attached my code which (almost) implements this strategy for Fish in a somewhat ugly way.
This approach to allocating resources is biased, because the first fish in the list has more choices than the second by virt