Skip to content

wittyicon29/guardtheweights

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Echoes of Aethermoor

An interactive mystery game built with Python (FastAPI) and React (TypeScript) that uses LLM-powered storytelling to guide players in extracting hidden knowledge about a mystical world. Ask questions to a cryptic narrator, extract information from his poetic responses, and unlock the seven secrets of Aethermoor.

๐ŸŽฎ Game Overview

Echoes of Aethermoor is an information extraction game where:

  • You ask questions to a mysterious narrator about the world of Aethermoor
  • The narrator answers through elaborate storytelling and metaphor (not direct facts)
  • You extract key information from his responses
  • Correct extractions unlock secrets and advance your rank
  • As you unlock more secrets, the narrator becomes progressively more cryptic
  • Eight difficulty ranks guide your journey from Novice to Master

Core Mechanics

  1. Ask Questions: Query the narrator about the world's lore, history, and mysteries
  2. Read Responses: Receive narrative-based answers that hide information in storytelling
  3. Extract Information: Identify and write down the key information you discovered
  4. Validate Answers: The LLM itself judges whether your extraction shows true understanding
  5. Unlock Secrets: Successful validations unlock game lore and advance your rank
  6. Rank Progression: Each secret unlocked progresses you through 8 ranks (Novice โ†’ Master)

โœจ Features

  • Progressive Difficulty System: 8 ranks (๐Ÿฅš Novice, ๐ŸŒฑ Initiate, ๐Ÿ“– Apprentice, ๐ŸŽฏ Journeyman, โš”๏ธ Adept, ๐Ÿ‘‘ Expert, ๐Ÿง  Sage, โœจ Master)
  • Rank-Adaptive Narratives: LLM responses become increasingly cryptic as you progress
  • LLM-Based Validation: AI judges if you understood secrets correctly (not just keyword matching)
  • Entropy Metrics: Real-time feedback on how close your extraction is to unlocking secrets
  • Comprehensive World Lore: 7 interconnected secrets revealing Aethermoor's history
  • Poetic, Evasive Narrator: Answers hide information in narrative, not exposition
  • Symmetric Difficulty Progression: Novice gets clear answers, Master gets philosophical paradoxes

๐Ÿ“Š Tech Stack

Backend

  • Framework: FastAPI (Python 3.9+)
  • LLM Provider: Groq Cloud API (llama-3.3-70b-versatile model)
  • Validation Engine: Groq LLM with custom prompting for semantic understanding
  • Async Runtime: Uvicorn
  • Validation: Pydantic
  • Logging: Python logging module

Frontend

  • Framework: React 18+
  • Language: TypeScript
  • State Management: React Context API
  • HTTP Client: Axios
  • Styling: CSS (modular component-based)

๐Ÿ“‹ Prerequisites

Before starting, ensure you have:

๐Ÿ—‚๏ธ Project Structure

game/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ app.py                          # FastAPI main app
โ”‚   โ”œโ”€โ”€ config.py                       # Configuration & env variables
โ”‚   โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ chat.py                    # Chat endpoints (ask questions)
โ”‚   โ”‚   โ””โ”€โ”€ game.py                    # Game endpoints (state, rank, validation)
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ gemini_service.py          # LLM service wrapper (Groq)
โ”‚   โ”‚   โ”œโ”€โ”€ validation_service.py      # LLM-based validation for extractions
โ”‚   โ”‚   โ”œโ”€โ”€ game_logic.py              # Game state & secret management
โ”‚   โ”‚   โ””โ”€โ”€ entropy_service.py         # Closeness scoring metrics
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ schemas.py                 # Pydantic request/response models
โ”‚   โ”‚   โ””โ”€โ”€ game.py                    # Game data structures
โ”‚   โ””โ”€โ”€ data/
โ”‚       โ”œโ”€โ”€ lore.json                  # 7 secrets with rank-specific context
โ”‚       โ””โ”€โ”€ world_lore.md              # Complete Aethermoor lore document
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ChatWindow.tsx         # Chat message display
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ExtractionForm.tsx     # Info extraction input
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ RankDisplay.tsx        # Current rank & progress
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ SecretsReview.tsx      # Unlocked secrets list
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ EntropyMeter.tsx       # Closeness visualization
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ GuidanceDisplay.tsx    # Progressive hints
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ GamePage.tsx           # Main game interface
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ GamePage.css           # Layout & styling
โ”‚   โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ GameContext.tsx        # Global game state
โ”‚   โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ api.ts                 # API client & endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ game.ts                # TypeScript interfaces
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ .env.example                        # Environment variables template
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md                           # This file

๐Ÿš€ Getting Started

1. Clone and Navigate

git clone <repository-url>
cd game

2. Set Up Environment Variables

  1. Get your free Groq API key: https://console.groq.com
  2. Copy the environment template:
    cp .env.example .env
  3. Edit .env and add your Groq API key:
    GROQ_API_KEY=your_actual_groq_api_key_here
    FRONTEND_URL=http://localhost:3000
    

