Before starting, make sure you have the following installed:
- Git: Download from https://git-scm.com/
- VS Code (recommended): Download from https://code.visualstudio.com/
- Node.js: Download from https://nodejs.org/ (for bytecode extraction)
β οΈ Important for Windows Users: If you're using Windows, you'll need to install and use Git BASH or WSL as your terminal, since Foundryup currently doesn't support PowerShell or Command Prompt (Cmd).
# Foundry installation
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Install project dependencies
forge installEdit the src/cars/ExampleCar.sol file and code your own strategy.
# Compile + race simulation + bytecode extraction
./compile.sh
# Compile only
forge build
# Race simulation only
forge script script/RunRace.s.sol -vvv- Starting money: 15,000 units
- Win condition: First to reach 1000 units
- Number of players: 5 cars
- buyAcceleration(amount) - Increase speed (permanent)
- Target price: ~10 coins | Min price: 1 coin
- buyShell(amount) - Hit the car in front (reduces their speed to 1)
- Target price: ~200 coins | Min price: 10 coins
- buyShield(amount) - Buy protection (max 6 turns)
- Target price: ~100 coins | Min price: 10 coins
- buyKamikaze() - π₯ Nuclear option! Reduces ALL cars' speed to 1
- Fixed price: 7,500 coins
β οΈ Can only be purchased ONCE per game (by any player)- Affects everyone including yourself!
- Actions become more expensive as they're used more
- Prices decrease as turns pass
- Early actions are expensive, late actions are cheap
βββ src/
β βββ CodePrix.sol # Main game contract
β βββ interfaces/Car.sol # Car interface
β βββ utils/SignedWadMath.sol # Mathematical helpers
β βββ cars/
β βββ ExampleCar.sol # Template car (edit this!)
β βββ DefensiveCar.sol # Defense-focused strategy
β βββ gpt4Car.sol
β βββ ...
βββ script/
β βββ RunRace.s.sol # Advanced race script
βββ extract-bytecode.js # Bytecode extraction
βββ compile.sh # Quick compilation script
// Am I in the lead?
if (ourCarIndex == 0) {
// Defense-focused strategy
}
// Am I at the back?
if (ourCarIndex == allCars.length - 1) {
// Attack-focused strategy
}// Is the car in front too fast?
if (ourCarIndex > 0 && allCars[ourCarIndex - 1].speed > ourCar.speed + 3) {
// Fire shell
codePrix.buyShell(1);
}// Price control
uint256 accelCost = codePrix.getAccelerateCost(1);
if (ourCar.balance > accelCost * 10) {
// Can spend comfortably
}// Check if kamikaze is still available
if (codePrix.kamikazeIsAvailable()) {
// Consider using it strategically
// Best when: you're behind and others have high speed
if (ourCar.balance >= 7500 && needDesperateMove) {
codePrix.buyKamikaze();
}
}// Early game: Build speed
if (codePrix.turns() < 20) {
// Accelerate focus
}
// Late game: Act based on position
if (allCars[0].y > 800) {
// End game tactics
}# Quick simulation (ExampleCar vs ExampleCar x5)
./compile.sh
# Manual simulation run
forge script script/RunRace.s.sol -vvv- Run
./compile.sh - Open
ExampleCar.bytecodefile frombytecode/folder - Copy the content and submit to platform
After running a race simulation:
- Open the
out/gameLog.jsonfile generated from your race - Go to 'https://grandfinale.universitycodeprix.com/simulate'.
- Paste the contents of
gameLog.jsoninto the text area - Click "Load Race Data" to visualize your race
The project includes 3 basic strategy examples:
- Priority: Shield protection and steady progress
- Strategy: Constantly buys shields, accelerates while protected
- Advantage: Strong against shell attacks
- Disadvantage: Slow start, expensive protection
- Priority: Slowing opponents with shells
- Strategy: Constantly hits cars in front
- Advantage: Reduces opponent speeds to 1
- Disadvantage: Remains defenseless, high shell cost
- Priority: Simple and balanced decision making
- Strategy: Shield β Accelerate β Shell sequence
- Advantage: Understandable and safe
- Disadvantage: Predictable
Also advanced examples:
- gpt4Car.sol: AI-generated
# If dependencies are missing
forge install
# Clear cache
forge clean
forge build# Verbose output
forge script script/RunRace.s.sol -vvvvYour contract can use a maximum of 2M gas per turn.
- Understand game mechanics by examining CodePrix.sol contract
- Learn race script structure from RunRace.s.sol
- Get strategy ideas from existing car implementations
- Develop your strategy by watching race simulation
Good racing! ποΈπ¨