Skip to content

xxdagi/Darwin-World-Mini-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 

Repository files navigation

Darwin World Mini Simulation

A mini Java implementation inspired by the Darwin World simulation - animals move across a 2D map, avoid collisions, and interact with their environment. Built with JavaFX and object-oriented design principles including interfaces, abstract classes, the Observer pattern, and multithreading.

Table of Contents

Overview

A mini Darwin World implementation in Java. Animals are placed on a 2D grid and move step by step according to a sequence of commands entered by the user. They navigate the map, avoid collisions, and interact with grass elements scattered across the world. The simulation can be run both in the console and via a graphical JavaFX interface with a live-rendered canvas map.

Features

  • Two map types: RectangularMap (bounded) and GrassField (infinite with grass)
  • Animals that move, rotate, and respect map boundaries
  • Randomly placed grass
  • JavaFX GUI with a live canvas-rendered map
  • Console mode with real-time map display
  • Multithreaded simulation engine supporting sync, async, and thread pool execution
  • Observer pattern - map notifies listeners on every change

Project Structure

src/
├── main/
│   ├── java/
│   │   └── agh/ics/oop/
│   │       ├── model/
│   │       │   ├── util/
│   │       │   ├── AbstractWorldMap.java
│   │       │   ├── Animal.java
│   │       │   ├── ConsoleMapDisplay.java
│   │       │   ├── Grass.java
│   │       │   ├── GrassField.java
│   │       │   ├── MapChangeListener.java
│   │       │   ├── MapDirection.java
│   │       │   ├── MoveDirection.java
│   │       │   ├── MoveValidator.java
│   │       │   ├── RectangularMap.java
│   │       │   ├── Vector2d.java
│   │       │   ├── WorldElement.java
│   │       │   └── WorldMap.java
│   │       ├── presenter/
│   │       │   └── SimulationPresenter.java
│   │       ├── OptionsParser.java
│   │       ├── Simulation.java
│   │       ├── SimulationApp.java
│   │       ├── SimulationEngine.java
│   │       ├── World.java
│   │       └── WorldGUI.java
│   └── resources/
└── test/

Controls

In the GUI, type of a sequence of moves in the text field and click Start.

Command Action
f Move forward
b Move backward
l Rotate left (90°)
r Rotate right (90°)

Example input: f f r f f l b f

NOTE: Animals take turns - each move command is applied to the next animal in rotation.

How to run

Prerequisites

  • Java 25

Clone the repository

git https://github.com/xxdagi/Darwin-World-Mini-Simulation.git

Navigate to the project folder

cd Darwin-World-Mini-Simulation
cd oolab

Run

./gradlew run

This will open the JavaFX window. Type your move commands in the text field and click Start.

Map Types

RectangularMap

  • Fixed boundaries defined at creation (width × height)
  • Animals cannot move outside the bounds
  • No grass

GrassField

  • Effectively unbounded - canvas resizes to fit all elements
  • Grass is randomly placed at startup (up to √(n*10) coordinate range for n grass patches)
  • Grass does not block animal movement

Tests

The project includes unit tests. Below there is a description of each one.

Test class What is tested
Vector2dTest Vector operations: add, subtract, precedes, follows, upperRight, lowerLeft
MapDirectionTest Direction rotation: next() and previous()
OptionsParserTest Parsing valid, invalid, mixed and empty move commands
RectangularMapTest Placing animals, boundary checks, collision detection
GrassFieldTest Grass placement, animal interaction with grass, movement
SimulationTest Animal movement, rotation, boundary behavior, multi-animal simulation

Notes

  • Simulation runs in a separate thread with a 500ms delay between moves for visual feedback
  • Multiple simulations can be run in parallel using SimulationEngine
  • Each map has a unique UUID for identification in multi-simulation scenarios

About

A mini Java implementation inspired by the Darwin World simulation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors