Building Text-Based Games with LLM-Assisted Development: Key Practices

    A text-based RPG prototype lives or dies by its rules and narrative. Large language models (LLMs) can generate data structures, state transitions, and basic logic from natural language descriptions, making them well suited for early prototyping. But model-generated code is not automatically correct—developers still need to define specifications, split modules, and verify continuously. This article walks through a complete workflow using an open-world text sandbox project as an example, covering requirements decomposition, module design, and engineering practices for collaborating with LLMs.

    1. Background: Prototyping Games with LLMs

    The core of a text-based role-playing game is the combination of rules and narrative. Developers typically want to validate gameplay first before investing in full art assets and engine work. LLMs can generate data structures, state transitions, and basic logic from natural language descriptions, which makes them a good fit for coding during the prototyping stage. However, model output is not inherently correct—humans still need to define specifications, break the work into modules, and keep verifying the results.

    This article uses an open-world text sandbox project as an example. The game world consists of five regions where players can move freely, with no fixed linear storyline. It also includes interconnected systems such as reputation, character attributes, and turn-based combat, making it a good vehicle for demonstrating a complete development workflow.

    2. Requirements Decomposition: Turning Spoken Requirements into Verifiable Specs

    Informal, spoken requirements typically suffer from three problems: ambiguous references, conflicting rules, and missing edge cases. A statement like “players can be either good or evil” cannot be written directly into code; it needs to be converted into quantifiable state, such as faction tendency, reputation points, and behavior records.

    The following approach is recommended for organizing requirements:

    • Divide requirements into three layers: “world facts,” “rules,” and “interactions.” World facts describe static information about locations and characters; rules describe numeric calculations and state changes; interactions describe actions the player can perform.
    • Give every rule its inputs, outputs, and exception cases. For example, “the player has 30 attribute points in total” should specify what happens if allocation exceeds the total, and which tier each single-attribute cap corresponds to.
    • Define initial values and valid ranges for all numbers explicitly, so that no module makes its own assumptions during implementation.

    The specification document should exist before the code. After the model generates code module by module against the spec, check the output with fixed test cases. Merging code that merely “looks fine” after a single run often misses edge-case issues.

    3. Module Design and Implementation Examples

    3.1 World Structure

    Represent the world as a three-level hierarchy: “region, settlement, location.” A region contains villages and cities, and cities are further tiered by size. This structure should be driven by data tables rather than hardcoding locations into the logic. Adding a new location only requires changing data—no changes to game flow code.

    3.2 Reputation System

    Reputation determines how NPCs treat the player. When implementing it, map reputation values to attitude tiers, and have dialogue, trading, and quest conditions read the tier rather than comparing raw numbers. That way, adjusting thresholds only requires modifying the mapping table, not the dialogue branches.

    1. reputation_tiers = [
    2. (0, "Unknown Wanderer"),
    3. (30, "Known Face"),
    4. (60, "Well Respected"),
    5. ]
    6. function get_attitude_tier(reputation):
    7. for (threshold, name) in tiers, checked from highest to lowest:
    8. if reputation >= threshold: return name

    3.3 Turn-Based Combat and Action Counts

    Turn order in combat is determined by the agility attribute. When the two sides’ agility is close, each side takes one action per turn, alternating. When the gap is large, the side with higher agility gets multiple actions within the same turn.

    The action-count calculation should be a configurable parameter, not hardcoded. The following pseudocode shows one approach:

    1. function compute_action_count(agility_high, agility_low, cap=4):
    2. if agility_low <= 0: return cap
    3. ratio = agility_high / agility_low
    4. if ratio < 1.5: return 1 // Comparable skill; sides alternate turns
    5. return min(floor(ratio), cap)

    Here, 1.5 and the cap of 4 are both tuning parameters that need balancing through actual playtests. Testing should cover: equal agility, a twofold agility gap, one side having zero agility, and extremely large values. Each scenario should be verified against the intended design.

    4. Engineering Practices for Working with LLMs

    1. Modular prompting: Provide only one module’s spec, interface contracts, and existing data structures at a time. For example, when generating the combat module, attach only the combat rules and character attribute definitions—not the entire world description. The more focused the context, the more stable the output.
    2. Keep versions: Put every generated piece of code under version control. When a regression appears, you can trace it to a specific generation and diff it against the previous version.
    3. Tests designed by humans: Test cases for combat formulas, reputation thresholds, and numeric boundaries should be written by developers, not generated by the model alongside the implementation. If tests and implementation come from the same understanding, the tests will only confirm wrong assumptions.
    4. Focus review on hidden issues: State synchronization, save-file compatibility, and malformed input often fail silently and need dedicated checking. A prototype that runs is not proof these areas are correct.
    5. Maintain a rules document: Over long conversations, models tend to forget earlier agreements. Once a project reaches mid-to-late stages, consolidate all rules into a single document and prepend it to every prompt.

    5. Content Boundaries and Compliance

    Text-creation applications must handle content rating. Define your content strategy during development, including allowed subject matter, minor-protection requirements, and the moderation rules of your target platform. Do not rely on the model’s default behavior to draw boundaries. A safer approach is to build configurable filtering and rating mechanisms into the system, keep a human review step in the loop, and record the reason for every policy adjustment.

    6. Efficiency Gains and Key Limitations

    LLMs significantly cut the time spent writing boilerplate code and data structures, making them ideal for rapid gameplay validation. But the limitations are equally clear: long-range consistency is weak, numeric balancing requires extensive manual tuning, and the model’s grasp of implicit business rules depends heavily on the quality of the requirement descriptions.

    As for how much development efficiency actually improves, personal impressions are no substitute for measurement. Teams can record time spent writing versus generating code, plus rework counts, on the same project and draw their own conclusions.

    7. Practical Recommendations

    • Write the spec first, then generate code.
    • Put numeric values in configuration files, not hardcoded.
    • Write a minimal, usable test suite for every core system.
    • Set up a review process for generated game text content.
    • Never merge logic you don’t understand into the main branch. LLMs can accelerate coding, but understanding system behavior remains the developer’s responsibility.