Tutorial:  Moving

 Moving

Ants in this simulation do not know where they are exactly.
They only know what they see and smell. All other objects are unknown.

Each ant though can turn around and walk to perceive more of its surroundings. The direction and rotation are both relative to the ants current location and rotation.

Move command

The command looks like this:

[ActionType.MOVE, DirectionType.<direction>, <rotation>];

The parameter can be FORWARD, BACKWARD or NONE.
Keep in mind: Ants can't move backwards as fast as they move forwards.

Rotations are always given in degree relative to the ants current heading. If you like to use radians just convert it with

var degree = radToDeg( radians )

Examples:

[ActionType.MOVE, DirectionType.NONE, 25];        // rotate 25° to the left
[ActionType.MOVE, DirectionType.FORWARD, radToDeg(-0.7854)];    // rotate 45° to the right
[ActionType.MOVE, DirectionType.BACKWARD, rand(-30, 30)]; // walk backward with a random rotation (-30°,30°)

Rotation towards objects

By moving around the ants perception of the world changes. Distance and rotation to other objects are updated each iteration.

The rotation angle towards something can be returned by

var nearestFood = this.getNearestObjectType(ObjectType.FOOD);
var rotationTowardsFood = nearestFood.getRotationToObj();

Try it yourself!

A little hands on:
By default the ant walks randomly around. Try to let the ant walk towards the green food source!