Overview
TheGameRunner class orchestrates a complete Codenames game with 4 agents (2 hint givers and 2 guessers). It handles the full game loop including hint validation, guess execution, turn switching, and retry logic for handling API errors.
Classes
GameResult
Complete result of a game for analysis.Unique identifier for the game
Final outcome of the game (BLUE_WIN, RED_WIN, DRAW, etc.)
Winning team (Team.BLUE or Team.RED), None for draws
Total number of turns played
Tuple of (blue_remaining, red_remaining) cards
Complete game state snapshot for analysis
Class name of blue team’s hint giver
Class name of blue team’s guesser
Class name of red team’s hint giver
Class name of red team’s guesser
LLM model name for blue hint giver
LLM model name for blue guesser
LLM model name for red hint giver
LLM model name for red guesser
Error message if game ended due to error
Timestamp when game completed
Methods
Convert GameResult to dictionary for logging/storage
GameRunner
Orchestrates a complete Codenames game with 4 agents.Constructor
The game board with word assignments
Blue team’s hint giver agent
Blue team’s guesser agent
Red team’s hint giver agent
Red team’s guesser agent
Maximum turns before declaring draw (uses config default if None)
Print game progress (uses config default if None)
Optional game identifier (auto-generated if None)
Orchestrator configuration (uses default if None)
LLM configuration for retry settings (uses default if None)
Methods
run()
Run the complete game until completion.GameResult with complete game data including winner, scores, and full game snapshot.
Usage Example
Game Loop Details
TheGameRunner handles the full game loop:
- Get hint from current team’s hint giver
- Validate hint against board words (no exact matches or substrings)
- Get guesses from current team’s guesser
- Execute guesses and provide feedback
- Switch teams and repeat until game over
Retry Logic
The runner includes robust retry logic for handling API errors:- Exponential backoff: 5s, 10s, 20s delays with random jitter
- Max retries: Configurable via
LLMConfig.MAX_RETRIES(default: 3) - Retryable errors: Service unavailable, rate limits, timeouts, connection errors
- Non-retryable errors: Invalid hints, validation failures, non-string responses
Hint Validation
Hints are validated per official Codenames rules:- Cannot exactly match a board word
- Cannot contain a board word as substring
- Cannot be a substring of a board word
- Must have count within configured bounds (MIN_HINT_COUNT to MAX_HINT_COUNT)
Error Handling
The runner tracks various error types:- Invalid guesses: Not on board, already revealed, non-string type
- Hint errors: Invalid format, contains board words
- API errors: Timeouts, service unavailable, rate limits
- Bomb hits: Guessing the assassin card
GameResult.error for analysis.
Thread Safety
Related
- GameConfig - Game configuration options
- Board - Game board management
- Agents - Hint giver and guesser implementations