AI-Assisted Development in Practice: Using a Text RPG to Model Requirements and Turn-Based Combat

    This article explores how large language models can assist with requirements analysis, module design, and code generation in a stateful, branching application. Using an open-world text-based sandbox wuxia RPG as a case study, it describes how to break down entities and relationships, implement reputation-driven NPC interactions, and build an action-point combat system. It also covers common failure modes in AI-generated code, a review checklist, the shifting role of developers, and content compliance controls. The focus is on where LLMs add value and where human validation remains essential.

    Large language models have moved beyond code completion to act as collaborators in requirements analysis, module design, and code generation. This article uses an open-world text-based sandbox wuxia RPG as an example to show how developers can work with a model to build a complex application with state and branching, and which parts of the process still require human review.

    1. What LLMs Can and Cannot Do in Programming

    In daily development, tasks such as CRUD endpoints, form pages, and component templates are highly repetitive, and models can often generate usable first drafts. For algorithm logic or architecture proposals, models can quickly provide multiple alternatives to help developers compare feasibility. Developers can therefore spend more time on requirement definition and structural design.

    However, the size of the efficiency gain depends on task complexity, model version, and toolchain, and teams need to measure it in their own projects. Generated code quality is also inconsistent: prompt clarity, context completeness, and test coverage all affect the result. Human review and unit tests therefore remain necessary.

    2. Case Background: A Text-Based Sandbox Wuxia RPG

    In this case, all requirements were described in natural language, and the model generated the code. The game world is divided into five major regions: East, West, South, North, and Central. Each region contains several villages and cities. Players can choose their action routes freely, so state management and combat rules are the parts that require the most precise definition.

    2.1 Requirement Breakdown and World Structure

    When breaking down requirements, it helps to first write down three types of information: entities (regions, villages, cities, NPCs), attributes (population, reputation, dexterity, etc.), and relationships (a region contains cities; a city has NPCs). Organizing this information into a table before giving it to the model can reduce rework.

    Entity Key fields Relationships
    Region name, ID contains multiple cities
    City name, size, region has multiple NPCs
    NPC name, reputation threshold, attitude belongs to one city

    The model can generate data classes and traversal logic from the table. Developers still need to check whether IDs are unique, whether foreign keys are valid, and write tests to verify map generation results.

    2.2 State Management and Reputation System

    The player’s initial attributes (appearance, dexterity, etc.) have a point cap, and reputation determines NPC attitudes toward the player. Consider a player who asks the village chief for information when first entering the martial arts world: if the player’s reputation is below the chief’s threshold, the chief refuses to reveal information. The player can take errand quests to raise reputation or choose to use force, which triggers combat.

    Here is a corrected interaction function that handles unknown actions:

    1. def interact_with_npc(player, npc, action_type):
    2. """Handle player-NPC interaction and return result text."""
    3. if action_type == "INQUIRE":
    4. if player.reputation < npc.threshold:
    5. return "NPC refuses to provide information and drives you away"
    6. return "NPC provides a key clue"
    7. if action_type == "THREATEN":
    8. start_combat(player, npc)
    9. return "Combat triggered"
    10. raise ValueError(f"Unknown interaction type: {action_type}")

    When using this code, note the following:

    1. Interaction types should use an enum to avoid string typos.
    2. Unknown actions should raise an exception, not silently return an empty value.
    3. Reputation thresholds should be stored in a configuration file so values can be tuned easily.
    4. Every branch should have a corresponding unit test, covering at least insufficient reputation, sufficient reputation, and unknown actions.

    The model can help generate first drafts and basic exception branches, but state machine boundaries, reputation change rules, and consistency across states need to be defined and verified by developers.

    2.3 Turn-Based Combat: Action Point Model

    The combat system uses an action point (AP) model. Higher dexterity means faster movement and more AP per round. At the start of each round, both sides’ AP is calculated as follows:

    AP per round = base points + floor(dexterity / 5)

    With a base of 2, a player with 12 dexterity gets 2 + 2 = 4 AP per round. Skill costs are as follows:

    Skill AP cost Description
    Light attack 1 Lower damage, higher hit rate
    Heavy attack 3 Higher damage, lower hit rate
    Defend 1 Reduces damage taken this round by 50%

    The execution order for each round is as follows:

    1. Round start: calculate both sides’ AP and write it into their action queues.
    2. Action phase: both sides alternate actions, and each action deducts the corresponding AP. When one side runs out of AP, the other side continues acting.
    3. End conditions: both sides run out of AP, both choose to end, or the per-round action cap is reached (for example, 20 actions). Unused AP is cleared at the end of the round and does not carry over to the next round.
    4. Resolution phase: apply status modifiers (buffs and debuffs), hit checks, damage calculation, and defense reduction in order, then resolve persistent effects.

    This order must be fixed. If defense is calculated before damage, the result will not match the design. The pseudocode is as follows:

    1. Each round:
    2. player_ap = 2 + floor(player.dex / 5)
    3. enemy_ap = 2 + floor(enemy.dex / 5)
    4. current_actor = side with higher dexterity
    5. while either side has AP and action cap not reached:
    6. if current_actor lacks enough AP, switch to the other side
    7. current_actor performs an action, deducts AP, resolves effects in fixed order
    8. switch current_actor
    9. clear unused AP for both sides

    Each step should have tests. For example, when dexterity is equal, both sides should have equal AP; a skill cannot be used when AP is insufficient; and the formula should not go out of bounds when dexterity is 0 or extremely large.

    3. Common Errors and Review Checklist for AI-Assisted Development

    AI-generated code commonly has the following problems:

    • Logic gaps: incomplete branch coverage, especially for invalid inputs and boundary values.
    • Numerical imbalance: formulas may look reasonable, but one side dominates in actual combat. You can simulate battles in bulk, count win rates, and then adjust parameters.
    • Hidden dependencies: generated code references undeclared libraries or inconsistent versions.
    • Over-abstraction: models tend to generate complex framework code; ask for a minimal viable implementation first.

    Before committing code, check the following:

    1. Is every branch tested?
    2. Have numerical formulas been tested at boundary values (0, maximum, negative)?
    3. Are dependency versions written into the lock file?
    4. Does the generated code pass static checks and code review?

    4. How the Developer’s Role Changes

    Intelligent programming makes much coding work easier, and it also changes the skills developers need. Requirement definition, architecture design, and the ability to review and integrate AI-generated code are becoming more important. Developers need to clearly tell the model the business rules, constraints, and acceptance criteria, and then put the generated results through testing and review processes.

    5. Content Compliance and Risk Control

    Text games and content-generation applications must comply with the laws and regulations of their region and with platform policies. In implementation, teams can take the following measures:

    1. Set up keyword filtering on both input and output, and maintain an updatable sensitive-word list.
    2. Call a model moderation API to classify generated content; high-risk content goes to human review.
    3. Log generation requests, moderation results, and human handling records, and retain them for the period required by relevant regulations.
    4. Provide a user complaint and reporting channel and set a handling time limit.
    5. Periodically sample model outputs and adjust prompts and filtering rules when issues are found.

    Large language models can shorten some coding time and help developers quickly validate approaches. The reliability of complex applications still depends on clear requirement definitions, explicit state rules, and complete tests. Teams can start with small modules and use measured data to decide which parts are worth handing to the model.