Skip to content

yashclouded/algomain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ALife Simulation Engine v2

A modular artificial life simulation with neural network brains, sexual reproduction, cannibalism, emergent evolution, and a real-time GUI dashboard.

Python 3.10+

Features

  • Neural network brains — 6→6→4 feedforward neural net drives all organism decisions (movement, aggression, mating). 70 evolvable weights in the genome.
  • Sexual reproduction — organisms mate with genetically similar partners, performing crossover of both trait genes and neural network weights.
  • Cannibalism — organisms with 2× energy of a nearby organism can eat it, gaining 50% of its energy.
  • Death consequences — dead organisms drop food (corpse nutrients), creating nutrient cycling. Death causes tracked (starvation, old age, cannibalized).
  • Emergent evolution — fitness emerges from survival and reproduction, not hardcoded rules.
  • Genetic encoding — 8 trait genes (speed, vision, metabolism, reproduction threshold, mutation rate, lifespan, size, aggression).
  • Realistic aging — telomere-like mutation load degrades lifespan across generations.
  • Species clustering — distance-threshold clustering assigns species IDs by genome similarity.
  • Real-time GUI — tkinter dashboard with live canvas, statistics, matplotlib graphs, and controls.
  • CSV/JSON logging — all metrics saved for post-analysis.

Quick Start

1. Create virtual environment

/usr/local/opt/python@3.13/bin/python3.13 -m venv .venv
source .venv/bin/activate

2. Install dependencies

pip install -r requirements.txt

3. Run with GUI

python main.py

4. Run headless (no GUI)

python main.py --headless

Project Structure

algomain/
├── main.py               # Entry point
├── config.py              # Configuration dataclass
├── requirements.txt
├── src/
│   ├── neural_net.py      # Feedforward neural network (6→6→4)
│   ├── genome.py          # Genome: trait genes + NN weights + mutation
│   ├── organism.py        # Organism: NN decisions, mating, cannibalism
│   ├── environment.py     # 2D toroidal world, food, spatial indexing
│   ├── simulation.py      # Main engine loop
│   ├── controller.py      # Thread-safe simulation control
│   ├── analytics.py       # Metrics tracking & logging
│   └── gui.py             # tkinter + matplotlib dashboard
└── logs/                  # Auto-created CSV/JSON output

Configuration

Edit config.py or use the GUI sliders:

Parameter Default Description
world_width × world_height 1200×800 World dimensions
initial_population 100 Starting organism count
max_population 2000 Population cap
food_spawn_rate 8.0 Base food items per tick
base_mutation_rate 0.05 Per-gene mutation probability
cannibalism_energy_ratio 2.0 Attacker needs 2× victim energy
mating_distance 10.0 Max distance for mating
nn_weight_mutation_rate 0.1 NN weight mutation probability

GUI Controls

Button Action
▶ Start Begin a new simulation
⏸ Pause Pause the simulation loop
🔁 Resume Resume from paused state
⏹ Stop Cleanly terminate, save logs
⏭ Step Advance one tick (when paused)

How It Works

Neural Network Brain

Each organism has a small neural network (6 inputs → 6 hidden → 4 outputs) that processes sensory information and outputs decisions:

Inputs: nearest food distance/angle, nearest organism distance/angle, energy ratio of neighbor, own energy ratio.

Outputs: movement angle, speed factor, aggression level (attack/flee), mate desire.

Weights are stored in the genome and evolve through mutation and crossover.

Cannibalism

If an organism's energy exceeds 2× a nearby organism's energy AND its neural net aggression output is high AND its aggression gene is positive, it eats the victim. The predator gains 50% of the victim's energy.

Sexual Reproduction

Two organisms can mate if they're close enough, both have sufficient energy, their genomes are similar (same species), and neither is on mating cooldown. The child gets crossover of both parents' traits AND neural network weights.

Death Consequences

Dead organisms drop food at their death location (corpse → nutrients). This creates nutrient cycling — deaths feed the ecosystem, making carnivorous strategies viable.

Death causes are tracked: starvation, old age, cannibalized.

Aging & Telomere Model

  • Every reproduction increments the parent's mutation load
  • Mutation load reduces effective lifespan: effective_lifespan = base * (1 - 0.02 * load)
  • Death probability follows a hockey-stick curve — safe until 60% of lifespan, then rapidly increasing

Outputs

Logs are saved to logs/:

  • metrics_*.csv — per-tick population, genetics, aging, evolution, kills, matings
  • final_state_*.json — final snapshot with death causes and best organism genome

Inspiration

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages