Skip to content

About

It's a 2D ecosystem simulation built with Java and JavaFX.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

57 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Darwin World - Evolutionary Ecosystem Simulation

Java JavaFX Simulation

Darwin World is a 2D ecosystem simulation built with Java and JavaFX. It models a world where animals with genetic codes move, eat, reproduce, and pass traits to their offspring. The simulation runs automatically and shows how populations change through natural selection and mutations based on the initial parameters.

Table of Contents


About The Project

This is an autonomous simulation that evolves on its own without player input. The world is a grid divided into fertile jungle areas and harsher steppe areas. Animals spend energy every day and must find food to survive. When they have enough energy, they reproduce and pass a combination of their genes to the next generation, with possible mutations.


Media & Gallery

1. Main Menu (Configuration)

Main configuration menu

*Parameter configuration menu where you set all world settings before launching the simulation.*

2. Preset Selection

Preset selection screen

*Screen for loading built-in presets (for example "fox and rabbits") or choosing your saved configuration.*

3. Live Simulation Map

Live simulation map

*Real-time view of the world grid showing animals, plants, energy levels and movement.*

4. Simulation with Graphs and Animal Tracking

Simulation with statistics and tracker

*Full interface with live population charts, global statistics and detailed tracking of a selected animal (genotype, energy, lineage, etc.).*

Simulation Showcase Video

Watch the full simulation in action (screen recording):

simulation_demo.mp4

Ecosystem Mechanics

Animals in the Ecosystem

  • Herbivores: Move around the map searching for plants. Plants provide different amounts of energy when eaten.
  • Carnivores: Hunt other animals. A carnivore can eat another creature if the energy difference between them is sufficient.
  • Crossbreeding: Breeding is possible between herbivores and carnivores, animal with bigger energy determines the type of child.

Genetics and Movement

Every animal has a genome consisting of 8 genes (numbered 0 to 7), each representing a movement direction. Each day, the active gene determines the direction the animal turns before moving forward. After the move, the next gene in the sequence becomes active.

Reproduction and Mutation

Animals on the same tile with enough energy will mate. The offspring's genome is created by combining genes from both parents in proportion to each parent's current energy level. A random number of genes then mutate.


World Settings

Before starting the simulation you can configure the world parameters in the dedicated menu. These settings define the initial conditions and rules of the ecosystem:

  • Width / Height — width and height of the simulation grid.
  • startNumberOfPlants — initial number of plants placed on the map at the start.
  • numberOfCarnivores — initial number of carnivores.
  • numberOfHerbivores — initial number of herbivores.
  • plantsSpawnPerDay — number of new plants that appear on the map each day.
  • Refresh Rate (ms) — time interval in milliseconds between visual updates of the simulation.
  • startEnergy — starting energy level for every newly created animal.
  • genesLength — length of each animal’s genome (number of genes).
  • energyForTheDay — energy cost an animal spends per day (movement cost).
  • energyToReproduce — minimum energy an animal must have to be able to reproduce.
  • Minimal number of mutations — minimum number of genes that can mutate in the offspring.
  • Maximal number of mutations — maximum number of genes that can mutate in the offspring.
  • energyThreshold (Carnivore) — minimum energy difference required for a carnivore to eat another animal.
  • minEnergy / maxEnergy (Plant) — minimum and maximum energy a plant can provide when eaten (actual value is chosen randomly within this range).

The project includes several built-in presets. You can save your own configurations to files and load them later.


Key Features

UI & Visualization

  • The grid automatically scales to fit the window regardless of the map dimensions.
  • Animals display visual indicators (color or bar) showing their current energy level.
  • Support for running multiple independent simulations simultaneously in separate windows.

Data & Analytics

  • Click any animal to select it. The sidebar shows real-time information: full genotype, active gene index, energy level, number of eaten plants, age, and lineage (direct children and total descendants).
  • Main dashboard displays global statistics: total animals and plants, number of carnivores and herbivores, free cells, average lifespan, average children number and dominant genotypes.
  • Interactive charts: selecting any metric in the World Statistics panel generates a live historical graph of that parameter over time.
  • Daily simulation statistics are automatically exported to a CSV file for analysis in Excel or Python.

Configuration Management

  • Save and load custom world settings.
  • Several built-in presets for different scenarios.

Showcase: Fox & Rabbits

Load the fox and rabbits preset to see the interaction between carnivores and herbivores.

In this configuration the following cycle occurs:

  1. The rabbit population grows when plants are abundant.
  2. The fox population increases because more food is available.
  3. Intensive hunting reduces the rabbit population.
  4. Foxes begin to starve and their numbers decrease.
  5. With fewer predators the rabbit population recovers, and the cycle repeats.

Getting Started

Prerequisites

  • Java JDK 17 or higher
  • Gradle or Maven (depending on your build system)

Running the App

  1. Clone the repository: git clone https://github.com/your-username/darwin-world.git

  2. Navigate to the project directory: cd darwin-world

  3. Run the application via your IDE or build tool (e.g. Gradle): ./gradlew run

  4. In the main menu create your own configuration or load one of the presets and Click Start Simulation


Build with

  • Core Logic: Pure Java (OOP)
  • GUI: JavaFX
  • Concurrency: Java multi-threading for independent simulation instances

About

It's a 2D ecosystem simulation built with Java and JavaFX.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages