LLM-Assisted Development of a Strategy Game: Requirements Iteration and Practical Methods
This article explains how to use large language models to iteratively build an interactive strategy game. It covers why interactive games make good test scenarios, how to break vague requirements into verifiable acceptance criteria, prompt design principles, and implementation techniques including a fixed-timestep game loop, a state-machine-based automation assistant, data-driven unit configuration, and theme separation. A structured evaluation checklist and solutions to common pitfalls are also provided.
1. Why Interactive Games Make a Good Test Scenario
Interactive programs place higher demands on code generation than ordinary scripts. A strategy game involves state management, rule evaluation, time progression, UI rendering, and user input all at once—any failure in one of these surfaces at runtime. This makes such tasks a good test of a model’s overall capability: understanding domain concepts, respecting constraints, and maintaining code consistency across multiple rounds of modification.
These tests measure performance on a specific task and cannot be directly extrapolated to a model’s overall ability. Results from a single case should only serve as a reference and be combined with other tasks for evaluation.
2. Breaking Vague Requirements into Verifiable Items
A common problem when writing requirements is packing multiple intents into one sentence. For example, “make it real-time” actually contains three layers of meaning:
- Replace turn-based progression with continuous time progression;
- The player no longer needs to manually click an “end turn” button;
- Both sides act under the same time base, with resource production and unit speed applied symmetrically.
Each layer can be written as a checkable acceptance criterion. The third one is the most easily overlooked. A common defect in generated code is that one side’s timing logic runs faster than the other’s—this is not obvious in the UI and requires a dedicated test case to verify.
Another typical requirement is “add a toggleable automation assistant.” It should satisfy the following conditions:
- The player can enable or disable the feature via a switch;
- When enabled, it automatically selects and starts a research item when resources are sufficient;
- When disabled, manual control is restored;
- The automation must not bypass the existing resource deduction rules.
The fourth point is critical. If the automation logic modifies resource values directly, every subsequent adjustment to those values risks introducing hidden bugs. The correct approach is to reuse the same cost-deduction function.
For visual requirements such as “add icons to map objects,” you can use emoji or font icons. Whichever you choose, build a unified mapping table rather than hardcoding icons throughout the rendering code.
3. Prompt Design Principles
The prompt determines whether the model understands your intent. In practice, an effective prompt usually contains the following elements:
- Project background: runtime environment, tech stack, file structure;
- Goal for this round: change only one category of functionality per round;
- Constraints: what must not be changed, such as existing data structures and numeric rules;
- Acceptance criteria: results that can be checked item by item;
- Output order: provide a modification plan first, then the complete code.
Here is an example template:
Background: single-file web app, vanilla JavaScript, rendering a hex map with Canvas.Goal for this round: change turn-based progression to continuous time progression.Constraints:1. Keep the existing data structures for units, cities, and resources.2. Both sides advance using the same time step.3. Do not introduce external dependencies.Acceptance criteria:1. The game runs automatically after the page loads, with no end-turn button needed.2. Pause and speed-up functions work.3. No errors in the console.Please provide a modification plan first, then output the complete code.
The benefit of this style is that the model knows the boundaries before it starts, and when something goes wrong, the cause is easier to locate.
4. Key Points for the Real-Time Conversion
The core of real-time conversion is replacing “turns” with a “fixed-timestep loop.” A fixed timestep makes logic outcomes reproducible, and separating rendering from logic ensures that screen refreshes do not affect rule computation. Example code:
const TICK_MS = 100; // logic timestep in millisecondslet accumulator = 0;let lastTime = performance.now();let gameSpeed = 1; // 0 means pausedfunction frame(now) {const delta = now - lastTime;lastTime = now;accumulator += delta * gameSpeed;while (accumulator >= TICK_MS) {updateWorld(TICK_MS); // all entities advance in the same functionaccumulator -= TICK_MS;}render(); // drawing only; never modifies game staterequestAnimationFrame(frame);}requestAnimationFrame(frame);
This structure has three key points:
- All units, buildings, and research progress advance inside
updateWorld, so both sides follow the same time rules; renderchanges no state, so it can be inspected independently during debugging;- Pause and speed control only require modifying
gameSpeed, with no changes to rule code.
After the real-time conversion, leftover turn-based variables often remain in the code. When the refactor is done, search for turn counters and related conditionals to confirm nothing was missed.
5. State Machine Design for the Automation Assistant
The automation assistant is essentially a decision function that runs on every time step. Its design should follow two principles: the decision logic reuses existing rules, and strategy selection is separated from execution.
const assistant = { enabled: false };function assistantTick(player) {if (!assistant.enabled) return; // do nothing when the switch is offif (player.research.active) return; // skip if research is already in progressconst next = pickNextTech(player); // strategy function, replaceable on its ownif (next && canAfford(player, next.cost)) {startResearch(player, next); // reuse the same cost and start logic}}
canAfford and startResearch are the same functions used for manual player actions. This guarantees that automation and manual play follow identical rules and avoids two inconsistent sets of judgment logic. pickNextTech can be swapped to select by priority, by current threat, or by resource composition, making it easy to experiment with different strategies later.
The switch state should be synced to the UI. When the player checks or unchecks the box, only assistant.enabled is modified and the display text is refreshed—there is no need to reset game progress.
6. Adding Units with a Data-Driven Approach
When adding new units, the most efficient approach is to centralize attributes in a configuration table, with rule code reading properties by field rather than hardcoding values.
const UNIT_TYPES = {scout: { name: "Scout", icon: "🛰️", cost: 50, speed: 1.0, attack: 5 },airship: { name: "Heavy Airship", icon: "🛸", cost: 120, speed: 0.4, attack: 30 }};// The values above are structural examples only; actual values should// follow the design document.
This approach has two benefits. First, adding a unit only requires adding one row to the table—no changes to combat or movement code. Second, icons and attributes live together, so the UI and the rules share the same data.
Icon rendering depends on the runtime platform. The same emoji may look different across operating systems, so a fallback is needed. Two common approaches: fall back to a two-letter text label when the emoji cannot be displayed, or use vector icons or a sprite sheet instead. The former is simpler to implement; the latter offers better visual consistency.
7. Theme Replacement: Separating the Rule Layer from the Presentation Layer
Replacing the overall visual style—for example, switching to a cyberpunk futuristic city look—is a presentation-layer change. The rule layer’s values, judgments, and flow should remain unchanged. Keeping the two apart greatly reduces the risk of the refactor.
const THEMES = {classic: { city: "🏛️", unit: "⚔️", bg: "#2b3a4a", glow: null },neon: { city: "🌆", unit: "🤖", bg: "#0d0221", glow: "#ff2a6d" }};function drawHex(ctx, x, y, size, theme) {ctx.fillStyle = theme.bg;ctx.strokeStyle = theme.glow || "#444";ctx.lineWidth = 2;if (theme.glow) {ctx.shadowBlur = 12;ctx.shadowColor = theme.glow; // glow effect implemented via shadow}// Hexagon path drawing code omittedctx.stroke();ctx.shadowBlur = 0; // avoid affecting subsequent drawing}
Switching themes only requires swapping the THEMES reference. If rule behavior changes after a theme switch, it means logic code has leaked into the presentation layer and needs to be split back out.
Glow and particle effects increase drawing overhead. Heavy use of shadows over large areas can reduce frame rate; you can limit the number of particles, or pre-render the static map into an offscreen canvas and only redraw the parts that change each frame.
8. Evaluation Checklist
After each iteration, it is recommended to check the following items one by one:
| Dimension | How to check | Pass criteria |
|---|---|---|
| Functional completeness | Compare against each acceptance criterion | Every requirement can be reproduced |
| Instruction following | Compare the prompt with the actual result | Nothing omitted or changed without authorization |
| Rule consistency | Execute both manual and automated actions | Same cost deduction, cooldowns, and outcomes |
| Time fairness | Control test with identical units and resources on both sides | Same progression speed and output |
| Regression stability | Re-run test cases kept from the previous round | Existing features are not broken |
| Maintainability | Read the code structure | Clear separation of data, rules, and rendering |
Regression stability is the most easily neglected. In later modifications, models sometimes delete features added in earlier rounds or rewrite functions that were already correct. Including a feature list in each round’s prompt and requiring the model to preserve every item noticeably reduces this risk.
9. Common Problems and Solutions
- Later iterations lose earlier features: attach a feature list to the prompt and require existing interfaces to be preserved.
- Leftover turn-based logic after real-time conversion: globally search for old variable names and related conditionals, and verify each one.
- Inconsistent icon display: provide a unified mapping table and a fallback plan.
- Visual effects cause lag: limit the number of effects and use offscreen caching for static content.
- Automated and manual actions produce different results: check whether both call the same set of functions.
10. Conclusion
The key to developing interactive programs with LLMs is to break vague requirements into verifiable items, constrain the scope of generation with explicit constraints and acceptance criteria, and iterate round by round. In implementation, use a fixed-timestep loop, separate rules from rendering, manage units and themes with data tables, and have automation logic reuse the same functions as manual operations. After each round, use the evaluation checklist to verify functionality, instruction following, and regression stability—this keeps quality consistent as the project grows.
