Sugarscape with Canvas

Below is an implementation of the Sugarscape simulation I made using the HTML canvas. It shows a 50x50 grid with each square containing between 0 and 4 units of sugar represented with different intensities of green. There is an initial population of 200 agents (red circles) which move about and eat the sugar.

In each tick of the simulation, agents look around (1-6 squares depending on their eyesight) to see whether there is a square with more sugar than their current one. If there is they move to it and regardless, they harvest all the sugar where they are now standing. They then eat 1-4 units of sugar depending on their metabolic rate. The sugar then regrows at a rate determined below. If an agent tries to eat more sugar than it owns it dies and is replaced by a new agent in a random position.

Sugar regrowth rate:

With a sugar regrowth rate of 1, you should find that most agents move about. The only agents that stay where they are are those in the lightest green areas with only 1 sugar unit, whose vision is limited such that they cannot see a better area (so all agents must be at least 1 square away from a darker green). These agents must also have a metabolism of 1 otherwise they will soon starve.

Agents in more fertile regions will harvest more than 1 unit of sugar each turn so their squares are likely to contain less sugar than nearby squares and the agents will thus keep moving. As you increase the regrowth rate, regions with higher fertility will be completely replenished each turn, so more agents will settle. With a regrowth rate of 4, all agents should settle quite quickly.

Post new comment

The content of this field is kept private and will not be shown publicly.