Spaces:
Running
title: ChatCraft
emoji: ๐ฎ
colorFrom: red
colorTo: yellow
sdk: docker
app_port: 7860
pinned: false
license: mit
storage: small
short_description: 1v1 RTS game controlled by voice via Mistral
tags:
- game
- voice
- mistral
- rts
- hackathon
- svelte
- fastapi
ChatCraft is a 1v1 real-time strategy game (inspired by StarCraft's Terran race) entirely controlled by voice. Speak your commands โ build barracks, train marines, attack the enemy โ and Mistral AI interprets them into live game actions. No mouse clicks to play, just your microphone.
๐ฎ ChatCraft
Voice-Controlled Real-Time Strategy Game
Mistral ร ElevenLabs Hackathon โ Command your army. With your voice.
A 1v1 real-time strategy game entirely controlled by voice. Inspired by StarCraft's Terran race โ playable on mobile with just a microphone.
๐ฏ Concept
"Build barracks, train 4 marines, attack the enemy base"
Speak. Command. Conquer.
The AI (Mistral) interprets your natural language orders and translates them into real-time game actions. Voice feedback from the game ("Construction complete", "Under attack!") is delivered instantly via the Web Speech API.
Touch / mouse is only used to navigate the map, inspect units or techs โ never to play.
โก Tech Stack
| Layer | Technology |
|---|---|
| ๐ฅ๏ธ Frontend | SvelteKit + socket.io-client |
| โ๏ธ Backend | FastAPI + python-socketio (asyncio) |
| ๐ง Command AI | Mistral API (mistral-large-latest) |
| ๐๏ธ Voice โ Text | Voxtral (voxtral-mini-latest) |
| ๐ Text โ Voice | Web Speech API (browser, instant, free) |
| โ๏ธ Hosting | Hugging Face Spaces (Docker) |
๐ฃ๏ธ Voice Command Flow
๐ค [Player holds PTT]
โ
โผ
MediaRecorder (browser)
โ audio blob
โผ
Socket.IO โโvoice_inputโโโบ backend
โ
โผ
๐ค Voxtral STT
"train 3 marines"
โ
โผ
โจ Mistral API (system prompt = game state)
โ { action: "train", unit: "marine", count: 3 }
โ
โผ
engine.apply_command()
โ
โโโโโโโโโดโโโโโโโโ
โผ โผ
game_state feedback_text
broadcast "Training 3 marines started"
โ โ
โผ โผ
โโโgame_updateโโ ๐ Web Speech API (browser)
๐บ๏ธ Game โ Simplified Terran Race
๐ Resources
| Resource | Source | Usage |
|---|---|---|
| ๐ต Minerals | Patches collected by SCV | Everything |
| ๐ข Vespene Gas | Geysers collected by SCV | Advanced units, upgrades |
| ๐ฅ Supply | Supply Depots + Command Center | Population cap |
๐๏ธ Buildings
| Building | Prerequisite | Role |
|---|---|---|
| ๐๏ธ Command Center | โ | Starting building, produces SCV |
| ๐ฆ Supply Depot | โ | +8 supply |
| ๐ช Barracks | โ | Marine, Medic |
| ๐ง Engineering Bay | Barracks | Infantry upgrades |
| ๐ญ Factory | Barracks | Goliath, Tank |
| โ๏ธ Armory | Factory | Vehicle upgrades |
| ๐ Starport | Factory | Wraith |
โ๏ธ Units
| Unit | Cost | Prerequisite | Role |
|---|---|---|---|
| ๐จ SCV | 50m | CC | Gathering, construction |
| ๐ช Marine | 50m | Barracks | Basic infantry, anti-air |
| ๐ Medic | 50m / 25g | Barracks + Academy* | Heals infantry |
| ๐ค Goliath | 100m / 50g | Factory | Anti-air + ground |
| ๐ฃ Siege Tank | 150m / 100g | Factory + Machine Shop* | Ground DPS, siege mode |
| โ๏ธ Wraith | 150m / 100g | Starport | Air, cloaking |
*simplified: add-ons replaced by simple building prerequisites
๐ค Voice Command Examples
"Build a supply depot near the command center"
"Train four marines"
"Send all marines to attack top-left"
"Put the tank in siege mode"
"Patrol the wraiths around my base"
"How much gas do I have?"
"Scout with an SCV toward the center"
๐ฎ Core Game Rules
- ๐ฅ๏ธ HUD layout: resources top-left, production top-right, timer center; minimap bottom-left; control groups bottom-center and right; voice/text commands on the right.
- ๐ซ๏ธ Fog of war: visibility based on the player's units and buildings (vision radii per type); explored but not visible areas semi-transparent, never-seen areas in black.
- ๐บ๏ธ Minimap: 40ร40 map representation with fog, main map viewport, click to recenter.
- ๐ฏ Control groups: 3 groups; add/remove units or buildings, or create empty; unified representation by icons (buildings, technologies, units).
๐ Local Setup
# 1. Environment variables
cp .env.example .env
# Fill in MISTRAL_API_KEY
# 2. Backend
cd backend
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
# 3. Frontend
cd frontend
npm install
npm run dev
๐ Environment Variables
| Variable | Description |
|---|---|
MISTRAL_API_KEY |
Mistral API key (Voxtral STT + mistral-large chat) |
SECRET_KEY |
Key to sign lobby sessions |
๐๏ธ Project Architecture
hackaton/
โโโ Dockerfile # HF Spaces โ exposes port 7860
โโโ docker-compose.yml # Local dev
โ
โโโ backend/
โ โโโ main.py # FastAPI + Socket.IO entry point
โ โโโ lobby/manager.py # Room creation / joining, matchmaking
โ โโโ game/
โ โ โโโ engine.py # Game loop (tick ~250ms)
โ โ โโโ state.py # GameState: resources, units, buildings
โ โ โโโ units.py # Marine / Medic / Goliath / Tank / Wraith / SCV
โ โ โโโ buildings.py # Command Center / Barracks / Factoryโฆ
โ โ โโโ tech_tree.py # Build prerequisites
โ โ โโโ map.py # Grid + A* pathfinding
โ โโโ voice/
โ โโโ stt.py # Voxtral STT: audio โ text
โ โโโ command_parser.py # Mistral: text + game state โ actions
โ
โโโ frontend/
โโโ src/
โโโ routes/
โ โโโ +page.svelte # Lobby
โ โโโ game/+page.svelte # Main game view
โโโ lib/
โโโ socket.ts # socket.io-client singleton
โโโ voice.ts # PTT mic capture โ backend
โโโ components/
โโโ Map.svelte # Scrollable/zoomable SVG map
โโโ ResourceBar.svelte # Minerals / Gas / Supply
โโโ VoiceButton.svelte # Push-to-talk button
๐ง Design Notes
- python-socketio with asyncio is chosen for room management โ it natively handles rooms, namespaces and reconnection out of the box.
- The game loop runs server-side (tick every 250ms). Clients receive a full state snapshot each tick โ no client-side reconciliation.
- Mistral receives a summary of the player's current state (resources, active buildings, supply) as system context for consistent command interpretation.
- PTT (push-to-talk) avoids false positives on mobile and reduces latency by limiting audio chunk size.