Skip to content

ElixirMentor/wordle_battle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Wordle Battle

A real-time competitive Wordle game where players battle to guess the most 5-letter words within a timed session. Built with Phoenix LiveView for instant, multiplayer gameplay.

๐Ÿš€ Play Live


โœจ Features

  • ๐ŸŽฏ Real-time Multiplayer - Compete with friends in the same session
  • โšก Live Updates - See opponent progress in real-time via Phoenix PubSub
  • ๐Ÿ† Smart Scoring - Bonus points for speed and accuracy
  • ๐Ÿ’พ Session Persistence - Rejoin games automatically after disconnection
  • โฑ๏ธ Timed Rounds - Race against the clock to maximize your score
  • ๐ŸŽจ Color-Coded Feedback - Classic Wordle-style letter hints (green/yellow/gray)
  • ๐Ÿ“ฑ Responsive Design - Play on any device
  • ๐Ÿ”„ Endless Rounds - Start new games with the same players

๐Ÿ› ๏ธ Tech Stack

๐ŸŽฎ How to Play

  1. Create or Join a Session - Share the session URL with friends
  2. Ready Up - Click ready when all players have joined
  3. Guess Words - Type 5-letter words and press Enter
  4. Use Color Hints:
    • ๐ŸŸฉ Green - Letter is correct and in the right position
    • ๐ŸŸจ Yellow - Letter is in the word but wrong position
    • โฌœ Gray - Letter is not in the word
  5. Score Points - Each correct word scores points (bonus for fewer attempts!)
  6. Race the Clock - Maximize your score before time runs out

๐Ÿ… Scoring System

  • Base: 1 point per correct word
  • Bonuses:
    • 1 attempt: +5 bonus โ†’ 6 points total
    • 2 attempts: +3 bonus โ†’ 4 points total
    • 3 attempts: +2 bonus โ†’ 3 points total
    • 4-6 attempts: +1 bonus โ†’ 2 points total
  • Failed word: 0 points

๐Ÿš€ Local Development

Prerequisites

  • Elixir 1.18.3 or later
  • Erlang 27.1.2 or later
  • Node.js (for asset compilation)

Setup

# Clone the repository git clone <your-repo-url> cd wordle_battle # Install dependencies and build assets mix setup # Start the Phoenix server mix phx.server # Or start in interactive mode iex -S mix phx.server

Now visit localhost:4000 from your browser.

Development Commands

# Run tests mix test # Run pre-commit checks (compile, format, test) mix precommit # Build assets mix assets.build # Run specific test file mix test test/path/to/test.exs # Run only failed tests mix test --failed

๐Ÿ—๏ธ Architecture

Game State Management

The game uses a GenServer-based architecture with Phoenix LiveView:

  1. WordleServer (GenServer) - Each session runs as a supervised process

    • Manages game state and phase transitions (:lobby โ†’ :playing โ†’ :game_over)
    • Handles word assignment, guess validation, and scoring
    • Broadcasts state updates via PubSub
    • Persists state across player disconnections
  2. WordleLive (LiveView) - Real-time UI for players

    • Subscribes to PubSub for session updates
    • Renders game grid, virtual keyboard, and leaderboard
    • Handles user interactions
  3. Dynamic Supervision - Sessions registered via Registry

    • Efficient process lookup
    • Fault-tolerant session management

Word Management

  • 2,300+ answer words (common 5-letter words)
  • 12,000+ valid guesses (extended dictionary)
  • Per-session tracking prevents word repetition
  • O(1) validation using MapSet

Player Persistence

  • UUID stored in browser localStorage
  • Automatic reconnection on page refresh
  • Graceful handling of disconnections
  • Automated cleanup of inactive sessions

๐Ÿ“ Project Structure

lib/ โ”œโ”€โ”€ wordle_battle/ โ”‚ โ”œโ”€โ”€ application.ex # App supervision tree โ”‚ โ”œโ”€โ”€ dictionary.ex # Word loading and validation โ”‚ โ””โ”€โ”€ wordle_server.ex # Game state GenServer โ”œโ”€โ”€ wordle_battle_web/ โ”‚ โ”œโ”€โ”€ live/ โ”‚ โ”‚ โ”œโ”€โ”€ wordle_live.ex # Main game LiveView โ”‚ โ”‚ โ””โ”€โ”€ lobby_live.ex # Session creation/joining โ”‚ โ”œโ”€โ”€ components/ โ”‚ โ”‚ โ””โ”€โ”€ core_components.ex # Reusable UI components โ”‚ โ””โ”€โ”€ router.ex # Routes priv/ โ””โ”€โ”€ dictionary/ โ”œโ”€โ”€ answer_words.txt # Curated answer list โ””โ”€โ”€ valid_guesses.txt # All valid words 

๐Ÿšข Deployment

This app is deployed on Fly.io in the Amsterdam region.

Deploy Your Own

# Install flyctl curl -L https://fly.io/install.sh | sh # Login to Fly.io flyctl auth login # Launch the app (configure as needed) flyctl launch # Set secrets flyctl secrets set SECRET_KEY_BASE=$(mix phx.gen.secret) # Deploy flyctl deploy

Configuration

The app uses auto-scaling with a single shared-cpu-1x instance that stops when idle to minimize costs.

See fly.toml for configuration details.

๐Ÿงช Testing

Tests use Phoenix.LiveViewTest for comprehensive LiveView testing:

# Example test test "player can submit a valid guess", %{conn: conn} do {:ok, view, _html} = live(conn, "/session/#{session_id}") view |> form("#guess-form", guess: %{word: "HELLO"}) |> render_submit() assert has_element?(view, "[data-guess='HELLO']") end

Run tests with: mix test

๐ŸŽฏ Game Mechanics

Guess Validation Algorithm

Two-pass algorithm handles duplicate letters correctly:

  1. First pass: Mark exact matches (green)
  2. Second pass: Mark present letters (yellow) from remaining pool
  3. Remainder: Mark as wrong (gray)

State Machine

:lobby โ†’ :playing โ†’ :game_over โ†’ :lobby (new round) 
  • Lobby: Players join and ready up
  • Playing: Active gameplay with timer
  • Game Over: Display winners and final scores

Timer Implementation

  • Countdown broadcasts every second via PubSub
  • Auto-transition to game over at 0
  • Audio notification on expiration

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ License

This project is open source and available under the MIT License.

๐Ÿ™ Acknowledgments

  • Dictionary words sourced from common Wordle word lists
  • Inspired by the original Wordle by Josh Wardle
  • Built with the amazing Phoenix Framework

Made with โค๏ธ using Elixir and Phoenix LiveView

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published