AI-Assisted Coding in Practice: Modifying Classic Strategy Games

    Evaluating AI-assisted coding requires observing whether it can solve real, complex problems rather than merely generating code. This article explores how AI tools can assist in modifying classic real-time strategy games, detailing practical methods for addressing AI attacks, pathing congestion, "ghost grids," and crashes. It covers the boundaries between configuration and engine modifications, strategies for optimizing large-scale unit movements, ensuring state consistency, and leveraging AI for reverse engineering. By establishing an engineering loop of evidence collection, hypothesis testing, and regression validation, developers can effectively utilize AI tools to solve tangible development challenges.

    1. From “Powerful Models” to “Is the Problem Truly Solved?”

    The most convincing way to evaluate AI-assisted coding is not by observing how many lines of code it generates, but by whether it helps developers solve a real, long-standing problem with clear acceptance criteria.

    Modifying a classic real-time strategy (RTS) game is exactly such a scenario: developers want to preserve the original gameplay and narrative style while making the AI opponent continuously organize attacks, preventing large groups of infantry from frequently jamming at intersections, and fixing issues where grids remain occupied after units disappear or where specific actions cause game crashes.

    These requirements superficially fall under “game modification” but actually involve multiple layers:

    • Configuration layer: Unit attributes, production conditions, squad sizes, and behavior scripts.
    • Rules layer: Transport, garrison, attack range, experience attribution, and target selection.
    • Engine layer: Pathfinding, collision, spatial occupancy, object lifecycle, and task scheduling.
    • Engineering layer: Patch compatibility, save consistency, exception diagnosis, and regression testing.

    The value of AI-assisted coding tools lies in helping developers break down vague wishes into observable, locatable, and verifiable problems, rather than attributing all difficulties to “tweaking a few parameters.”

    While the original practice materials present modification directions such as continuous attacks, congestion improvement, and bug fixes, they do not provide reproducible code, complete runtime logs, or quantitative data. Therefore, the following focuses on executable methods, treating unverified effect descriptions as general conclusions.

    2. Clarify Boundaries: What Configuration Can Do vs. What the Engine Must Do

    1. Configuration Adjustments Only Utilize Existing Mechanisms

    Many older games describe unit speed, weapon range, passenger capacity, and production rules through text configurations. As long as the engine has already implemented the corresponding logic, adjusting the configuration can yield noticeable effects.

    For example, changing the attack squad size, rally point location, or departure conditions can reduce the probability of units clustering at the same location. However, this does not mean the underlying pathfinding algorithm has been improved.

    To determine whether a requirement can be fulfilled through configuration, answer three questions:

    1. Does the engine have the corresponding behavior?
    2. Can the configuration reach that behavior branch?
    3. Will the modification break the semantics of other units or scenarios?

    If the engine lacks a mechanism for “passengers firing out from a transport vehicle,” adding a seemingly reasonable configuration field will not automatically create this capability. If a tool-generated field name lacks parsing code support, it is merely invalid text.

    2. Missing Capabilities Require Complete Data Flow Support

    Taking passengers firing from a transport unit as an example, it is not as simple as “allowing fire.” It also requires addressing:

    • Is the target selected by the transport unit or independently by the passengers?
    • Is the range calculated from the transport unit’s center or from a virtual firing position?
    • Do passenger cooldowns progress independently?
    • Who receives the kill and experience attribution?
    • How is the passenger attack state cleared when the vehicle is destroyed?
    • Can these states be restored after loading a save file?

    Similarly, garrisoned buildings might feature two types of design: one where the building selects weapons based on garrison status, and another where each garrisoned member participates in attack resolution separately. Both affect damage composition, attack frequency, kill statistics, and experience distribution; they cannot be assumed to be the same implementation based solely on visual effects.

    For non-landing flying units, moving over a target to attack versus maintaining distance for ranged attacks may belong to different task state machines. Simply increasing weapon range does not necessarily change how the move task handles target positions.

    These examples collectively illustrate that modifying attributes and extending mechanisms are two entirely different engineering tasks.

    3. Break Down Large-Scale Attacks into Production, Rally, and Combat Phases

    “The AI opponent continuously produces units” and “large groups of units attack smoothly” are not the same goal. The former primarily involves combat scripts, while the latter also involves spatial organization and task scheduling.

    1. Production Phase: Avoid Boundaryless Unit Accumulation

    Continuous attacks should not be equated with infinite production. Total unit count affects object updates, target searches, collision processing, and the number of pathfinding requests.

    A more reasonable approach is to establish a production and reinforcement strategy with upper limits:

    • Allow reinforcements only after the current attacking squad suffers a certain level of losses.
    • Delay the departure of new squads if the rally area is noticeably congested.
    • Prioritize organizing existing idle troops rather than continuously producing new ones.
    • Apply different grouping and departure conditions for different unit types.

    These strategies do not guarantee an increased win rate, but they prevent concentrating all pressure on the engine’s weakest links.

    2. Rally Phase: Prevent Units from Competing for the Same Grid

    Large-scale infantry jams often occur not because the global route is entirely wrong, but because all units receive the same endpoint and end up competing for limited space.

    You can change “reach a specific point” to “enter a specific area,” and then assign multiple available positions within that area. Position allocation should consider terrain, building obstacles, squad direction, and existing occupancy, rather than mechanically using fixed coordinate offsets.

    The illustrative logic is as follows; the names are used only to explain the algorithm and do not represent actual game interfaces:

    1. Input: Squad, Target Area, Current Spatial Occupancy
    2. Candidate Positions = Collect traversable positions within the target area
    3. Candidate Positions = Exclude hard obstacles and confirmed occupied positions
    4. For each unit:
    5. Select a candidate position based on distance and traversal cost
    6. Mark the position as assigned in this round
    7. Issue a move task
    8. If candidate positions are insufficient:
    9. Expand the rally area, or enter in batches

    This method addresses endpoint competition. If congestion occurs in narrow passages, simply adjusting endpoints is insufficient; you must also arrange batch passage or staggered departures.

    3. Combat Phase: Distinguish Attack Targets from Move Targets

    After units enter combat, if they persist in heading to their initial rally point, a phenomenon may occur where “the front line is engaged, but the rear continues to push forward.”

    Therefore, you need to check task switching rules:

    • Does the move task pause when an attackable target is found?
    • Does the unit resume its original route after the target becomes invalid?
    • Does it attempt to find an alternative position when the current attack position is unreachable?
    • Is there a yielding or reassignment mechanism after multiple move failures?

    Here, you should not arbitrarily add logic like “immediately re-path upon failure.” Synchronous mass re-pathing by many units can create new computation spikes. A safer approach is to stagger retry times, limit the number of requests in a single update, and prioritize units that have been blocked for a long time.

    4. Congestion Optimization Must Balance Global Routing and Local Conflicts

    Global pathfinding answers “how to get from A to B,” while local avoidance answers “how to avoid nearby units in the next step.” The two cannot be confused.

    For older grid-based maps, common problems include:

    • Temporary obstacles being mistaken for permanently impassable areas.
    • Two units repeatedly fighting over the same position.
    • Units yielding to each other and then advancing simultaneously.
    • Massive numbers of units recalculating routes in the same frame.
    • Attack targets continuously moving, causing frequent route invalidation.

    You can prioritize low-risk measures:

    1. Handle moving units and hard obstacles like buildings differently.
    2. Add a limited wait for brief blockages instead of immediately discarding the entire route.
    3. Trigger local detours or task reassignment for long-blocked units.
    4. Introduce staggered mechanisms for retries to reduce synchronous computation.
    5. Use batch passage in narrow areas rather than forcibly increasing squad density.

    Whether these measures are effective depends on the engine’s existing structure. You cannot directly apply complex algorithms without understanding how units are updated. Better algorithms that introduce too many states may also cause save compatibility or synchronization issues.

    5. “Ghost Grids” are Primarily a State Consistency Issue

    So-called “ghost grids” typically refer to positions where there is no visible object, but the system still determines the space as occupied. This may result from spatial occupancy information not being released in time, or from invisible objects, temporary reservation states, or desynchronization between display and logic.

    Therefore, when diagnosing, you must first distinguish between “invisible” and “truly non-existent.”

    1. Establish a Tracking Chain for Occupancy Information

    Pay attention to the following events:

    • Unit spawn and destruction.
    • Cross-grid movement of units.
    • Entering or leaving transport units and buildings.
    • Unit removal, transformation, or teleportation.
    • Spatial reconstruction after save file restoration.
    • Cleanup after abnormal task interruption.

    For each occupancy change, it is best to record the object ID, original position, new position, and operation reason. This allows you to determine which process missed the release action.

    2. Fix the Source, Avoid Crude Clearing

    Periodically clearing all occupancy information might temporarily eliminate jams, but it could also disrupt normal path reservations and collision relationships.

    A more reliable approach is to establish consistency conditions:

    For active objects that require spatial occupancy registration, their position state and occupancy registration should remain consistent; objects that are destroyed or no longer occupy ground space should not retain corresponding valid occupancy records.

    You can add checks in the debug environment to output context when anomalies are detected. Full reconstruction of occupancy information should only serve as a controlled diagnostic or recovery tool, and must account for other occupancy sources in the map.

    6. How AI Coding Tools Assist in Reverse Engineering and Repair

    Provided there is legal authorization and compliance with licensing constraints, AI tools can assist in analyzing disassembly, pseudo-code, call relationships, and runtime logs. However, they cannot magically determine a function’s purpose, nor can they replace actual debugging.

    1. Provide Evidence, Not Just Describe Wishes

    “Help me fix pathfinding” is too broad. More effective inputs include:

    • Clear reproduction steps.
    • Behavioral differences before and after modification.
    • Relevant function snippets and call locations.
    • Confirmed data structure fields.
    • Runtime logs and exception scenes.
    • Current hypotheses, and evidence supporting or refuting them.

    You can ask the tool to structure its response as follows:

    1. Confirmed facts
    2. Possible explanations
    3. Missing evidence
    4. Minimal verification experiment
    5. Potential side effects
    6. Rollback plan

    This approach reduces the risk of treating guesses as conclusions.

    2. Independently Verify Every Inference

    For instance, if the tool suggests a field represents the “current grid index,” do not directly modify it just because the explanation sounds reasonable. Observe its changes across different scenarios: stationary, moving, entering a vehicle, dead, and loading a save.

    If it displays special values in certain scenarios, check whether these values carry other state meanings.

    AI tools are best suited for proposing candidate explanations, organizing complex control flows, and generating verification ideas. Final confirmation should come from program behavior, debugging evidence, and regression results.

    7. Mode-Based Combat Configurations Require Determinism and Traceability

    Selecting different combat configurations based on game modes allows standard skirmishes and high-intensity battles to adopt different strategies. However, the implementation must clarify when configurations are loaded.

    A safer approach is to determine the mode during match initialization, load the corresponding rules, and complete validation, rather than repeatedly swapping key behavior configurations during runtime.

    You need to check:

    • Whether the mode selection is consistent with the actually loaded content.
    • Whether there is a clear fallback strategy for missing configurations.
    • Whether the current configuration can be identified in logs or the UI.
    • Whether it remains consistent after saving and loading progress.
    • Whether there is residual configuration state from a previous match.

    Even if primarily targeting single-player gameplay, determinism should not be ignored. Hidden states and residual configurations make issues difficult to reproduce, directly increasing debugging costs.

    8. Prove Modification Value Through Testing, Not Just Visual Scale

    “Many units on screen” only indicates high pressure; it does not prove modification quality. You should compare results before and after modification under the same map, unit structure, and test conditions.

    It is recommended to observe at least four sets of metrics:

    Behavioral Effect: Squad rally completion time, the proportion actually reaching the combat area, and the number of units idle for extended periods.

    Traffic Quality: Intersection wait times, number of move failures, number of route recalculations, and number of anomalous occupancy records.

    Operational Cost: Frame time changes, pathfinding processing time, memory usage trends, and performance degradation as unit count increases.

    Stability: Whether long-term operation crashes abnormally, whether saving and loading work normally, and whether transport, garrison, and unit destruction processes produce residual states.

    Test scenarios should not only consist of open maps, but also include narrow roads, bridges, dense buildings, frequently moving targets, and simultaneous destruction of large numbers of units.

    Try to introduce only one major variable per modification and retain a rollback version. Otherwise, even if the effect improves, it is difficult to know exactly which modification caused it.

    9. True Implementation is an Engineering Loop

    Modifying classic games reveals a pragmatic value of AI-assisted coding: it can lower the developer’s cost of reading unfamiliar logic, organizing hypotheses, and designing experiments, giving requirements that previously stayed in the idea stage a chance for further verification.

    However, this does not mean the model can automatically fill engine capability gaps, nor does it mean generating a patch completes the engineering task.

    The reliable path is always:

    Define Goals -> Determine Modification Layer -> Collect Runtime Evidence -> Form Testable Hypotheses -> Implement Minimal Changes -> Stress and Regression Testing -> Document Conclusions and Retain Rollback.

    For individual modders, the most noteworthy aspect is not whether the tool can provide a seemingly complete answer, but whether it helps them continuously shrink the range of the unknown. Only when requirements, code, runtime behavior, and test results correspond to each other does AI-assisted coding truly transform from “looking strong” to “solving the problem.”