A console-based race simulation developed in Java to demonstrate graph algorithms, custom data structures, and event-driven processing.
The race track is represented as a directed graph. Cars travel between checkpoints, where different processing rules such as FIFO, LIFO, MAX Heap, and START priority determine the order in which cars continue the race.
- Graph-based race track representation
- Event-driven race simulation
- Random road selection between checkpoints
- Multiple checkpoint processing rules
- FIFO processing using a custom queue
- LIFO processing using a custom stack
- Min-Heap and Max-Heap implementations
- Custom event priority queue
- Depth-First Search (DFS) for path existence checks
- Race leaderboard based on finishing time
- Tracking of each car's complete path
- PIT and FINISH checkpoint handling
- Race track data loaded from an external text file
java-race-simulation/
├── src/
│ ├── Main.java
│ ├── Race.java
│ ├── Car.java
│ ├── Checkpoint.java
│ ├── Road.java
│ ├── Graph.java
│ ├── DepthFirstPaths.java
│ ├── Eventt.java
│ ├── EventList.java
│ ├── EventHeap.java
│ ├── MyHeap.java
│ ├── MyQueue.java
│ └── MyStack.java
├── racetrack.txt
├── .gitignore
└── README.md
Controls the overall simulation, loads the track, creates cars, processes events, manages checkpoints, and generates the final leaderboard.
Represents the race track using checkpoints as vertices and roads as directed edges.
Represents a connection between two checkpoints together with its distance.
Processes cars according to different rules:
FIFO→ QueueLIFO→ StackMAX→ Max HeapSTART→ Min HeapPIT→ Removes cars from the active raceFINISH→ Records completed cars
Stores information about each car, including:
- Car ID
- Current checkpoint
- Elapsed race time
- Race status
- Complete travelled path
Uses Depth-First Search to determine whether a path exists between two checkpoints.
Stores race events in priority order according to arrival time.
Custom dynamically growing circular queue implementation.
Custom stack implementation used for LIFO checkpoint processing.
Custom Min-Heap / Max-Heap implementation used to prioritize cars based on their IDs.
This project demonstrates:
- Graphs
- Depth-First Search
- Priority Queues
- Binary Heaps
- Queues
- Stacks
- Arrays
- Event-driven simulation
- File I/O
The race track is loaded from:
racetrack.txt
The file contains the number of checkpoints, number of roads, and the directed connections between checkpoints.
Each road is represented using:
startCheckpoint endCheckpoint distance
Example:
0 1 8
0 2 1
0 3 5
- Java Development Kit (JDK)
From the project root directory:
javac src/*.javajava -cp src MainMake sure racetrack.txt remains in the project root directory.
When the program starts:
- The race track is loaded from
racetrack.txt. - The user enters the number of cars.
- Cars begin at checkpoint
0. - Cars travel through randomly selected outgoing roads.
- Each checkpoint processes cars according to its assigned rule.
- Events are processed according to arrival time.
- Cars reaching checkpoint
15finish the race. - Cars entering checkpoint
10are moved to the PIT. - A leaderboard is generated after the race.
- The user can check whether a path exists between two checkpoints using DFS.
The simulation combines several data structures in a single application:
Graph -> race track
DFS -> path checking
Queue -> FIFO checkpoints
Stack -> LIFO checkpoints
Heap -> priority-based checkpoints
Event Heap -> chronological race event processing
This project was developed as an academic Java project to practice data structures, graph algorithms, custom collection implementations, priority processing, and event-driven simulation.
Zeynep Oktay