# MUD AI Player An autonomous AI player for MUD (Multi-User Dungeon) text-based games. ## Features - ๐Ÿค– **Autonomous Gameplay**: Simulates a human player from character creation to endgame - ๐Ÿ—บ๏ธ **Auto-Mapping**: Builds a complete map of the MUD world with hybrid storage (SQLite + Memvid) - โš”๏ธ **Combat AI**: Intelligent combat decisions, target selection, and survival tactics - ๐Ÿ“œ **Quest System**: Automatically detects, plans, and completes quests - ๐Ÿ” **Semantic Search**: Find locations using natural language queries with configurable embedding models (MiniLM, MPNet, Gemma) - ๐Ÿ“Š **Progression Optimizer**: Finds optimal grinding spots and equipment upgrades - ๐Ÿง  **LLM Integration**: Context-aware responses to players using local LLMs (Ollama) - ๐ŸŒ **Web Dashboard**: Real-time monitoring dashboard with WebSocket updates - ๐Ÿ‘ค **Human Behavior**: Simulates realistic reaction times and behavior patterns ## Architecture The application is built with a modular architecture: - **Core**: Telnet client, ANSI parser, text parser, game state - **Modules**: - Character Creator: Stats rolling, class/race selection - Auto-Mapper: World mapping with hybrid storage (SQLite + Memvid) - Decision Engine: AI decision-making, combat AI, goal management - Quest System: Quest detection, planning, execution - Progression Optimizer: Grinding optimization, equipment analysis - LLM Integration: Ollama/OpenAI-compatible LLM client with memory - Web Dashboard: FastAPI-based monitoring with WebSocket support ## Installation ### Using Poetry (Recommended) ```bash # Install Poetry if not already installed pip install poetry # Install dependencies poetry install # Activate virtual environment poetry shell ``` ### Using pip ```bash # Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt ``` ## Configuration 1. Copy the example configuration: ```bash cp examples/config.example.yaml config.yaml ``` 2. Edit `config.yaml` with your MUD server details: ```yaml mud: host: "your-mud-server.com" port: 4000 username: "your_username" password: "your_password" ``` ## Usage ```bash # Run the AI player python -m src.main # Run with custom config python -m src.main --config custom_config.yaml # Run tests pytest tests/ -v # Run with coverage pytest --cov=src --cov-report=html ``` ## Project Structure ``` mud-ai-player/ โ”œโ”€โ”€ src/ # Source code (~7,500 lines) โ”‚ โ”œโ”€โ”€ core/ # Core components โ”‚ โ”‚ โ”œโ”€โ”€ telnet_client.py # Async telnet connection โ”‚ โ”‚ โ”œโ”€โ”€ game_state.py # Game state management โ”‚ โ”‚ โ”œโ”€โ”€ ansi_parser.py # ANSI color code parsing โ”‚ โ”‚ โ””โ”€โ”€ parsers/ # MUD-specific parsers โ”‚ โ”œโ”€โ”€ modules/ # Specialized modules โ”‚ โ”‚ โ”œโ”€โ”€ mapper/ # World mapping (SQLite + Memvid) โ”‚ โ”‚ โ”œโ”€โ”€ decision/ # AI decision engine โ”‚ โ”‚ โ”œโ”€โ”€ llm/ # LLM integration โ”‚ โ”‚ โ”œโ”€โ”€ character/ # Character creation โ”‚ โ”‚ โ”œโ”€โ”€ quest/ # Quest management โ”‚ โ”‚ โ”œโ”€โ”€ progression/ # Grinding optimizer โ”‚ โ”‚ โ””โ”€โ”€ web/ # Monitoring dashboard โ”‚ โ”œโ”€โ”€ utils/ # Utilities โ”‚ โ””โ”€โ”€ config/ # Configuration management โ”œโ”€โ”€ data/ # Persistent storage โ”‚ โ”œโ”€โ”€ maps/ # World maps (SQLite + Memvid) โ”‚ โ”œโ”€โ”€ characters/ # Character saves โ”‚ โ””โ”€โ”€ logs/ # Game logs โ”œโ”€โ”€ tests/ # Test suite (17 files, ~2,500 lines) โ”œโ”€โ”€ docs/ # Documentation โ”‚ โ”œโ”€โ”€ architecture.md # System architecture โ”‚ โ”œโ”€โ”€ configuration.md # Configuration guide โ”‚ โ”œโ”€โ”€ development.md # Development guide โ”‚ โ””โ”€โ”€ api_reference.md # API reference ``` ## Web Dashboard The AI player includes a real-time web dashboard for monitoring: ```yaml monitoring: enabled: true host: "127.0.0.1" port: 8080 ``` ## ๐ŸŽฎ Autonomous Mode **Modalitร  completamente autonoma** dove il bot esplora, impara e cresce da solo guidato dall'LLM: ```bash # Avvia esplorazione autonoma per 60 minuti python -m src.autonomous_mode --duration 60 # Con config personalizzata python -m src.autonomous_mode --config my_config.yaml --duration 120 ``` **Caratteristiche:** - ๐Ÿค– **LLM-First**: L'LLM prende tutte le decisioni strategiche - ๐Ÿ—บ๏ธ **Auto-Mapping**: Esplora e mappa automaticamente il mondo - ๐Ÿง  **Learning**: Memorizza stanze pericolose, NPC utili, pattern - ๐Ÿ“Š **Session Logging**: Salva tutto in `data/autonomous_sessions/` - ๐ŸŽฏ **Goal Dinamici**: Obiettivi di esplorazione e crescita - ๐Ÿ›ก๏ธ **Safety First**: Override automatico se HP critici **Esempio di output:** ``` ๐Ÿš€ Avviata sessione autonoma: session_20240209_143022 ๐Ÿง  Decisione LLM: [explore] north Ragionamento: Uscita non esplorata, pericolo basso ๐Ÿ” Scoperta: [room] Village Square: You are standing in... ๐Ÿ“„ Log completo: data/autonomous_sessions/session_20240209_143022.json ``` ## Configurable Embedding Models Choose the best embedding model for semantic room search: ```yaml mapper: semantic_search: # Available models: # - "sentence-transformers/all-MiniLM-L6-v2" (fast, 22MB) - default # - "sentence-transformers/all-mpnet-base-v2" (better quality, 418MB) # - "google/embeddinggemma-300m" (state-of-the-art, ~300MB) model: "google/embeddinggemma-300m" ``` | Model | Size | Speed | Quality | Use Case | |-------|------|-------|---------|----------| | **all-MiniLM-L6-v2** | 22MB | โญโญโญโญโญ | โญโญโญ | Low resource, fast queries | | **all-mpnet-base-v2** | 418MB | โญโญโญ | โญโญโญโญ | Better accuracy, balanced | | **google/embeddinggemma-300m** | ~300MB | โญโญโญโญ | โญโญโญโญโญ | Best quality, requires transformers>=4.40 | Access the dashboard at `http://127.0.0.1:8080` **Features:** - Real-time character vitals (HP/MP/SP) - Current room information with NPCs and items - Active goals and AI state - Map statistics (rooms discovered, exits mapped) - Event log with game events - WebSocket updates (no page refresh needed) ## Development ```bash # Format code black src/ tests/ # Lint code ruff check src/ tests/ # Run tests with watch pytest-watch ``` ## Documentation See the `docs/` directory for detailed documentation: - [Architecture](docs/architecture.md) - [Configuration Guide](docs/configuration.md) - [Development Guide](docs/development.md) - [API Reference](docs/api_reference.md) ## License MIT License ## Contributing Contributions are welcome! Please read the development guide before submitting PRs. ## Disclaimer This is an educational project. Please respect the rules and terms of service of any MUD you connect to. Some MUDs prohibit automated players.