Darwin's Sandbox

A natural selection and evolution simulator powered by Unity, demonstrating artificial neural networks and genetic algorithms through a virtual ecosystem.

Project Overview

Darwin's Sandbox is a natural selection and evolution simulator powered by Unity. This project demonstrates artificial neural networks (ANNs) and genetic algorithms through a virtual ecosystem of creatures (wolves) that hunt, mate, and evolve over time.

Built using Unity and C#, this project allows users to observe and interact with evolving neural networks in real-time. The simulation includes various environmental factors that influence the evolution of the AI agents, creating a fascinating demonstration of artificial life and adaptation.

Key Features

  • Neural Network-Driven Creatures: Each creature is controlled by a neural network that evolves through generations
  • Natural Selection: Creatures that better adapt to find food and mates survive longer and reproduce more frequently
  • Dynamic Ecosystem: Food spawns throughout the environment, creating a balanced ecosystem
  • Realistic Behaviors: Hunting, mating, and wandering states with genetic inheritance
  • Simulation Controls: Adjust simulation speed with = to increase and - to decrease speed

How It Works

Creature States

  • Wandering: Default exploration state
  • Hunting: Activated when hunger falls below 50% and prey is detected
  • Mating: Triggered when love level is full and creature isn't hungry
  • Resting: Brief recovery period after reproduction

Neural Networks

  • Inputs: Environmental sensors, hunger level, prey direction and distance
  • Outputs: Movement controls (forward/backward and turning)
  • Evolution: Neural networks evolve through inheritance and mutation

Energy System

  • Hunger decreases over time
  • Consuming food restores hunger
  • Creatures die if hunger reaches zero
  • Reproduction costs energy for both parents

Technologies Used

UnityC#Neural NetworksGenetic AlgorithmsMachine Learning

Evolution in Action

Watch as neural networks learn and adapt to their environment through natural selection.

Neural Network Architecture

The project uses a sophisticated neural network system that evolves through generations, with successful traits being passed down to future generations while less successful ones are gradually phased out.

Interactive Environment

Users can interact with the simulation by adjusting various parameters such as:

  • Population size
  • Mutation rate
  • Selection pressure
  • Environmental conditions

Wolf AI State Machine

Wolf Hunting State

Hunting

When a wolf's hunger drops below 50, it enters the Hunting state. The wolf will pathfind toward the nearest sheep and attempt to eat it—if its neural network decides to do so (some are better at hunting than others). This decision-making process is influenced by the wolf's current neural network weights, allowing for emergent and evolving behaviors.

Wolf Mating State

Mating

If two wolves both have their Love at 100 and their Hunger above 50, they can enter the Mating state. If their neural networks decide to mate, a new wolf is created, inheriting a combination of neural network weights from both parents. This allows for the evolution of more successful behaviors over generations.

Wandering

Wolves enter the Wandering state when they are not hungry enough to hunt or not ready to mate. In this state, they move around the environment in a more random or exploratory fashion, waiting for their internal conditions to change.

Source Code

Check out the source code on GitHub