Gyula Rabai

Natural Selection Simulator

by Gyula Rabai

This is the Natural Selection Simulator or in other words an Evolution Simulator. The simulator shows how a population of species can evolve. The simulator has 2 entities: plants and animals. The animals are looking for food. Each animal is represented by a red circle with a specific radius, that allows them to see where food is. They have an energy level and a speed. The energy consumption of an animal is calculated by the radius of the circle, their speed and size. On any given day, if an animal cannot find food before running out of energy he dies. If he finds 1 unit of food, he survives, if he finds 2 units of food, he reproduces. During reproduction, the offsprings get random, modified traits. The simulation can run over several days.

Download (Exe): NaturalSelectionSim.zip
Download (Source code): Natural-Selection-Simulator.zip

Figure 1 - Screenshot

Video

Explanation

The simulation consists of two entity types: plants (food) and animals (agents).

Each animal is visualized as a red circle with a vision radius that reveals nearby food.

  • Vision radius – determines how far the animal can see food.
  • Energy level – consumed each day based on the animal’s radius, speed, and size.
  • Speed – how far the animal moves per tick.

How It Works

  1. Daily Tick – Each day the simulation updates all animals. They move, consume energy, and search for food within their vision radius.
  2. Energy Consumption – Energy used each day is based on the animal’s vision radius, speed, and size.
  3. Survival
    • If an animal cannot find food before its energy reaches zero, it dies.
    • Finding 1 unit of food allows the animal to survive to the next day.
    • Finding 2 or more units of food triggers reproduction.
  4. Reproduction – Offspring receive the parent’s traits with random modifications, enabling evolution over multiple days.

The simulation can be configured to run for a specified number of days, allowing observation of population dynamics and evolutionary trends over time.

Project Structure

├─ LinearAlgebraDotNet/          # Linear algebra utilities (vectors, points)
├─ MovementLab/                  # WPF UI for the movement lab (demo)
├─ NatrualSelectionSim/          # Core simulation
│   ├─ Animal/                   # Player entity implementation
│   ├─ Plant/                    # Food entities
│   ├─ Trait/                    # Trait & mutation logic
│   ├─ World/                    # World management & tick handling
│   └─ GFX/                      # Graphics components
└─ *.sln, *.csproj               # Visual Studio solution & project files
    

Class Overview

  • OzWorld: Manages the overall simulation world, including ticks, rendering, and world state.
  • OzTraits: Container for trait definitions used by animals.
  • OzTrait: Represents a single mutable trait (e.g., speed, size, vision radius).
  • SimulationWindow: WPF window that hosts the simulation view.
  • OzAnimal: Base class for animal agents; handles movement, searching for food, and graphics.
  • OzAnimal_Move: Implements movement logic for OzAnimal.
  • OzAnimal_Search: Implements food‑searching logic for OzAnimal.
  • OzAnimal_Graphics: Handles drawing of animal entities.
  • OzAnimalManager: Manages the collection of animals, creation, removal, and updates.
  • OzPlant: Represents a food item on the island.
  • OzPlantManager: Manages plant generation and rendering.
  • OzGFXComponent: Abstract base for all graphics components.
  • OzGFX: Central graphics helper used by rendering code.
  • OzGFXDimentions: Base class for dimension data (size, radius, etc.).
  • OzGFXCircleDimention: Dimension data for circular shapes.
  • OzGFXEllipseDimention: Dimension data for elliptical shapes.
  • OzGFXApearence: Stores visual appearance properties (color, stroke, etc.).
  • OzGFXCircle: Graphics component for drawing circles.
  • OzGFXEllipse: Graphics component for drawing ellipses.
  • OzEventSyncroniser: Synchronises events between UI thread and simulation logic.
  • OzEntity: Abstract base for all entities (animals, plants, etc.) in the MovementLab demo.
  • OzMovingEntity: Concrete moving entity used in the demo.
  • OzPlainEntity: Simple non‑moving entity used in the demo.
  • App: Application entry point for both the main simulator and the demo.
  • MainWindow: Main WPF window for the simulator.
  • SimulationWindow: Additional window used for visualizing simulation steps.
  • Settings & Resources: Auto‑generated classes for application settings and resources.

Building & Running

  1. Prerequisites
    • Windows 11 (or later)
    • Visual Studio 2022 with .NET desktop development workload
  2. Open the Solution – Open NatrualSelectionSim.sln in Visual Studio.
  3. Build – Press Ctrl + Shift + B or select Build → Build Solution.
  4. Run – Press F5 (Debug) or Ctrl + F5 (Run without debugging). The main window will display the island, animal entities (red circles), and food items (green). Use the UI controls to adjust simulation speed, vision radius, etc.

Configuration

Key simulation parameters can be tweaked in NatrualSelectionSim/App.config or via the UI:

  • InitialEnergy – Starting energy for each animal.
  • VisionRadius – Default radius of the vision circle.
  • MutationRate – Probability of trait mutation during reproduction.

More information


Projects | Books | Printouts | On-line lectures | Presentations