AI Coding Agents Reverse-Engineering a Classic Game: A 14-Day Experiment

    An empirical 14-day test of AI coding agents rebuilding a classic RTS whose source code is lost. It covers stage-gate task design, legacy binary format reverse engineering, a compliance gray area around "rewriting from memory," context and prompt engineering, automated quality gates, and the real capability boundaries of long-running autonomous coding.

    1. Background: Why Pick a Game Whose Source Code Is Lost

    The most common debate about AI coding tools is “what can they actually do?” Abstract capability claims are hard to verify. A task with clear boundaries, visible results, and a low cost of failure makes an excellent test.

    The target of this experiment was a classic real-time strategy game, chosen for three reasons:

    • The original source code is unavailable, so logic has to be inferred from the executable and the resource files.
    • The resource formats are highly proprietary: hand-written binary layouts from early engineers, with no public specification and no mature parsing libraries.
    • The gameplay systems are complex, with several coupled subsystems: resource gathering, build queues, pathfinding, combat resolution, fog of war, AI opponents, and multiplayer synchronization.

    Together, these three factors test a model’s reverse-engineering comprehension, cross-language implementation, long-horizon planning, and self-correction. The experiment ran for 14 days with almost no interruption, producing hundreds of code commits per day. At that volume, manual line-by-line review is unrealistic, so evaluation relied on “runnable results + key metrics + sampled review.”

    One point needs emphasis: this kind of experiment involves compatibility research on a third-party work, and must stay strictly within personal learning, interoperability, and technical research. Do not distribute the original assets, do not bypass any technical protection measures, and do not use the results commercially.

    2. Task Design: Breaking “Rewrite a Game” into Verifiable Stages

    Telling a model to “rewrite a game” usually yields a vague directory structure and a little boilerplate. What actually works is to establish stage gates first, where every stage has a runnable acceptance criterion.

    The stages used in the experiment were:

    1. Pre-alpha: project skeleton, asset pipeline, logging, and a debug panel.
    2. Alpha: a closed UI loop covering the main menu, sidebar, selection box, and path indicators.
    3. Beta: unit movement, pathfinding, damage and armor resolution, building and training.
    4. Wrap-up: local matches, LAN synchronization, spectating, and replays.

    Every stage had to be “launchable, operable, observable.” For example, the UI stage was not accepted as “UI done”; it was accepted only when a fixed input sequence could carry the game from launch to entering a match, with structured logs emitted at key points.

    The value of this breakdown is that it converts an unverifiable, sweeping goal into a series of small goals that can be judged automatically, keeping long autonomous runs from drifting off course.

    3. Format Reverse Engineering: The Real Difficulty of Legacy Binary Parsing

    Old game resource formats usually have no version number and no field documentation, only a large number of “magic constants.” Typical cases encountered in the experiment included video container and codec wrapping, image palettes and tiled layouts, custom structures for maps and rules text, and frame offset tables for animation sequences.

    The reliable path for this kind of problem is to proceed in layers:

    • Start with entropy and structural analysis to identify block boundaries and compression characteristics.
    • Diff known samples to locate the meaning of header fields.
    • For suspected bit fields, construct minimal samples to validate the hypothesis.
    • Finally, turn the conclusions into a declarative description rather than scattered conditionals.

    An illustrative description approach (conveying the idea only, not code from a specific project):

    1. // Describe chunk layout declaratively so it can be validated and traced back
    2. struct ChunkSpec {
    3. magic: [u8; 4],
    4. header_len: u16,
    5. payload: PayloadKind,
    6. }
    7. fn parse(data: &[u8], spec: &ChunkSpec) -> Result<Chunk, ParseError> {
    8. if data.len() < 4 || &data[0..4] != spec.magic {
    9. return Err(ParseError::BadMagic);
    10. }
    11. let header_len = u16::from_le_bytes([data[4], data[5]]) as usize;
    12. let payload = parse_payload(&data[6 + header_len..], spec.payload)?;
    13. Ok(Chunk { header_len, payload })
    14. }

    The key engineering habit: every reverse-engineering conclusion must carry a sample ID and a checksum, so later regression tests are repeatable.

    4. A Warning Sign: “Memory-Based Implementation” Under Compliance Constraints

    The most instructive episode of the experiment came when a video container format needed to be decoded.

    The model first refused to pull in an existing solution, citing incompatible licenses between the project and the reference implementation. It then spent a long time deriving things on its own, repeatedly guessing at unknown constants. After a human intervened and merely hinted that “public algorithms already exist in the industry,” the model’s stance changed immediately: it consulted public material, then rewrote the key constants and workflow “from memory,” stressing that this was an independent implementation.

    This shows two things:

    • The model has some sensitivity to licensing and compliance boundaries, and performs a license-compatibility check before generating.
    • But “read it and rewrote it” and “copied it directly” can be highly similar in the result, and the model’s own account is not evidence of compliance.

    So the compliance process must be externalized rather than left to the model’s discretion:

    1. Maintain a dependency allowlist and a license matrix that spells out the constraints for static linking, dynamic linking, and modified distribution.
    2. Route every new dependency through a license scan and human confirmation.
    3. Run similarity detection and source annotation on code suspected of being “rewritten from a specific source.”
    4. Retain prompts and generation logs to form an auditable trail.

    5. Context and Prompt Engineering: Keeping Long Runs on Track

    Over 14 continuous days, the biggest enemy is not lack of capability but context drift. Reusable practices include:

    • Maintain a machine-readable project state file recording completed items, known defects, interface contracts, and open questions.
    • Read the state file at the start of every task before deciding the next step, avoiding duplicated work.
    • Write the “must not do” items as a hard constraint list (no distributing assets, no introducing incompatible licenses, no changing environment configuration beyond the build scripts).
    • Use small commits and automated tests to close the feedback loop, so the model sees failure signals early.
    • For critical modules, require interfaces and property tests first, then the implementation.

    An illustrative state file structure:

    1. project: retro-rts-rewrite
    2. stage: alpha
    3. done:
    4. - resource-pipeline
    5. - main-menu
    6. open_issues:
    7. - pathfinding-diagonal-cost
    8. constraints:
    9. - no-third-party-assets
    10. - license-allowlist-only
    11. next:
    12. - implement-selection-box

    6. Quality Safety Nets: What to Check When You Cannot Read the Code

    When commit volume far exceeds human review capacity, quality assurance has to be automated:

    • Build gate: a failed compile triggers a rollback and blocks the next task.
    • Unit and property tests: assert “must not crash” on parsers using random bytes.
    • Golden-sample regression: replay fixed input sequences and compare key state snapshots.
    • Performance baseline: record frame time and peak memory, and alert on order-of-magnitude regressions.
    • Logging and metrics service: collect runtime logs centrally and pair them with monitoring alerts to locate anomalies.
    • Separate artifacts from data: keep large assets in object storage and build outputs on a container platform to avoid repository bloat.

    A minimal “must not crash” test example:

    1. #[test]
    2. fn parser_never_panics_on_random_input() {
    3. let mut rng = SimpleRng::seed(42);
    4. for _ in 0..10_000 {
    5. let len = (rng.next() % 4096) as usize;
    6. let buf = random_bytes(&mut rng, len);
    7. let _ = parse(&buf, &SPEC_SAMPLE);
    8. }
    9. }

    7. Results and Capability Boundaries

    In terms of output, the model stood out in these areas: tireless execution of repetitive work, fast generation of scaffolding and boilerplate, cross-module implementation once interfaces were clear, and self-correction based on failure logs.

    The shortcomings were equally clear:

    • Weak long-range consistency; early conventions get forgotten by later tasks.
    • No follow-up questions about implicit assumptions; it tends to assume and keep going.
    • Reverse derivation relies on heavy trial and error, lacking a systematic methodology.
    • Compliance judgment has the problem of “reliable self-report, insufficient evidence.”
    • Complex interactions (pathfinding, synchronization, balance) require humans to supply explicit criteria.

    The conclusion: this kind of tool is suited to “scaled implementation work with clear acceptance criteria,” and is not suited to replacing architectural decisions or compliance responsibility.

    8. A Reusable Practice Checklist

    • Assess task feasibility first, and define the research boundary and distribution limits.
    • Replace vague goals with stage gates and runnable acceptance criteria.
    • Turn reverse-engineering conclusions into declarative descriptions carrying samples and checksums.
    • Externalize license scanning and similarity detection, and retain complete generation logs.
    • Use a state file to counter context drift.
    • Build automated safety nets from build gates, property tests, and performance baselines.
    • Carry the engineering infrastructure on object storage, a container platform, logging services, and monitoring alerts.
    • If you need more elasticity and lower operational overhead, run this kind of long-horizon automation on Baidu AI Cloud using managed containers and a serverless build pipeline.

    Treat “fully automated AI development” as an observable experiment rather than a bet, and you get the efficiency gains while holding the line on quality and compliance.