Inspiration

THE ANTS

What it does

Our program models real-world ant colonies, simulating competition for shared resources, avoiding obstacles, and pathfinding. Ants explore their environment to find resources, then successful ants leave trails for others to follow. The ants constantly adapt as resources are consumed, refining the paths taken to reach them.

How we built it

We built the project in Kotlin using the OPENRNDR graphics framework.

Each ant belongs to a 'colony'. Members of a colony can communicate with one another by leaving trails of pheromone for other ants to follow. However, instead of just blindly following any nearby pheromone, ants are controlled by a behavioural state machine. After following a trail to find food, ants will gather as much as they can carry before returning to the colony to share their haul with others. Pheromones evaporate over time, forcing the ants to continue exploring new paths, or re-confirm existing ones.

Challenges we ran into

Implementing pheromone trails posed a number of interesting technical challenges. Ants must be able to lay continuous trails while also querying pheromone levels, all at arbitrary positions. Using a 2D grid of pheromone values provides fast lookup, but requires very high resolution and constrains the ants to a fixed bounding box. On the other hand, storing pheromone trails as vectors is space efficient and permits arbitrary positions, but suffers from very slow lookup. We had to devise a hybrid approach: storing vector trails and using an efficient flood-fill algorithm to compute a cached grid.

Even with a working pheromone trail, getting the ants to correctly follow the trails and navigate their way home was still a challenge. A lot of tweaking and refining of the pheromone-following algorithm was needed to make the pathfinding look organic. We needed to strike a balance between allowing the ants to have the capability to wander randomly (in order to find untouched resources) but also be guided enough to take efficient paths to and from a resource.

Another challenge was splitting the simulation and rendering code onto separate threads. This was a crucial optimisation given the intensive front and back-end workload.

Accomplishments that we're proud of

We struggled initially to settle on an idea that we were excited about, but we pushed through and ended up with a project that we're really happy with. We're really proud to have made a simulation so deeply fascinating and mesmerising to watch. We're also extremely proud to say that not a single line of code in this project was written by GenAI.

What we learned

Half of our team had almost no experience with Kotlin before starting this project, and had to learn on the fly in a technical and performance critical project. Graphics programming in Kotlin was new to all of us, so we had to learn the ins-and-outs of OPENRNDR from scratch.

What's next for THE ANTS

World domination.

Built With

Share this project:

Updates

Submission history