Starting an ant colony

The ants move randomly, leaving a trail of pheromones.

I have started to remake a simulation of an ant colony that I once made in QBASIC. The idea (which I am by no measure, the first to contemplate) is to create an ant colony that can harvest surrounding food (seeds or leaves – the green ovals in the picture) in an intelligent manner, despite the individual ants having very limited intelligence or information to work with.

The ants (black circles in the picture above – I could replace them with more realistic images, but it’s probably not worth it) can be considered simple information processors (Hofstadter made the analogy between ants in a colony and neurons in a brain). In the simulation they are blind, and can only sense food and pheromones. They are capable of a limited repertoire of actions, such as moving forward, turning, picking up food and releasing a pheromone (the blue squares in the picture below). So far in my simulation, the ants leave the nest (the odd looking black circle with a halo, and the reason I got sidetracked into evolving images of Darwin – I know it looks rubbish), in a random direction. At each unit of time, there is a 10% chance of an ant altering its direction (somewhere between -45 and 45 degrees), otherwise it moves releases a pheromone and moves forwards; over time the pheromone degrades.

The next step will be to allow the ants to change their behaviour when they detect a pheromone. For example, if we want ants to explore new areas, we could make them avoid areas of high pheromone, since those areas will have been covered by ants before. If we want the ant to return to its nest (e.g. if it is holding a seed), then we could make it prefer areas of high pheromone. By introducing a second pheromone, released when ants are carrying food, information about where food is can be passed to other ants, perhaps allowing the colony to efficiency direct its efforts to collecting food. Later, I would like to add moveable and immovable obstacles to get in the ants way.

This simulation is the first time I’ve really made use of Pygame’s sprite objects. I’m not sure whether made full use of the object's functionality, but I have found that it make detecting collisions between ants and seeds much simpler than it would otherwise have been. I would like to work out how to use SVG images for the sprites, because at the moment, the seeds look quite rubbish. But I should focus on the ants behaviour before getting bogged down in making things look pretty.

See Evolving Ant Behaviour for more on this project.


This is very inspiring and impressive work. Can you please publish the source code? and maybe you know good ant-algorithm tutorial in the internet? thanks!

If you email me via the Contact Me button I'll email you the code.


Would it be possible to have a look at the source code for your simulated ant colony work?

Its facinating and would like to try modifying the simulation with opposing species of ants...


Cecil :-)

Post new comment

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