- Moved 20 root-level markdown files to readmes/ - Includes COMMANDS.md, CONFIG_README.md, all UNO docs, all completion reports - Added new: MEMORY_EDITOR_FEATURE.md, MEMORY_EDITOR_ESCAPING_FIX.md, CONFIG_SOURCES_ANALYSIS.md, MCP_TOOL_CALLING_ANALYSIS.md, and others - Root directory is now clean of documentation clutter
6.2 KiB
Miku UNO Bot Integration - Setup Guide
Overview
Miku can now play UNO using a combination of:
- Playwright: Headless browser automation to join and play the game
- LLM Integration: Strategic decision-making with Miku's personality
- Discord Commands: Easy interface for starting/joining games
Files Created
bot/commands/uno.py- Discord command handlerbot/utils/uno_game.py- Core game automation (MikuUnoPlayer class)bot/bot.py- Updated to route !uno commands
Prerequisites
1. Install Playwright Browsers
Playwright requires browser binaries to be installed:
# Inside the bot container or virtual environment
python -m playwright install chromium
Or if you need all browsers:
python -m playwright install
2. Verify UNO Server is Running
Make sure both UNO game servers are running:
# Terminal 1 - Backend (port 5000)
cd /home/koko210Serve/docker/uno-online
node server.js
# Terminal 2 - Frontend (port 3002)
cd /home/koko210Serve/docker/uno-online/client
npm start
Discord Commands
Create a New Game
!uno create
- Miku creates a new UNO room and joins as Player 2
- Returns room code for you to join
- Automatically starts playing when you join
Join an Existing Game
!uno join ABC123
- Miku joins room ABC123 as Player 2
- Starts playing automatically
List Active Games
!uno list
- Shows all active UNO games Miku is currently playing
Quit a Game
!uno quit ABC123
- Makes Miku leave the specified game
Help
!uno help
- Shows all available UNO commands
How It Works
Game Flow
- User sends command:
!uno createor!uno join <code> - Playwright launches: Headless Chromium browser opens
- Navigation: Bot navigates to game URL (http://192.168.1.2:3002)
- Join room: Enters room code and joins as Player 2
- Game loop starts: Polls game state every 2 seconds
- Turn detection: Checks if it's Miku's turn
- LLM decision: Prompts Miku's LLM with game state for strategy
- Action execution: Sends JSON action to game via HTTP API
- Trash talk: Sends personality-driven message to Discord
- Repeat: Loop continues until game ends
LLM Strategy System
When it's Miku's turn, the bot:
- Gets current game state (hand, top card, opponent cards)
- Builds a strategic prompt with:
- Current game situation
- Available cards in hand
- Strategic advice (color matching, special cards, etc.)
- JSON format requirements
- Gets Miku's decision from LLM
- Validates and executes the action
Personality Integration
Miku trash talks based on card type:
- Draw 4: "Take four cards! 💙✨ I hope you're ready for a comeback~"
- Draw 2: "Draw two cards! Don't worry, I still believe in you~ ✨"
- Skip: "Sorry~ Skipping your turn! Maybe next time? 🎶"
- Wild: "I'm changing the color! Let's see how you handle this~ 💫"
- Regular cards: "Playing my card~ Let's keep this fun! 🎵"
Configuration
Server URLs
Located in bot/utils/uno_game.py:
UNO_SERVER_URL = "http://localhost:5000" # Backend API
UNO_CLIENT_URL = "http://192.168.1.2:3002" # Frontend URL
Adjust these if your setup is different.
Polling Interval
Game state is checked every 2 seconds:
POLL_INTERVAL = 2 # seconds
You can adjust this in uno_game.py if needed.
Testing
1. Quick Test
# Start both UNO servers first
# In Discord, type:
!uno create
# You'll get a response like:
# "🎮 Created UNO room: ABC123
# Join at: http://192.168.1.2:3002
# I'm joining now as Player 2! ✨"
# Open that URL in your browser and join
# Miku will start playing automatically
2. Check Logs
Watch bot logs for:
[UNO]- Game actions and status[MikuUnoPlayer]- Detailed game loop info- LLM prompts and responses
- Trash talk messages
3. Manual Testing
You can still test the JSON action API directly:
# Get game state
curl http://localhost:5000/api/game/ABC123/state | jq
# Send bot action
node test-bot-action.js ABC123 '{"action":"draw"}'
Troubleshooting
Browser Not Found
Error: playwright._impl._api_types.Error: Executable doesn't exist
Solution:
python -m playwright install chromium
Bot Not Responding to Commands
Check:
- Is bot.py running?
- Check bot logs for errors
- Try
!uno helpto verify command is loaded
Game Not Starting
Check:
- Are both UNO servers running? (ports 5000 and 3002)
- Can you access http://192.168.1.2:3002 in browser?
- Check server logs for errors
Miku Not Making Moves
Check:
- Is it actually Miku's turn? (Player 2)
- Check bot logs for LLM errors
- Verify game state is being fetched correctly
- Check if LLM is returning valid JSON
Invalid JSON from LLM
The bot validates LLM output. If invalid:
- Bot will log the error
- May attempt to draw a card as fallback
- Check LLM prompt in
build_strategy_prompt()
Architecture
HTTP API (Game Server)
GET /api/game/:roomCode/state- Get game statePOST /api/game/:roomCode/action- Send bot action
WebSocket Events (Optional)
botActionReceived- Triggers action execution in client- Not currently used by Playwright approach
Playwright Automation
- Headless Chromium browser
- Navigates to game URL
- No actual UI interaction needed (uses HTTP API)
- Browser is just for joining the room
Future Enhancements
Discord Activity Integration (Phase 2)
After testing is complete, we can convert this to a proper Discord Activity:
- Package as Discord Activity
- Use Discord's activity APIs
- Embed directly in Discord
- No external browser needed
Improvements
- Better error recovery
- Multiple concurrent games
- Difficulty levels (aggressive vs casual play)
- Statistics tracking
- Tournament mode
Documentation References
BOT_ACTION_SPEC.md- JSON action format specificationQUICK_START_BOT.md- Quick start for manual testingBOT_INTEGRATION_COMPLETE.md- Full integration details
Need Help?
Check the logs first:
# Bot logs
tail -f bot.log
# UNO server logs
# (in terminal where server.js is running)
Look for [UNO] or [MikuUnoPlayer] tags for game-specific logs.