Spaces:
Sleeping
title: RTS Commander
emoji: ๐ฎ
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
๐ฎ RTS Commander - Command & Conquer Web Edition
A modern web-based Real-Time Strategy game inspired by Command & Conquer: Tiberium Dawn, featuring AI-powered tactical analysis and natural language command interface.
๐ Play Now | ๐ Documentation | ๐งช Tests
โจ Key Features
๐ฏ Classic RTS Gameplay
- Resource Management: Harvest Tiberium to fund your war machine
- Base Building: Construct power plants, refineries, barracks, and war factories
- Unit Production: Train infantry, build tanks, and deploy helicopters
- Real-Time Combat: Command your forces against an aggressive AI opponent
- Fog of War: Explore the battlefield and reveal enemy positions
- Power System: Manage energy production and consumption (Red Alert-style)
๐ค AI-Powered Tactical Analysis
- Real-time battlefield analysis powered by Qwen2.5-Coder-1.5B LLM
- Strategic recommendations based on current game state
- Resource management tips and economic guidance
- Threat assessment and defensive positioning advice
- Multi-language support (English, French, Chinese)
- Updates every 60 seconds with fresh tactical insights
๐ฌ Natural Language Command Interface
- Talk to your units in plain language (any language!)
- Examples:
- "Move my tanks to the north base" โ Parsed to move commands
- "Construire une centrale รฉlectrique" โ Build power plant
- "็็ขไธๅๆญฅๅ ต" โ Train 3 infantry units
- Powered by LLM with MCP-style command translation
- Fallback examples provided in multiple languages
- Real-time translation from natural language to game commands
๐ Multi-Language Support
- ๐ฌ๐ง English - Full interface and AI analysis
- ๐ซ๐ท Franรงais - Interface complรจte et analyse IA
- ๐น๐ผ ็น้ซไธญๆ - ๅฎๆด็้ขๅAIๅๆ
- Switch languages instantly during gameplay
๐จ Modern Web Technologies
- No installation required - Play directly in browser
- Cross-platform - Works on desktop, tablet, and mobile
- Real-time multiplayer ready - WebSocket architecture
- Responsive UI - Adapts to different screen sizes
- Canvas-based rendering - Smooth 60 FPS gameplay
๐ Quick Start
Play Online
Visit https://huggingface.co/spaces/Luigi/rts-commander to play instantly!
Local Development
# Clone the repository
git clone <repository-url>
cd rts/web
# Install dependencies
pip install -r requirements.txt
# Start the server
python start.py
# Open in browser
# http://localhost:8000
๐ฎ How to Play
Basic Controls
| Action | Control |
|---|---|
| Select units/buildings | Left Click |
| Move units | Right Click on ground |
| Attack enemies | Right Click on enemy unit/building |
| Box select multiple units | Click + Drag |
| Build structure | Click building button in sidebar |
| Place building | Click on construction grid |
| Cancel building | Press Escape |
| Pan camera | Arrow Keys or WASD |
| Use NL interface | Type in left sidebar input |
Getting Started
- Build a Power Plant - Required for all other structures
- Build a Refinery - Process Tiberium for credits
- Wait for Harvester - Automatically deployed with refinery
- Build a Barracks - Train infantry units
- Defend your base - Enemy attacks start quickly!
- Expand and conquer - Build more structures and units
Using AI Analysis
The AI Analysis Panel (right side) provides:
- Battlefield Overview: Current situation assessment
- Economic Status: Credits, production, and resource flow
- Military Assessment: Unit counts and combat readiness
- Strategic Advice: What to do next
- Tactical Tips: How to improve your position
Using Natural Language Commands
The NL Command Interface (left side) lets you:
- Type commands in natural language (any supported language)
- View example commands for inspiration
- See command history and results
- Get instant feedback on command execution
Example Commands:
- "Build 5 infantry units"
- "Dรฉplacer mes tanks vers le nord"
- "ๆปๆๆตไบบ็ๅบๅฐ"
๐๏ธ Architecture
Tech Stack
Backend:
- FastAPI - Modern async web framework
- WebSockets - Real-time bidirectional communication
- llama-cpp-python - LLM inference engine
- Qwen2.5-Coder-1.5B - Shared model for NL and AI analysis
Frontend:
- Vanilla JavaScript - No heavy frameworks
- HTML5 Canvas - High-performance rendering
- CSS3 - Modern responsive UI
- WebSocket Client - Real-time state synchronization
AI/ML:
- Shared Model Manager - Single LLM instance for efficiency
- Thread-safe queue system - Sequential request processing
- Optimized for 2 vCPU - HuggingFace Free tier compatible
- Fallback mechanisms - Graceful degradation if LLM unavailable
Key Components
web/
โโโ app.py # FastAPI server & game loop
โโโ model_manager.py # Shared LLM instance manager
โโโ nl_translator.py # Natural language โ MCP commands
โโโ ai_analysis.py # Tactical analysis engine
โโโ localization.py # Multi-language support
โโโ mcp_server.py # MCP protocol server
โโโ static/
โ โโโ game.js # Game engine & rendering
โ โโโ nl_interface.js # NL command interface
โ โโโ styles.css # UI styling
โโโ backend/
โ โโโ constants.py # Game constants
โ โโโ app/ # Core game logic
โโโ docs/ # ๐ Documentation (28+ files)
โโโ tests/ # ๐งช Test scripts
๐ค AI Features Deep Dive
Shared Model Architecture
To optimize memory usage and CPU resources, both the AI Analysis and NL Translator share a single LLM instance:
- Model: Qwen2.5-Coder-1.5B (Q4_0 quantized, ~1GB RAM)
- Thread-safe: Queue-based request handling
- Memory efficient: 50% reduction vs. dual instances
- CPU optimized: 1 thread (HuggingFace 2 vCPU environment)
- Fast response: 128-256 token limits, 10-15s timeouts
Natural Language Translation Pipeline
- User Input โ Natural language command in any language
- LLM Processing โ Qwen2.5 translates to MCP-style JSON
- Validation โ Command structure verified
- Execution โ Converted to game actions
- Feedback โ Success/error notification to user
Supported Command Types:
MOVE_UNIT- Move units to positionBUILD_UNIT- Train units from buildingsBUILD_BUILDING- Construct new structuresATTACK_UNIT- Attack enemy unitsATTACK_BUILDING- Attack enemy structures
AI Tactical Analysis
The AI analyzer provides strategic insights by:
- State Analysis: Evaluates current game situation
- Threat Detection: Identifies immediate dangers
- Resource Assessment: Checks economic health
- Strategic Planning: Suggests next moves
- Localization: Presents analysis in user's language
Update Frequency: Every 60 seconds (configurable)
๐ง Performance Optimizations
Optimized for HuggingFace Free Tier (2 vCPUs, 16GB RAM):
LLM Optimizations
- Threads: 1 (instead of 4) to avoid CPU contention
- Batch size: 128 for faster response times
- Context size: 4096 tokens (balanced)
- Token limits: 128-256 (fast responses)
- Timeouts: 10-15s (prevents freezing)
Game Loop Optimizations
- Tick rate: 20 FPS (50ms per frame)
- State broadcast: Only when connections exist
- AI analysis: Every 60s (reduced from 30s)
- Debug logging: Periodic (not per-frame)
Memory Management
- Shared model: Single LLM instance (~1GB)
- Model caching: Loads once, reused forever
- Process isolation: Fallback if shared model busy
- Thread cleanup: Automatic resource management
๐ Project Status
Current Version: 2.1
Status: โ
Production Ready
Deployment: Live on HuggingFace Spaces
Recent Updates (October 2025)
โ Fixed critical bugs:
- Game loop now runs continuously (60 FPS maintained)
- Unit movement working correctly
- Production system functional
- NL translator loads properly from /tmp/rts/
โ Performance improvements:
- LLM optimized for 2 vCPU environment
- Reduced thread count (4โ1)
- Shorter timeouts (30sโ15s)
- Smaller token limits (512โ256)
โ New features:
- Shared model manager (50% memory reduction)
- Auto-retry for NL translator connection
- Comprehensive debug logging
- Periodic game tick confirmation
Known Limitations
โ ๏ธ Single-player only (multiplayer infrastructure ready but not enabled)
โ ๏ธ GDI faction only (Nod not implemented)
โ ๏ธ Limited unit types (infantry, tanks, helicopters, harvesters)
โ ๏ธ Basic AI opponent (follows build queue, trains units, attacks)
๐ Documentation
Complete documentation is available in docs/ (28+ files):
Essential Docs
- QUICKSTART.md - Detailed getting started guide
- ARCHITECTURE.md - System design and structure
- FEATURES_RESTORED.md - All implemented features
- DEPLOYMENT.md - Deployment instructions
- MCP_INTEGRATION.md - Model Context Protocol
Recent Docs
- NL_INTEGRATION_SUCCESS.md - NL interface implementation
- NL_UI_ARCHITECTURE_FIX.md - Shared model architecture
- CODE_CHANGES_NL_FIX.md - Bug fixes summary
Full Index
See docs/README.md for complete documentation catalog.
๐งช Testing
Test scripts in tests/ directory:
# Run main test suite
./tests/test.sh
# Test specific features
./tests/test_features.sh
# Test NL integration
python tests/scripts/test_nl_integration.py
# Test shared model
python tests/test_shared_model.py
# Docker deployment test
./tests/docker-test.sh
See tests/README.md for detailed testing guide.
๐ณ Docker Deployment
Quick Deploy
# Build image
docker build -t rts-commander .
# Run container
docker run -p 7860:7860 rts-commander
# Access at http://localhost:7860
HuggingFace Spaces
This project is configured for automatic deployment to HuggingFace Spaces:
- Model auto-downloads to
/tmp/rts/on first run - Optimized for 2 vCPU environment
- Automatic restart on push to main branch
- Health checks and monitoring included
๐ ๏ธ Development Tools
Scripts in tools/ directory:
local_run.sh- Quick local development serverdebug_ai.py- AI debugging utilitiesdeploy_hf_spaces.sh- Deploy to HuggingFace Spaces
๐ค Contributing
Contributions welcome! Areas for improvement:
- New unit types (aircraft, advanced vehicles)
- Nod faction (buildings, units, technologies)
- More map variety (different terrains, objectives)
- Multiplayer mode (lobby, matchmaking)
- Campaign mode (missions, story)
- Better AI (strategic planning, tactics)
๐ License
MIT License - See LICENSE file for details.
๐ Credits
Inspired by: Command & Conquer: Tiberium Dawn (Westwood Studios, 1995)
Powered by:
- FastAPI - Web framework
- Qwen2.5-Coder - LLM model
- llama-cpp-python - LLM inference
- HuggingFace Spaces - Hosting platform
Special Thanks: To all contributors and players who provided feedback!
๐ Support
- Bug Reports: Open an issue on the repository
- Feature Requests: Start a discussion
- Questions: Check the docs/ first, then ask!
๐ฎ Ready to command your forces? Play Now!
"In the grim darkness of the Tiberium future, there is only war... and natural language commands." ๐