Wolves, Sheep, and Grass

wolf-sheep-grass

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:

  1. a blank cell which is adjacent to grass will be replaced by grass
  2. a grass cell which is adjacent to a sheep will be replaced by a sheep
  3. a sheep cell which is adjacent to a wolf will be replaced by a wolf
  4. if a sheep has no grass adjacent, it will be replaced by a blank cell
  5. if a wolf has no sheep adjacent, it will be replaced by a blank cell
  6. 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.

See the Pen Game of wolves, sheeps and grass by Lutz Rosema (@terabaud) on CodePen.

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.

Rob

Rob has been building websites for more than half of his life. You'd think that'd make all this less interesting, but nope! There's a lot of awesome stuff going on webwards, and canvas is definitely one of them.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *