Skip to content

xerk-dot/scrabble_with_gemini_3.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฒ Scrabble AI Arena

An advanced Scrabble implementation with optimized AI opponents, experimental game variants, and team-based mega board battles

Scrabble AI Arena

Next.js TypeScript React AI

Play Now โ€ข Features โ€ข Variants โ€ข Tech Stack


๐ŸŒŸ What Makes This Special?

This isn't just another Scrabble clone. Scrabble AI Arena is a high-performance testing ground for AI strategies with:

  • ๐ŸŽฏ Optimized AI - DAWG/Trie-based move generation with cross-set pruning
  • ๐ŸŸ๏ธ Mega Board - 45x45 grid with 8-player team battles
  • ๐Ÿงช Experimental Variants - Modified rulesets to challenge AI decision-making
  • ๐Ÿค– Multi-Difficulty AI - Compare strategies across Easy/Medium/Hard opponents
  • ๐Ÿ“Š AI vs AI Mode - Watch different difficulties compete for strategy analysis
  • โšก Real-Time Validation - SOWPODS dictionary with 267,751 words
  • ๐ŸŽจ Team Color Coding - Visual distinction for team members

โœจ Features

๐ŸŽฎ Core Gameplay

  • Complete Scrabble Implementation - Official rules with full tile bag
  • Drag & Drop Interface - Smooth tile placement with @dnd-kit
  • Instant Validation - Live preview shows validity and score in real-time
  • Smart Word Detection - Validates all formed words including cross-words
  • Move History - Track every play throughout the game
  • Full-Screen Mode - Optimized for mega board viewing

๐Ÿค– AI Opponents

Optimized with Professional Techniques:

  • DAWG/Trie Data Structure - O(1) word validation and prefix checking
  • Rack-Based Word Generation - Only generates playable words from current tiles
  • Board-Aware Search - Finds words that extend existing board tiles
  • Cross-Set Pruning - Pre-calculates valid letters at each position
  • Alpha-Beta Pruning - Skips unpromising branches in HARD mode

Three Difficulty Levels:

Difficulty Strategy Performance
Easy ๐ŸŸข Random from all valid moves ~50-200ms
Medium ๐ŸŸก Random from top 50% moves ~100-500ms
Hard ๐Ÿ”ด Always highest-scoring move ~200-1000ms

AI Features:

  • Uses full SOWPODS dictionary (267,751 words)
  • Validates all words (including cross-words) before playing
  • Team-aware resignation (only resigns if all teammates stuck)
  • Generates moves in <1 second even on Mega Board
  • Fully optimizes for bonus squares (DW/TW/DL/TL)

๐ŸŸ๏ธ Board Variants

๐ŸŸฆ Standard (15x15)

Classic Scrabble layout - the baseline for comparison

โšก Bonus Blitz (15x15)

2.5x more bonus squares for aggressive scoring strategies

  • Tests AI's ability to maximize multipliers
  • Favors positional play over vocabulary

๐ŸŽฒ Random (15x15)

Procedurally generated bonus placement every game

  • Eliminates memorized optimal positions
  • Tests AI adaptability to unknown layouts

โš ๏ธ Hazards (15x15)

Risk/reward gameplay with dangerous squares

  • Hazard squares deduct 10 points
  • Forces strategic risk assessment

๐ŸŸ๏ธ Mega Board (45x45)

The Ultimate Scrabble Challenge

A massive 45x45 grid designed for 8-player team battles (4v4). Features:

  • Extended Premium Squares - Strategic DL/TL/DW/TW placement across the expanded board
  • Team Mode - Red vs Blue teams with color-coded tiles for easy tracking
  • Longer Games - More space = more complex strategies and higher scores
  • Performance Optimized - Handles 2,025 squares smoothly

Mega Board Team Battle

๐ŸŽฏ Game Modes

  • ๐Ÿ‘ค Human vs AI - Classic gameplay with AI opponent
  • ๐Ÿค– AI vs AI - Watch and learn from AI strategies
    • Set different difficulties for each AI
    • Great for benchmarking and analysis
  • ๐Ÿ‘ฅ Teams (Mega Only) - 4v4 team battles on the mega board
    • Red Team vs Blue Team
    • Color-coded tiles by team
    • Team-aware AI resignation logic
    • Interleaved turn order

๐Ÿš€ Getting Started

Prerequisites

node --version  # v18.0.0 or higher
npm --version   # v9.0.0 or higher

Quick Start

# Clone
git clone https://github.com/xerk-dot/scrabble_with_gemini_3.0.git
cd scrabble_with_gemini_3.0

# Install
npm install

# Run
npm run dev

Open โ†’ http://localhost:3000 ๐ŸŽ‰

Production Build

npm run build
npm start

๐ŸŽฎ How to Play

1๏ธโƒฃ Setup

  • Choose board variant (Standard, Bonus Blitz, Random, Hazards, or Mega)
  • Select game mode (Human vs AI, AI vs AI, or Teams for Mega)
  • Pick AI difficulty (or two for AI vs AI)
  • Click "New Game"

2๏ธโƒฃ Make Moves

  • Drag tiles from rack to board
  • Live preview shows validity โœ“/โœ— and score
  • Submit to play or Recall to undo

3๏ธโƒฃ Actions

Button Action
Submit Play your word
Recall Take back tiles
Shuffle Reorganize rack
Pass Skip turn
Resign Give up (when stuck)

4๏ธโƒฃ Win

  • Highest score when all players resign
  • Team mode: Highest team score wins
  • AI auto-resigns when no valid moves exist (team-aware)

๐Ÿ—๏ธ Tech Stack

  • Framework โ†’ Next.js 15 with App Router
  • Language โ†’ TypeScript for type safety
  • UI โ†’ React 18 with CSS Modules
  • Drag & Drop โ†’ @dnd-kit/core
  • Validation โ†’ Server Actions with SOWPODS
  • State โ†’ React Context API
  • AI Optimization โ†’ DAWG/Trie, Cross-Sets, Alpha-Beta Pruning

๐Ÿ“Š AI Architecture

Optimization Techniques

  1. DAWG/Trie Data Structure (src/lib/dawg.ts)

    • O(1) word validation
    • Instant prefix checking
    • Cached globally for performance
  2. Rack-Based Word Generation (src/lib/word-generator.ts)

    • Generates only words from available tiles
    • Handles blank tiles (tries all 26 letters)
    • Board-aware extensions (e.g., CAT โ†’ CATS)
  3. Cross-Set Pruning (src/lib/cross-sets.ts)

    • Pre-calculates valid letters at each position
    • Filters invalid placements before validation
    • Separate sets for horizontal/vertical plays
  4. Alpha-Beta Pruning (HARD mode only)

    • Skips words that can't beat current best score
    • Estimates maximum possible score
    • 2-3x speedup for HARD difficulty

Performance Characteristics

Expected Performance:

  • Standard board: <100ms per move
  • Mega Board: <1 second per move (HARD mode)
  • 100% accuracy maintained

Speedup vs Brute Force:

  • 10-100x faster on average
  • Scales well to Mega Board (45x45)

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ actions.ts          # ๐Ÿ” Word validation (Server Actions)
โ”‚   โ”œโ”€โ”€ ai-actions.ts       # ๐Ÿค– Optimized AI move generation
โ”‚   โ””โ”€โ”€ page.tsx            # ๐Ÿ“„ Main page
โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ Board.tsx           # ๐ŸŽฒ Game board with team colors
โ”‚   โ”œโ”€โ”€ Game.tsx            # ๐ŸŽฎ Game controller
โ”‚   โ”œโ”€โ”€ Rack.tsx            # ๐ŸŽซ Tile rack with controls
โ”‚   โ”œโ”€โ”€ Square.tsx          # โฌœ Board squares
โ”‚   โ””โ”€โ”€ Tile.tsx            # ๐Ÿ”  Individual tiles (team colored)
โ”œโ”€โ”€ context/
โ”‚   โ””โ”€โ”€ GameContext.tsx     # ๐Ÿ”„ State management & team logic
โ””โ”€โ”€ lib/
    โ”œโ”€โ”€ constants.ts        # ๐Ÿ“‹ Board layouts (including Mega)
    โ”œโ”€โ”€ cross-sets.ts       # ๐ŸŽฏ Cross-set calculation
    โ”œโ”€โ”€ dawg.ts             # ๐ŸŒณ DAWG/Trie data structure
    โ”œโ”€โ”€ gameUtils.ts        # ๐Ÿ› ๏ธ Board init, tile bag
    โ”œโ”€โ”€ scoring.ts          # ๐Ÿ“Š Score calculation
    โ”œโ”€โ”€ teamColors.ts       # ๐ŸŽจ Team color utilities
    โ”œโ”€โ”€ types.ts            # ๐Ÿ“ TypeScript types
    โ”œโ”€โ”€ validation.ts       # โœ… Move validation
    โ””โ”€โ”€ word-generator.ts   # ๐Ÿ“ Rack-based word generation

๐Ÿค Contributing

Built with Google Gemini assistance.

Contributions welcome! Feel free to:

  • ๐Ÿ› Report bugs
  • ๐Ÿ’ก Suggest new variants
  • ๐Ÿš€ Submit PRs
  • ๐Ÿ“– Improve docs

๐Ÿ“ License

MIT License - see LICENSE

๐Ÿ™ Acknowledgments

  • Inspiration - Classic Scrabble by Hasbro
  • AI Assistant - Google Gemini 3.0

Optimized AI โ€ข Mega Battles โ€ข Team Play ๐ŸŽฒโœจ

Report Bug โ€ข Request Feature

Releases

No releases published

Packages

 
 
 

Contributors