Quaternion: The Fourfold Simulation - Hackathon Submission
Inspiration
Our inspiration for Quaternion stemmed from a desire to redefine the role of artificial intelligence in gaming. We asked ourselves: what if AI wasn't just the opponent, but the entire ecosystem? Instead of creating another RTS with smarter, faster enemies, we envisioned a world where AI is a creative partner, a dynamic narrator, and a philosophical judge. The name "Quaternion" reflects this core concept, representing a system of four interconnected parts. In our game, these are the four fundamental resources the player must balance: Matter (Ore), Energy, Life (Biomass), and Knowledge (Data). Our goal was to build a game that is not just played, but experienced—a simulation where every action has a meaningful, AI-driven reaction, creating a truly emergent narrative.
We were inspired by the idea of a game that feels alive, where the world, the music, and the characters react to the player's strategic and moral choices. We wanted to move beyond scripted events and create a system where the story is a direct consequence of gameplay, a world that remembers and reflects on the player's philosophy. This led us to integrate a suite of generative AI tools, not as gimmicks, but as foundational pillars of the game's design.
What it does
Quaternion is a sci-fi real-time strategy (RTS) game where players build, explore, and battle in a world that is procedurally generated and constantly evolving through AI. The core gameplay revolves around managing the four primary resources, each representing a different philosophical and strategic path. The ultimate goal is not just to win, but to find balance.
Key Features:
AI-Driven World Generation: Players can generate unique, playable RTS maps from simple text prompts (e.g., "a fractured neon wasteland with overgrown biotech ruins"). The AI interprets the prompt to create strategically diverse terrain with distinct biomes and resource layouts.
Adaptive AI Commanders: The game features AI opponents with evolving personalities. These commanders learn from each match, adjusting their strategies and internal biases based on their performance. Their personalities are defined by their affinity to the four Quaternion axes, resulting in unique playstyles.
AI-Generated Voiceover & Narrative: Quaternion features a cast of four AI advisors, each representing one of the core resources. Using ElevenLabs TTS, their voices are dynamically modulated based on the game's state. If the player neglects a resource, the corresponding advisor's voice will shift in tone, becoming panicked, arrogant, or disappointed, creating an immersive, emotionally-resonant experience.
Adaptive Music System: The game's soundtrack is procedurally composed in real-time. The music shifts dynamically based on the balance of the four resources, the level of in-game tension, and the overall state of the simulation. A state of equilibrium produces calm, ambient music, while a resource crisis might trigger a tense, electronic score.
Dynamic Lore Engine & Emergent Narrative: Each map is generated with its own AI-written history and lore. As the game progresses, the AI generates micro-events and narrative snippets that reflect the player's actions. A "Moral Memory" system tracks player choices, influencing future events and the final judgment.
The Quaternion Core - A Meta-AI Judge: At the end of each game, a meta-AI called the "Quaternion Core" analyzes the player's entire gameplay log. It doesn't just determine win or loss; it offers a philosophical judgment on the player's strategy and choices, generating a unique monologue that reflects on whether the player achieved true balance or simply dominated through one particular axis.
How we built it
Quaternion was built on a modern, robust tech stack designed for performance and scalability, with a modular architecture to support its complex AI integrations.
Tech Stack:
- Frontend & Game Engine: React, TypeScript, and Phaser 3. We used Vite for a fast and modern development environment.
- Backend & Database: A lightweight backend using Express.js, with Supabase and PostgreSQL for data persistence, user management, and real-time multiplayer features.
- AI & Machine Learning:
- Google AI (Gemini): Used for all major LLM tasks, including procedural world generation, lore creation, AI commander decision-making, and the philosophical judgments of the Quaternion Core.
- ElevenLabs: Integrated for real-time, emotionally-modulated text-to-speech for the AI advisors.
- Fuser API (Conceptual): The architecture is designed to integrate with a music generation API like Fuser to create the adaptive soundtrack.
Architecture:
The game is built around a decoupled architecture that separates the game logic, rendering, and AI systems. The AIIntegrationManager serves as the central nervous system, coordinating between the game state and the various external AI APIs. A hybrid fixed/variable timestep game loop ensures that game logic remains deterministic and performant, while rendering is smooth and responsive.
We implemented a series of specialized AI managers, each responsible for a specific creative task:
-
AIWorldGenerator.ts: Interfaces with Google AI to turn text prompts into structured map data. -
AdaptiveCommanderAI.ts: Manages the personalities and strategic learning of AI opponents. -
AIVoiceController.ts: Handles the real-time TTS generation and emotional modulation. -
AdaptiveMusicMixer.ts: Translates game state metrics into parameters for the music generation engine. -
LoreEngine.ts: Generates and manages the dynamic world chronicles and events. -
QuaternionCore.ts: The meta-AI that performs the post-game analysis and delivers the final judgment.
Challenges we ran into
Building a game of this complexity in a short timeframe presented numerous challenges:
Game Loop and Initialization: Our biggest technical hurdle was a critical race condition in our game's initialization. We discovered that our custom game loop, which relied on
requestAnimationFrame, was being instantiated multiple times, and the coreGameState.start()function was being called in three different places. This created competing animation loops, causing the game to freeze or crash, especially in browser-based deployment environments like Lovable. We had to refactor the entire initialization sequence, add browser-environment safety checks, and implement a singleton pattern to ensure the game loop and game state were started only once.Integrating Disparate AI Systems: We were working with multiple AI APIs (LLM, TTS, Music), each with its own latency, rate limits, and data formats. Orchestrating these into a cohesive, real-time experience was a major challenge. We had to build robust fallback systems for when an API call failed or was too slow, ensuring the game remained playable even if, for example, an AI advisor's dialogue was delayed.
Balancing the Unbalanceable: The core mechanic of the game is the balance of four resources. Designing and balancing a system where players are encouraged to find equilibrium, while still allowing for diverse and viable strategies focused on a single resource, was incredibly difficult. It required countless hours of playtesting and tweaking of resource generation rates, unit costs, and the AI's response to different strategies.
From Stub to Full Implementation: The initial codebase, while architecturally sound, was largely a collection of stubs and interfaces. We had to build out the concrete implementations for nearly every core system, from the resource manager to the unit controller, all while simultaneously integrating the complex AI features.
Accomplishments that we're proud of
Despite the challenges, we are incredibly proud of what we've accomplished with Quaternion:
AI as a Creative Partner: We successfully created a game where AI is not just an obstacle, but a core part of the creative process. From the world you play in, to the story that unfolds, to the music you hear, AI is a constant, dynamic presence. This, we believe, is a significant step forward in the use of AI in interactive entertainment.
The Quaternion Core: We are particularly proud of the meta-AI judge. It elevates the game from a simple RTS to a philosophical sandbox. The fact that the game analyzes your playstyle and offers a thoughtful, AI-generated critique on your chosen philosophy is, in our opinion, our most innovative feature.
Emergent Narrative and Emotional Resonance: The combination of the dynamic lore engine and the emotionally-reactive AI advisors creates a powerful sense of immersion. The game feels alive and responsive in a way that pre-scripted narratives simply cannot match. When the Bio-Advisor's voice cracks with panic as you over-harvest the last patch of alien forest, it creates a genuine emotional connection.
Technical Resilience: Overcoming the critical game loop bug was a major accomplishment. It forced us to deeply understand the intricacies of the browser rendering pipeline and build a much more robust and resilient game architecture. The final product is stable, performant, and deployable.
What we learned
This project was a massive learning experience for our team:
The Devil is in the Initialization: We learned the hard way that a solid architecture is only as good as its initialization sequence. Race conditions, especially in a complex system with multiple asynchronous parts, can be incredibly difficult to debug and can lead to catastrophic failures.
The Importance of Fallbacks: When working with external APIs, especially in a real-time application, you have to design for failure. Every AI integration in Quaternion is now built with a fallback system, ensuring that the game remains a fun and functional experience even if the AI services are unavailable.
The Power of a Modular Architecture: Our initial decision to build a highly modular, decoupled architecture paid off immensely. It allowed us to work on different systems in parallel and made it possible to debug and fix the critical initialization bug without having to rewrite the entire game.
AI is a Design Tool, Not a Magic Bullet: We learned that integrating AI effectively requires a deep understanding of both the technology and the design goals. We couldn't just "add AI." We had to carefully consider where and how AI could enhance the player experience, and then build the systems to support that vision.
What's next for Quaternion Strategy Game
We are incredibly excited about the future of Quaternion. This hackathon is just the beginning. Our roadmap includes:
Expanding the AI's Creative Capabilities: We plan to give the AI even more control over the game world, allowing it to dynamically create new units, buildings, and technologies based on the evolving narrative and the player's actions.
True Multiplayer with AI Teammates: We will build out the multiplayer functionality, allowing players to team up with or compete against the adaptive AI commanders. Imagine a co-op mode where your teammate is an AI with its own personality, goals, and evolving strategy.
Deeper Narrative Integration: We want to expand the lore engine to create multi-game story arcs, where the Quaternion Core's judgments and the player's moral choices in one game have lasting consequences in the next.
Community-Driven Content: We plan to build a platform where players can share their favorite AI-generated maps, lore, and even their favorite AI commander personalities. We envision a thriving ecosystem of community-created content, all powered by the game's core AI systems.
Quaternion is more than just a game; it's a platform for exploring the future of interactive, AI-driven entertainment. We believe we've only scratched the surface of what's possible, and we can't wait to continue this journey.
Built With
- dreamina
- eleven
- elevenlabs
- fuser
- googleaistudio
- imagineart
- ltxstudio

Log in or sign up for Devpost to join the conversation.