Inspiration

The inspiration for XenoSwarm came from the mesmerizing beauty of "Particle Life" simulations and the concept of emergent behavior. We’ve always been fascinated by how simple mathematical rules can create complex, life-like structures—cells, gliders, and swarms.

However, most particle simulations are passive screensavers. We asked ourselves: What if we could weaponize this? What if we turned the mathematical beauty of cellular automata into a competitive strategy game where "DNA" is just a matrix of force vectors? Imagine if each particle were a drone in a swarm, robotic rover to collect resources, or tiny nanites that function like white blood cells. The applications of xenobots are endless!

We wanted to build a simulation that feels like a biological arms race in a cyberpunk petri dish, where players (and AI) engineer the fundamental laws of physics to survive.

What it does

XenoSwarm is a high-performance GPU-style particle strategy game. Players design a colony by tweaking its DNA Matrix—a set of floating-point values determining how particles attract or repel one another.

  • The Physics Engine: Simulates thousands of particles interacting in real-time.
  • The Arena: Two colonies are dropped into hostile environments (Vacuum, Soup, or Swarm Pit) to battle for dominance.
  • GenAI Evolution: The core innovation is the "Gauntlet Mode." We use Google Gemini to power an evolutionary engine. After every match, the AI analyzes the battle logs, survival rates, and opponent strategies. It then "mutates" its own DNA matrix to counter the player, effectively learning how to win through natural selection accelerated by LLMs.

How we built it

The project was built using a modern web stack designed for performance and interactivity:

  1. Simulation Engine (TypeScript & HTML5 Canvas): The core challenge was performance. A naive particle simulation has a complexity of \( O(n^2) \). To support 2,500+ particles at 60 FPS in the browser, we implemented a Spatial Partitioning Grid. The force \( F \) between two particles \( i \) and \( j \) is calculated based on their distance \( d \) and the interaction radius \( r_{max} \):

    $$ F_{ij} = \begin{cases} -2 (1 - \frac{d}{r_{min}}) & \text{if } d < r_{min} \ M_{AB} \times (1 - \frac{|2d - r_{max} - r_{min}|}{r_{max} - r_{min}}) & \text{if } r_{min} < d < r_{max} \end{cases} $$

    Where \( M_{AB} \) is the force value defined in the DNA matrix between particle type A and type B.

  2. Genetic Algorithm & LLM Integration: We treat the colony's behavior matrix \( M \) as its DNA. The evolution engine uses a heuristic function to calculate a mutation intensity \( \mu \) based on the survival ratio \( S_r \) and match duration \( T \):

    $$ \mu = \begin{cases} 0.05 & \text{if Win and } T < 20s \ 0.90 & \text{if Loss and } T < 15s \ 0.15 + (1 - S_r) \times 0.2 & \text{if Win} \ 0.65 & \text{if Draw} \end{cases} $$

    This \( \mu \) value acts as the "temperature" for the Gemini API, which receives the battle history sequence \( H = { (M_0, O_0), \dots, (M_t, O_t) } \) (where \( O \) is outcome) and generates the next generation matrix \( M_{t+1} \) to optimize the objective function (Victory).

  3. Procedural Audio Synthesis (Web Audio API): Instead of using static samples, we built a generative synthesizer. We mathematically derive frequencies \( f \) for our cyberpunk scales (e.g., Phrygian Dominant) relative to a base sub-bass frequency \( f_{base} = 27.5 \text{Hz} \) (A0):

    $$ f_n = f_{base} \times 2^{(O + \frac{I_n}{12})} $$

    To create the gritty, "broken" texture, we apply a non-linear distortion curve to the signal \( x \) using a WaveShaper node:

    $$ y(x) = \frac{(3+k)x \cdot 20}{\pi + k|x|} $$

    Where \( k \) is the distortion coefficient. This allows us to generate dynamic soundscapes that react to game events without loading external assets.

  4. UI/UX: Built with React and Tailwind CSS, featuring a CRT scanline aesthetic, glassmorphism panels, and dynamic data visualization for the force matrices.

Challenges we ran into

  • Physics Optimization: JavaScript is single-threaded. Calculating interactions for thousands of particles initially killed the frame rate. Implementing a robust spatial grid and optimizing array allocations (using Float32Array instead of native objects) was crucial to getting buttery smooth 60 FPS.
  • Prompt Engineering Physics: Getting an LLM to understand that changing a float value from 0.5 to -0.5 implies a shift from "Attraction" to "Repulsion" took several iterations. We had to provide the AI with a "memory" of past matches so it didn't just make random guesses but actually iterated on previous designs.
  • Audio Clipping: Generating procedural audio in a chaotic battle resulted in massive volume spikes. We had to implement a custom compressor chain and throttling logic to keep the soundscape atmospheric rather than painful.

Accomplishments that we're proud of

  • The "Gauntlet" Mode: Watching the Gemini-powered AI actually learn. In one test, we used a strategy of "clumping" for defense. After two losses, the AI evolved its DNA to maximize repulsion and speed, effectively turning its swarm into "missiles" that broke our defense. It was a genuine "Ghost in the Machine" moment.
  • The Vibe: The combination of the CRT effects, the generative dark-synth music, and the neon particle effects creates a deeply immersive atmosphere.
  • Performance: Running 2,500 interactive agents in a browser without WebGL (pure 2D Canvas) is a significant technical optimization feat.

What we learned

  • LLMs as Logic Engines: LLMs are excellent at "fuzzy logic." We didn't need to program complex if/else trees for the AI strategy; we just described the physics rules to Gemini, and it figured out how to manipulate the variables to achieve victory.
  • Emergent Complexity: You don't need complex code to create complex behaviors. Simple rules of attraction and repulsion can create structures that look like cells, snakes, and explosions.

What's next for XenoSwarm: Particle Arena

  • WebGL Migration: Porting the simulation loop to custom shaders to support 10,000+ particles.
  • Multiplayer: Implementing WebSockets to allow human players to pit their custom DNA strands against each other in real-time.
  • Ecosystems: Adding multiple species and food sources to simulate a full ecosystem rather than just a battle arena.
Share this project:

Updates