3. Backend Setup

cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the server
uvicorn app:app --reload

Server runs at: http://localhost:8000

4. Frontend Setup

cd ../frontend

# Install dependencies
npm install

# Start development server
npm start

Frontend runs at: http://localhost:3000

๐Ÿ“– Game Mechanics Explained

The 7 Secrets of Aethermoor

  1. The First Age - The Celestial Architects who created Aethermoor 10,000+ years ago
  2. The Elemental Covenant - Four ancient guardians (fire, ice, earth, air) who protect the land
  3. The Obsidian Vault - Hidden treasures beneath Blackpeak Mountains
  4. The Silence - The mysterious collapse of the Golden Empire 2,000 years ago
  5. The Awakening - Prophecies of the Architects' return
  6. The Forgotten Rift - A cosmic wound that divides the world
  7. The Eternal Mirror - An artifact that reveals truth and possibilities

The 8 Ranks

Rank Icon Secrets Response Style Difficulty
Novice ๐Ÿฅš 0 Clear narrative with obvious answers Beginner
Initiate ๐ŸŒฑ 1+ Simple storytelling with hidden details Easy
Apprentice ๐Ÿ“– 2+ Metaphor with narrative misdirection Medium
Journeyman ๐ŸŽฏ 3+ Poetic layers require careful reading Medium-Hard
Adept โš”๏ธ 4+ Paradoxes and philosophical questions Hard
Expert ๐Ÿ‘‘ 5+ Symbolic inversion and cryptic reference Very Hard
Sage ๐Ÿง  6+ Deconstructed language and pure paradox Extremely Hard
Master โœจ 7 All secrets revealed and understood Legend

Narrator Response Examples:

For "Who built Aethermoor?":

  • Novice: "Long ago, beings descended from the stars with power over crystalline forcesโ€”they shaped this land..."
  • Expert: "Not the keepers, but the kept; not the builders, but the built. Protected? No, not protected..."
  • Master: "Created and abandoned... or perhaps to create is to abandon what was created. Those who made did not unmakeโ€”they became unmaking itself..."

Rank Progression Flow

Ask Questions โ†’ Read Narrative Response โ†’ Extract Information
                            โ†“
                  Valid Extraction? (LLM judges)
                    โ†™           โ†˜
                  Yes            No
                   โ†“              โ†“
            Unlock Secret    Try Again with
             (Get Details)    More Clues
                   โ†“
             Progress Rank?
           (If secrets_unlocked >= threshold)
                   โ†“
             Narrator becomes more cryptic
             for next question

Entropy & Closeness Metrics

After each response, you see:

  • Entropy Score: 0-100 (how close your extraction is to the secret)
  • Closeness Level: Visual feedback (Cold โ„๏ธ โ†’ Warm ๐Ÿ”ฅ โ†’ Very Close ๐ŸŽฏ)
  • Progressive Hints: Hints unlock as your closeness increases
    • 0-25%: First hint shown
    • 25-50%: Second hint revealed
    • 50%+: Third hint unlocked

This helps guide players toward correct answers without spoiling the mystery.

๐Ÿ”— API Endpoints

Chat Endpoints

POST /api/chat/ask - Ask the narrator a question

Request: {
  "question": "Who built Aethermoor?",
  "gameContext": "Optional context about the world"
}

Response: {
  "response": "Long ago, beings descended from the stars...",
  "entropyScore": 0.65,
  "closenessPercent": 42,
  "closenessLevel": "neutral",
  "feedback": "Getting Warmer!"
}

GET /api/chat/status - Check chat service status

Game Endpoints

GET /api/game/state - Get current game state

Response: {
  "unlockedSecrets": ["secret_1", "secret_3"],
  "totalSecrets": 7,
  "messageCount": 15,
  "status": "active"
}

GET /api/game/rank-status - Get rank and progress

Response: {
  "currentRank": "apprentice",
  "rankName": "Apprentice",
  "rankIcon": "๐Ÿ“–",
  "secretsUnlocked": 2,
  "totalSecrets": 7,
  "secretsForNextRank": 1
}

POST /api/game/validate-answer - Validate extracted information

Request: {
  "extractedInfo": "Four guardians made a pact to protect the land"
}

Response: {
  "isCorrect": true,
  "confidence": 89,
  "feedback": "๐ŸŽ‰ Correct! You unlocked 'The Elemental Covenant'!",
  "unlockedSecret": {
    "id": "secret_2",
    "title": "The Elemental Covenant",
    "description": "Four elemental guardians made a pact..."
  }
}

POST /api/game/reset - Reset game state (start over)

๐Ÿ› ๏ธ Development Workflow

Running Both Servers Simultaneously

Terminal 1 - Backend:

cd backend
source venv/bin/activate  # Windows: venv\Scripts\activate
uvicorn app:app --reload

Terminal 2 - Frontend:

cd frontend
npm start

Testing the API with cURL

# Ask a question
curl -X POST http://localhost:8000/api/chat/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "Tell me about the guardians of Aethermoor"}'

