This demo by Lutz Rosema is a fun cellular autonoma (Game of Life) style simulation featuring three different types of “cell”: wolves, sheep, and grass. The rules of the demo are pretty simple:
- a blank cell which is adjacent to grass will be replaced by grass
- a grass cell which is adjacent to a sheep will be replaced by a sheep
- a sheep cell which is adjacent to a wolf will be replaced by a wolf
- if a sheep has no grass adjacent, it will be replaced by a blank cell
- if a wolf has no sheep adjacent, it will be replaced by a blank cell
- if a wolf has a shepherd adjacent, it will be replaced by a blank cell
Lutz is modifying each of these rules with probability variables: each event does not have a 100% chance of occurring, which adds some nice complexity.
The demo is based on an old BASIC program (which makes it that much cooler in my book). Try tweaking the variables at the top of the JS to modify the probability of each event happening. I personally liked setting grass high (0.875), sheep medium-low (0.25), and wolf low (0.125).
The code is pretty heavily optimized, so it might be tough to learn from… but the rules are simple enough you could try to build a version of your own.