https://github.com/neomat-prog/f1-simulator
An overly complicated F1 race simulator
https://github.com/neomat-prog/f1-simulator
f1 javascript nodejs npm
Last synced: about 1 month ago
JSON representation
An overly complicated F1 race simulator
- Host: GitHub
- URL: https://github.com/neomat-prog/f1-simulator
- Owner: neomat-prog
- Created: 2025-04-08T18:35:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-08T21:00:43.000Z (about 1 year ago)
- Last Synced: 2025-09-04T21:41:05.465Z (10 months ago)
- Topics: f1, javascript, nodejs, npm
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/f1-sim
- Size: 7.3 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ποΈ F1 Simulator Package
A complete Formula 1 racing simulation package with real-world data integration, dynamic race features, and realistic race results.
π¦ Installation
bash
Copy
Edit
npm install f1-simulator
π Quick Start
import { F1Client, Race, Track } from 'f1-simulator';
```
async function runSimulation() {
try {
const sessionKey = await F1Client.getSessionKey('Monza', 2023, 'Qualifying');
const driversData = await F1Client.getDrivers(sessionKey);
const track = new Track('Monza', 75, 95, 3); // name, minLapTime, maxLapTime, DRS zones
const race = new Race({
track,
drivers: driversData,
sessionKey,
laps: 53,
weather: 'dry' // Options: 'dry', 'wet', or 'dynamic'
});
await race.initialize();
const results = race.simulate();
console.log('\nRace Results:');
results.forEach((driver, index) => {
const status = driver.retired ? 'DNF' : `${driver.time.toFixed(3)}s`;
console.log(`${index + 1}. ${driver.driver.padEnd(15)} ${status}`);
});
} catch (error) {
console.error('Simulation error:', error.message);
}
}
runSimulation();
```
π§° Features
β
Real F1 data integration
π Tire degradation modeling
π¨ Safety car deployment probabilities
π DRS system simulation
π₯ Crash and mechanical failure mechanics
β±οΈ Realistic lap time performance calculations
π¦οΈ Dynamic weather changes
π§ Pit strategy planning
π οΈ Custom Simulation
Custom Drivers and Teams
```javascript
const redBull = new Team('Red Bull', 97);
const mercedes = new Team('Mercedes', 95);
const customDrivers = [
new Driver('Max Verstappen', redBull, 95, 1),
new Driver('Lewis Hamilton', mercedes, 93, 44)
];
```
Custom Track
```
const customTrack = new Track('Custom Circuit', 80, 110, 2);
Run a Custom Race
const customRace = new Race({
track: customTrack,
drivers: customDrivers,
laps: 30,
weather: 'wet'
});
customRace.initialize().then(() => {
const results = customRace.simulate();
console.log('\nCustom Race Results:');
results.forEach(r => console.log(r));
});
```
βοΈ Advanced Configuration
π¦οΈ Weather Simulation
```
const race = new Race({
// ... other config
weather: 'dynamic',
weatherChanges: [
{ lap: 10, newWeather: 'wet' },
{ lap: 20, newWeather: 'dry' }
]
});
```
π οΈ Pit Strategy
```
const strategies = {
'Max Verstappen': {
15: 'hard',
30: 'medium'
},
'Lewis Hamilton': {
10: 'soft',
25: 'medium'
}
};
```
```
const race = new Race({
// ... other config
pitStrategies: strategies
});
```
π Safety Car Configuration
```
import { SafetyCarSystem } from 'f1-simulator';
SafetyCarSystem.probabilities = {
normal: 0.03,
wet: 0.20,
crash: 0.35
};
```
π§Ύ Output Example
```
Race Results:
1. Max Verstappen 3089.452s
2. Lewis Hamilton 3092.781s
3. Charles Leclerc 3095.112s
4. Sergio PΓ©rez DNF
5. Carlos Sainz 3101.334s
```
Contributing:
I am very open for people to request commits, to my project. If you have any ideas that could be implemented or bugs squashed just send a pull request and I will be on my way to check it out!
π API Documentation
For full API reference and advanced usage, see the API Docs.
https://openf1.org/?javascript#introduction