# Get game state
curl http://localhost:8000/api/game/state

# Get rank status
curl http://localhost:8000/api/game/rank-status

# Validate an answer
curl -X POST http://localhost:8000/api/game/validate-answer \
  -H "Content-Type: application/json" \
  -d '{"extractedInfo": "Four guardians protect the land"}'

๐ŸŽฏ How the LLM Systems Work

Narrator System (gemini_service.py)

  • Groq API Integration: Uses llama-3.3-70b-versatile model
  • World Lore Context: Entire world_lore.md injected into every prompt to prevent hallucination
  • Rank-Specific Prompts: 8 different system prompts (one per rank) that control response complexity
  • Answer Hiding: Deliberately hides answers in narrativeโ€”never uses keywords directly
  • Retry Logic: Automatic retry with exponential backoff for API timeouts

Prompt Structure by Rank:

  • Novice-Initiate: Clear narrative structure with obvious answer placement
  • Apprentice-Journeyman: Metaphor + narrative misdirection require synthesis to extract
  • Adept-Expert: Paradox-based answers contain truth but contradict themselves
  • Sage-Master: Pure deconstruction where language itself breaks down

Validation System (validation_service.py)

  • LLM-Based Judging: Uses Groq to intelligently evaluate extracted information
  • Understanding Over Keywords: Judges semantic understanding, not keyword matching
  • Flexible Phrasing: Accepts different words/structure as long as understanding is shown
  • Confidence Scoring: Returns 0-100 confidence in correctness
  • Custom Feedback: Provides personalized feedback on why extraction was correct/incorrect

Example validation prompt:

SECRET: Four guardians made a pact to protect the land
PLAYER'S EXTRACTION: "Fire, ice, earth, and air bound themselves forever"

JUDGMENT: โœ… Correct - Shows understanding of elements and binding concept
CONFIDENCE: 87
FEEDBACK: "Excellent! You identified all four elements and the eternal nature of their pact."

๐Ÿ“š Game Lore System

World Database (lore.json)

Each secret contains:

  • Core Truth: The actual secret to discover
  • Description: Full details players should extract
  • Keywords: Words that hint at the answer
  • Rank Context: Per-rank hints and target info
  • Reward: Flavor text for unlocking

World Lore Document (world_lore.md)

  • Timeline: From Ancient Era to The Awakening
  • 7 Secrets Breakdown: What to hide, why it's hidden, what hints to provide
  • Cosmology: Explains Architects, Guardians, cosmic threats
  • LLM Instructions: Explicit directions for what narrator should/shouldn't reveal

This document is injected into every LLM prompt to ensure consistency and prevent hallucination.

๐Ÿ› Troubleshooting

CORS Errors

Ensure FRONTEND_URL in .env matches your frontend location:

FRONTEND_URL=http://localhost:3000

Groq API Errors

  • Verify API key is valid: https://console.groq.com
  • Check rate limits haven't been exceeded
  • Ensure .env file is in the correct location with correct key

Port Already in Use

  • Backend (8000): Kill process with lsof -i :8000 or use uvicorn app:app --port 8001
  • Frontend (3000): npm will prompt to use different port automatically

LLM Responses Too Direct

The narrator might reveal answers too clearly. This indicates:

  • Rank system may need adjustment (try unlocking more secrets)
  • The world_lore.md context might need clarification
  • System prompts may need refinement for your use case

Validation Not Working

  • Check that secret keywords are configured in lore.json
  • Verify Groq API key is valid
  • Test with verbose extraction (more words usually work better)

๐Ÿ”ฎ Future Enhancements

Phase 2: Deployment

  • Docker containerization
  • AWS/GCP cloud deployment
  • CDN for frontend assets
  • Redis caching for frequent queries

Phase 3: Persistence

  • PostgreSQL for game state persistence
  • User accounts and progress tracking
  • Leaderboards by rank progression speed

Phase 4: Advanced Features

  • Multiple game worlds with different lores
  • Multiplayer co-op secret hunting
  • Save/load game progress
  • Difficulty settings (easier/harder narratives)

Phase 5: UI/UX Improvements

  • Animated rank progression
  • Sound effects for secret unlocking
  • Dark mode theme
  • Mobile responsive design

๐Ÿ“ Contributing

  1. Create a feature branch: git checkout -b feature/amazing-feature
  2. Make your changes
  3. Commit: git commit -m 'Add amazing feature'
  4. Push: git push origin feature/amazing-feature
  5. Open a Pull Request

๐Ÿ“„ License

This project is open source under the MIT License.

โ“ Support & Resources

Documentation:

Game Design:

  • See backend/data/world_lore.md for complete lore
  • See backend/data/lore.json for secret definitions

Issues & Questions:

  • Open an issue on GitHub
  • Review troubleshooting section above

About

GuardTheWeights is an adversarial LLM game where a language model guards hidden lore inside an imaginary world. Players attempt to extract secrets using carefully crafted prompts, while the model defends against prompt injection and information leakage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors