This repository contains an advanced Ant Colony Simulation that demonstrates emergent behavior through pheromone-based pathfinding and collective food gathering.
- Obstacle implementation and collision detection
- Ant steering behavior and obstacle avoidance
- Core ant movement mechanics
- Simulation physics and navigation
- Food system implementation
- Pheromone tracking mechanism
- Nest functionality and return behavior
- Food counting system
- Right-click food spot creation
- Soldier ant implementation and behavior
- Teamwork interaction between worker and soldier ants
- Enhanced soldier ant protection logic
- Game mechanics adjustments for ant behaviors
- Realistic ant movement with steering behaviors
- Obstacle avoidance system
- Pheromone-based communication
- Food gathering and transportation
- Nest-centered colony behavior
-
Worker Ants:
- Responsible for foraging food and gathering resources.
- Exhibit pheromone-following behaviors to lead others to food sources.
- Carry food back to the nest and deposit it for storage.
-
Soldier Ants:
- Designed to protect the colony and worker ants.
- Move towards nearby worker ants when they are in danger.
- Maintain a distance from the nest while ensuring the safety of worker ants during food collection.
- A heart-shaped obstacle that creates interesting patterns in the simulation.
- This shape adds a unique visual element and tests the ants' navigation skills.
- A circular obstacle that provides a smooth barrier for the ants.
- This shape encourages ants to navigate around it rather than directly through it.
- A square-shaped obstacle that represents typical barriers.
- It introduces a standard challenge for ant movement and pathfinding.
- Obstacles that are placed at random locations within the simulation area.
- This adds unpredictability to the environment, requiring ants to adapt their strategies.
-
Food Collection System:
- Ants search for food sources
- Food is gathered in concentrated spots
- Automatic food replenishment
- Visual feedback when ants carry food
-
Pheromone System:
- Dynamic pheromone trails
- Strength-based pheromone following
- Pheromone decay over time
- Different pheromone types (food and home trails)
-
Anti-Clustering Mechanisms:
- Memory-based movement patterns
- Stuck detection and resolution
- Directional persistence
- Random exploration factors
-
**Teamwork Behavior: • Soldier ants move to protect worker ants when they are nearby. • Worker ants benefit from soldier protection, ensuring safer food collection.
PHEROMONE_STRENGTHS = {
'carrying_food': 300, # Strong trail when carrying food
'returning_to_food': 200, # Medium-strong trail when returning to known food
'experienced': 100, # Medium trail for experienced ants
'exploring': 20 # Weak trail during exploration
}
MOVEMENT_WEIGHTS = {
'wander_force': 0.3, # Base random movement
'avoid_force': 2.0, # Obstacle avoidance priority
'pheromone_influence': {
'carrying_food': 2.0,
'returning': 1.5,
'exploring': 0.4
}
}
ANTI_CLUSTERING = {
'memory_length': 30, # Positions to remember
'stuck_threshold': 40, # Distance threshold for stuck detection
'direction_persistence': {
'min': 30,
'max': 60
}
}
The simulation includes four types of obstacles, each represented in the following GIFs:
- Heart-shaped Obstacle:
- A unique heart shape that presents a challenge for the ants.
- Circular Obstacle:
- A circular obstacle that requires strategic navigation.
- Square Obstacle:
- A square obstacle that blocks paths and affects ant movement.
The soldier ant is a specialized type of ant responsible for protecting worker ants during food collection. Below are the characteristics of the soldier ant:
-
Protection of Worker Ants: Soldier ants actively approach nearby worker ants to provide protection, ensuring their safety during food gathering.
-
Behavior Demonstration: Soldier ants patrol around the nest to offer support when needed.
git clone https://github.com/Yoppman/Ant-Simulation.git
cd Ant-Simulation
Make sure you have Python installed. Install required libraries:
pip install -r requirements.txt
- Python 3.x
- Pygame 2.x
Launch the simulation:
python main.py
- Right Click: Add new food source
- Close Window: Exit simulation
- Food counter displays in top-left corner
-
Exploring:
- Higher random movement
- Lower pheromone influence
- Active obstacle avoidance
-
Food Found:
- Strong pheromone trail creation
- Direct path to nest
- Minimal random movement
-
Returning to Food:
- Medium pheromone following
- Remembered position influence
- Moderate random movement
-
Trail Creation:
- Stronger trails when carrying food
- Medium strength for return trips
- Weak trails during exploration
- Automatic decay over time
-
Following Behavior:
- Weighted influence based on pheromone strength
- Distance-based effectiveness
- Random variation to prevent clustering
- Experience-based following efficiency
-
Anti-Clustering Mechanics:
- Position memory system
- Stuck detection algorithms
- Direction persistence
- Random force injection
- Different ant types (workers, soldiers)
- Multiple food types
- Dynamic obstacle generation
- Weather effects on pheromones
- Colony growth mechanics
- Predator-prey interactions
Feel free to fork the repository and submit pull requests. Areas for improvement include:
- Performance optimization
- New ant behaviors
- UI improvements
- Additional environment features
This project is open source and available under the MIT License.