A Scrabble engine for dictionary lookup, move generation, and optimal play analysis. Part of a larger project to build a learning tool.
- Word retrieval: Find words by length, pattern, prefix, suffix, or contained letters
- Rack solving: Given 7 tiles, find all playable words
- Move generation: Given a board and rack, find all legal moves with scores
- Best play analysis: Rank moves by score, including cross-word scoring and bonus squares
- Game state tracking: Tile bag, remaining letters, score tracking
Built in phases, each extending the previous:
- Dictionary & Trie — word list indexed for fast lookup and traversal
- Tiles & Rack — tile values, bag management, anagram solving
- Board & Scoring — 15x15 board with bonus squares, correct scoring rules
- Move Generator — Appel & Jacobson algorithm for exhaustive legal move search
- Game Logic — full state management, tile tracking, analysis mode
- Blank Support — blank tile handling in rack and on board
- CLI & Integration — interactive REPL, scrabble-vision bridge
Designed to accept board state as a 15x15 text grid:
from scrabble_engine import Engine
board = Board.from_text(grid_from_vision)
moves = engine.analyze_position(board, rack=["S", "T", "A", "R", "E", "D"])
for move in moves[:10]:
print(f"{move.word} at {move.start} {move.direction}: {move.score} pts")cd scrabble-engine
uv sync
uv run pytestUses TWL06 (Tournament Word List, North American standard, ~178K words). Place twl06.txt in src/scrabble_engine/data/.
Designed to be integrated with other learning tools