Spaces:
Runtime error
Runtime error
File size: 8,902 Bytes
07ed12b 15f5def 9930fa0 4df477d 07ed12b 15f5def 29a88f8 ba8b1b9 920f9a0 07ed12b 920f9a0 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 5c0862e 9930fa0 5c0862e 9930fa0 5c0862e 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 98d62d6 07ed12b 9930fa0 07ed12b 244fb73 98d62d6 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 98d62d6 9930fa0 07ed12b 9930fa0 98d62d6 9930fa0 98d62d6 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 07ed12b 9930fa0 98d62d6 07ed12b 9930fa0 4665d9f 9930fa0 4665d9f 9930fa0 4665d9f 9930fa0 4665d9f 9930fa0 07ed12b 9930fa0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | ---
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.
<div align="center">
# ๐ฎ ChatCraft
### Voice-Controlled Real-Time Strategy Game
[](https://mistral.ai)
[](https://elevenlabs.io)
[](https://huggingface.co/spaces)
[](https://kit.svelte.dev)
[](https://fastapi.tiangolo.com)
> **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.*
</div>
---
## ๐ฏ 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
```bash
# 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.
|