TurboShells
Turtle racing simulation with 20-trait genetics and sacrificial breeding
The Problem
Breeding simulations often oversimplify genetics to a few traits. The challenge was implementing a 20-trait genetic system with meaningful trait interactions, while maintaining frame-independent stability and performance at simulation limits.
My Approach
- → 20-trait genetic system with complex trait interactions
- → Rust core for performance-critical genetics calculations
- → Mendelian inheritance with blended inheritance patterns
- → RGB, discrete, and continuous mutation systems
- → Python bindings via PyO3 for integration
Key Highlights
- Zero-copy genetics operations in Rust
- Parallel-ready architecture (rayon-compatible)
- 10-100x speedup over pure Python for batch operations
- Memory-safe physics simulation
How It Works
TurboShells is a turtle racing simulation with a 20-trait genetic system. The Rust core library provides compute-intensive genetics operations with Python bindings via PyO3.
Overview
The turboshells-core library provides high-performance Rust systems for turtle racing simulation:
| Module | Description |
|---|---|
genetics | 20 gene definitions, Mendelian inheritance, mutation system |
simulation | Turtle physics, terrain effects, race engine |
Genetic System
20 Gene Definitions:
- Comprehensive trait set for realistic genetic diversity
- Mendelian inheritance patterns
- Blended inheritance for continuous traits
- Mutation systems: RGB, discrete, and continuous
Inheritance Mechanics:
import turboshells_core as tc
genetics = tc.PyGenetics()
parent1 = genetics.generate_random()
parent2 = genetics.generate_random()
child = genetics.inherit(parent1, parent2)
mutated = genetics.mutate(child, rate=0.1)
Simulation:
turtle = tc.PyTurtle("Speedster", speed=10, energy=80, recovery=5, swim=5, climb=5)
race = tc.PyRace(track_length=1500.0)
race.add_turtle(turtle)
winner = race.run()
Architecture
src/
├── lib.rs # PyO3 module entry
├── types.rs # Rgb, TurtleStats, GeneValue
├── genetics/
│ ├── genes.rs # 20 gene definitions
│ ├── mutation.rs # RGB/discrete/continuous mutations
│ └── inheritance.rs # Mendelian + blended inheritance
└── simulation/
├── turtle.rs # Turtle struct + physics
├── terrain.rs # 6 terrain types
└── race.rs # Race simulation loop
Performance
The Rust implementation provides:
- Zero-copy genetics operations
- Parallel-ready architecture (rayon-compatible)
- Memory-safe physics simulation
- Typical 10-100x speedup over pure Python for batch operations
Building
Requires Python 3.12 and Rust toolchain.
# Install maturin
pip install maturin
# Build wheel
maturin build --release
# Install
pip install target/wheels/turboshells_core-*.whl
Lessons Learned
Complex trait interactions create emergent behaviors that are difficult to predict. The 20-trait system produces surprising combinations that weren’t explicitly designed, demonstrating the power of genetic algorithms.
Performance-critical operations belong in Rust. The 10-100x speedup for batch genetics operations enables simulations that would be impractical in pure Python.
GitHub: TurboShells
Built with Rust and PyO3. 20-trait genetics with sacrificial breeding mechanics.