Introducing randomness


This release introduces randomness for choices where an animal has multiple valid targets. In the previous deterministic world, anminals would always choose the first valid target, leading to behavior like foxes always gravitating to the top-right corner and starving there despite an abundance of rabbits on the map. Now that foxes move randomly, they quickly kill all the rabbits and then die of hunger.

This required changing up the architecture a bit. I've tried to keep all the actual game logic separate from dealing with randomness as much as possible. For example, moving to a given location and moving to a random location are separate functions that build on each other.

While almost every random operation is described in terms of generators, I've opted to manually step the generators at the top level when iterating through the grid. This is so that all the randomness remains synchronous since each step depends on the result of the previous. While I could have chained them all with andThen, there is a limit to that after which it will trigger a stack overflow (see https://thoughtbot.com/blog/elm-debugging-story). While the grid currently only has 100 cells, growing the grid rapidly increases the number of cells.

I've hardcoded the initial seed of the program as 1, however that doesn't mean that every program plays out the same. This is because I'm independently generating the initial graph (as a command), so all of my repeatable random functions have a different starting point. Therefore I effectively have a random starting seed.

Files

ecosystem-html5.zip Play in browser
Version 0.3.0 Jul 04, 2020

Leave a comment

Log in with itch.io to leave a comment.