Tutorial:  Harvest

 Harvest

For the queen to thrive and increase their ant numbers she need food. If a certain amount of food is harvested and brought to the hive, a new ant is born.

Harvest command

The command looks like this:

[ActionType.HARVEST, <object>];

// examples:
[ActionType.HARVEST, food];        // harvest food from food source
[ActionType.HARVEST, dead_spider]; // harvest food from a dead spider
[ActionType.HARVEST, dead_ant];    // cannibalism

Note: Normally ants don't cannibalise other ants. In this simulation though, it's a fight for survival!

Memory:

Ants can memorize everything they experience.
Finding a straight way back home for example is achieved by memorizing direction (position of the sun) and walking distance.
In this simulation though an ant can memorize everything you want with

this.memory.<some topic> = <value>;

// examples:
this.memory.carryingFoodHome = true; // Ant wants to bring food home
this.memory.totalFoodCarried = 200; // Ant counts how many food was carried
this.memory.distanceToHive = 10; // Ant tracks distace to hive

Try it yourself!

A little hands on:
By default the ant walks towards the food location. This resembles one possible solution to the previous tutorial.
Try now to enhance the code to let the ant walk back with full hands!