Replace a Heuristic Terminal Text Game's Python Logic With LLM Calls
Company: Cohere
Role: Machine Learning Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
In a live coding round you receive a text-based game that runs in the terminal, together with its Python implementation of several hundred lines, which works through hand-written heuristics. Your task is to replace that heuristic implementation with one driven by interaction with an LLM, so that the game still runs end to end in the terminal.
AI coding assistants are allowed during the round. The interviewer, however, is judging your own ability to implement and debug. Handing the task to an assistant ("vibe coding") without understanding, checking and explaining the result counts against you, even if the code appears to work.
The game's rules are not part of this prompt; in the round you learn them by reading the provided code. Where the prompt needs a concrete picture, assume the game keeps its state in Python objects, reads the player's commands from the terminal, and calls heuristic functions to decide what happens next.
```hint Find the seam
Before writing anything, locate the narrowest point where heuristic decisions enter the game loop, and what information flows in and out at that point.
```
```hint The reply is untrusted
Treat whatever the model returns as input from an unreliable user. Decide what your code does when the reply is malformed, refers to something that does not exist, or breaks a rule of the game.
```
### Clarifying Questions
- Which part is heuristic: an opponent's or non-player character's decisions, the interpretation of the player's free-text commands, the narration of outcomes, or the whole game engine?
- Must the game state and rules stay in Python, with the LLM only making decisions, or may the LLM take over state as well?
- Which LLM client, model, key and latency budget are provided?
- How is success judged: the game runs to completion, it plays better than the heuristic, or it behaves like the heuristic but with more natural language?
- Are there existing tests or example sessions to compare against?
- Must runs be reproducible?
### What a Strong Answer Covers
- Reading the existing code first, and explaining where the heuristic boundary is
- A narrow interface that keeps game state and rules in code
- A prompt that serializes the relevant state and constraints compactly
- Structured output, with parsing, validation, retries and a fallback
- Verification that is visible to the interviewer: a fake model for tests, logging of prompts and replies, and repeated end-to-end runs
- A debugging process the candidate can explain step by step, including how AI-generated code was reviewed
- Latency, cost and failure handling for model calls inside an interactive loop
### Follow-up Questions
- How would you compare the LLM-driven version with the original heuristic version objectively?
- A long game no longer fits in the model's context window. What do you send each turn?
- A teammate reports that the game froze on turn 30 of one run. How would you reproduce and debug it?
- When would you keep the heuristic instead of the LLM for part of the game?
Overview: A live coding round: replace the heuristic Python implementation of a terminal text game with one driven by an LLM while keeping the game playable end to end. AI assistants are allowed, but the round judges your own implementation and debugging, including validating model output, fallbacks, and tests with a fake model.