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.
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.
- 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
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/
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.
- Java 25
git https://github.com/xxdagi/Darwin-World-Mini-Simulation.gitcd Darwin-World-Mini-Simulation
cd oolab./gradlew runThis will open the JavaFX window. Type your move commands in the text field and click Start.
- Fixed boundaries defined at creation (width × height)
- Animals cannot move outside the bounds
- No grass
- Effectively unbounded - canvas resizes to fit all elements
- Grass is randomly placed at startup (up to
√(n*10)coordinate range forngrass patches) - Grass does not block animal movement
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 |
- 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
UUIDfor identification in multi-simulation scenarios