Katkat

Replace a Heuristic Terminal Text Game's Python Logic With LLM Calls

CohereMachine Learning Engineer · Onsite

Last updated

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.

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.

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?

Hints

Hint 1

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 2

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.

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?