/wordfeud-player

API for analyzing Wordfeud board screenshots

Primary LanguagePython

๐ŸŽฎ Wordfeusk - Wordfeud Board Analyzer ๐Ÿ”

๐Ÿš€ A powerful FastAPI-based service for analyzing Wordfeud board screenshots using computer vision and OCR techniques. This project helps players analyze their Wordfeud game state through screenshot processing and provides a web interface for easy interaction.

โœจ Features

  • ๐Ÿ“ธ Screenshot analysis with OpenCV and Tesseract OCR
  • ๐ŸŽฏ Board state recognition and visualization
  • ๐ŸŽฒ Rack letter detection
  • ๐ŸŒ Modern web interface for uploads
  • โšก Async processing for long-running tasks
  • ๐Ÿ”„ Real-time status updates

๐Ÿ“‹ Prerequisites

๐Ÿ’ป System Requirements

  • ๐Ÿ Python 3.10 or higher
  • ๐Ÿ”  Tesseract OCR

๐Ÿ› ๏ธ Installing Tesseract

๐ŸŽ macOS
brew install tesseract

For other platforms, see Tesseract documentation.

๐Ÿ“ฆ Python Dependencies

numpy==1.24.3
opencv-python==4.8.1.78
packaging==24.2
pillow==11.0.0
pytesseract>=0.3.10
matplotlib==3.8.2
fastapi==0.109.1
python-multipart==0.0.6
uvicorn==0.27.0
jinja2==3.1.3

๐Ÿš€ Installation

  1. ๐Ÿ“ฅ Clone the repository:
git clone https://github.com/martinkallstrom/wordfeud-player.git
cd wordfeud-player
  1. ๐ŸŒ Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. โšก Install dependencies:
pip install -r requirements.txt

๐ŸŽฏ Usage

๐Ÿš€ Starting the Server

Run the FastAPI server:

uvicorn app:app --reload --host 0.0.0.0 --port 8000

๐ŸŒ Accessing the Service

๐Ÿ”Œ API Endpoints

๐Ÿ“ค POST /analyze

Upload and analyze a Wordfeud board screenshot:

curl -X POST "http://localhost:8000/analyze" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@your_screenshot.png"

๐Ÿ“ฅ GET /status/{task_id}

Check the status of an analysis task:

curl -X GET "http://localhost:8000/status/task_1" -H "accept: application/json"

๐Ÿ“‚ Project Structure

  • ๐Ÿ” ocr/: OCR-related code and template matching
  • ๐ŸŽจ visualization/: Board and match visualization tools
  • ๐Ÿงช test/: Test suite
  • ๐Ÿ“ letter_templates/: Reference images for letter recognition
  • ๐Ÿ—‚๏ธ static/: Generated visualizations and static assets
  • ๐ŸŽฏ templates/: HTML templates for web interface
  • ๐Ÿ› ๏ธ utils/: Shared utility functions

๐Ÿ‘ฉโ€๐Ÿ’ป Development

๐Ÿ”„ Git Workflow

Two helper scripts are provided for git operations:

  1. ๐Ÿ“ค Push changes to your repository:
./push_git.sh "Your commit message"
  1. ๐Ÿ“ฅ Pull updates from upstream:
./pull_upstream.sh

๐Ÿ”ง Technical Details

๐Ÿงฉ Core Components

  1. ๐Ÿ” OCR Engine

    • ๐Ÿ“ธ OpenCV for image processing
    • ๐Ÿ”  Tesseract OCR for text recognition
    • ๐ŸŽฏ Custom template matching for letter detection
  2. ๐ŸŽฎ Game Logic

    • ๐ŸŽฒ Board state representation
    • โœ… Move validation
    • ๐Ÿ“Š Game state analysis
  3. ๐ŸŽจ Visualization

    • ๐Ÿ–ผ๏ธ Board state rendering
    • ๐Ÿ”„ Match visualization
    • ๐ŸŽฏ Template matching results
  4. โšก API Service

    • ๐Ÿ”„ Async processing
    • ๐Ÿ”™ Background tasks
    • ๐Ÿ“Š Status tracking
    • ๐Ÿ›ก๏ธ Error handling

๐Ÿค Contributing

  1. ๐Ÿ”ฑ Fork the repository
  2. ๐ŸŒฟ Create your feature branch
  3. ๐Ÿ’พ Commit your changes
  4. ๐Ÿ“ค Push to your branch
  5. ๐ŸŽฏ Create a Pull Request

๐Ÿ“œ License

This project is based on the work by mrcz and maintains the same license terms.

๐Ÿ™ Acknowledgments

  • ๐ŸŽฎ Original project by mrcz
  • ๐Ÿ” OpenCV and Tesseract OCR communities
  • โšก FastAPI framework developers