Overview
The game engine implements the core rules of Codenames, optimized specifically for LLM agents. Instead of a visual grid layout, words are represented as plain lists—making them easier to include in prompts and process by language models.The game engine is located in the
game/ directory and includes Board, GameState, and supporting types.Core Components
Board Structure
TheBoard class manages the word-to-color mapping for all 25 cards on the board.
game/board.py
Card Colors
Each word on the board has one of four colors:game/board.py
Blue Team
9 words (starting team gets +1)
Red Team
8 words
Neutral
7 words (no effect)
Bomb
1 word (instant game over)
Game State Management
TheGameState class tracks the current game status, turn history, and win conditions.
game/state.py
Team Enumeration
game/state.py
Blue team always starts first by default. The starting team gets one extra word (9 vs 8).
Game Flow
A typical game follows this pattern:Initialize Board
Create a
Board with 25 words. Colors are randomly assigned according to the standard distribution.Play Turns
Each turn consists of three phases:
- Start Turn: Spymaster gives a hint
- Make Guesses: Field operative guesses words
- End Turn: Switch teams
Turn Structure
Each turn is represented by aTurn object that records the complete history:
game/state.py
Turn Results
Each guess produces aTurnResult with detailed information:
game/state.py
Win Conditions
The game ends when one of three conditions is met:Team Reveals All Words
Team Reveals All Words
A team wins when all their words have been revealed.
Opponent Hits Bomb
Opponent Hits Bomb
If a team guesses the bomb word, they lose immediately and the other team wins.
Maximum Turns Reached
Maximum Turns Reached
Games automatically end after 50 turns to prevent infinite loops (configurable in
config.py).game/state.py
Game Configuration
You can customize game parameters usingGameConfig:
config.py
Configuration Options
| Parameter | Default | Description |
|---|---|---|
BOARD_SIZE | 25 | Total number of words |
BLUE_WORDS | 9 | Blue team word count |
RED_WORDS | 8 | Red team word count |
NEUTRAL_WORDS | 7 | Neutral word count |
BOMB_COUNT | 1 | Number of bomb words |
MAX_TURNS | 50 | Turn limit before draw |
STARTING_TEAM | ”BLUE” | Which team goes first |
LLM-Optimized Design
The game engine includes several features specifically designed for language model agents:Plain Word Lists
No grid coordinates—just lists of words. Easier to include in prompts and process.
Full History Tracking
Complete turn history with hints, guesses, and outcomes for analysis.
Automatic Validation
Catches common LLM errors like hallucinated words or duplicate guesses.
JSON Snapshots
Serializable game state for logging and debugging.
Error Handling
The game engine validates all actions and provides clear error messages:Example: Complete Game
Next Steps
Agents
Learn how AI agents play the game using the HintGiver and Guesser interfaces
BAML Integration
Understand how BAML enables type-safe LLM interactions