You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press

A More Lifelike Simulation

To make life in the terrarium more interesting, we will add to it the concepts of food and reproduction. Each living thing in the terrarium gets a new property, energy, which is reduced by performing actions and increased by eating things. When it has enough energy, a thing can reproduce, generating a new creature of the same kind. To keep things reasonably simple, the creatures in our terrarium reproduce asexually, all by themselves.

If there are only bugs, wasting energy by moving around and eating each other, a terrarium will soon succumb to the forces of entropy, run out of energy, and become a lifeless wasteland. To prevent this from happening (too quickly, at least), we add lichen to the terrarium. Lichen do not ...

The best content for your career. Discover unlimited learning on demand for around $1/day.