AI Coding Under UEFI Shell: Building a Tank Battle Game and Lessons Learned

    This article documents a hands-on experiment that uses a top-down tank battle game built for the UEFI Shell as a stress test for AI code generation. It explains why firmware-level graphics are a strong test case, how to turn a vague request into verifiable engineering constraints, and where the first real blocker appeared: toolchain build errors rather than game logic. The article shares practical guidance on context management, token cost control, layered logic and rendering design, and a behavior-based verification checklist, concluding that success in constrained low-level AI collaboration depends on requirement formalization, the choice of verification target, and disciplined stop-loss decisions.

    1. Why UEFI Shell Is a Good Stress Test for AI Coding

    When evaluating the code generation ability of AI coding tools, many people default to tasks such as “write a sorting algorithm” or “build a web scraper.” The problem with these tasks is that they have a large semantic space, a mature dependency ecosystem, and high fault tolerance. Even when a model gets something wrong, it can often “guess correctly” by leaning on the vast amount of public examples. What really separates models are scenarios with strict constraints, scarce public corpus, and a high cost of failure.

    Graphics programs at the firmware layer meet all three conditions. They run before the operating system is loaded. There is no ready-made graphics library, no file system abstraction, and no multi-threaded runtime. The only things you can rely on are a small set of protocols defined by the firmware specification. Handing a model a composite task like “implement a top-down tank shooting game,” which involves a real-time loop, input handling, collision detection, and a state machine, is essentially testing whether it can complete system-level design inside unfamiliar and rigid boundaries.

    The value of this kind of task lies not in the artifact itself, but in how it exposes problems: where the model starts inventing non-existent interfaces, at which step it falls into unproductive retries, and how developers should step in to cut losses.

    2. Task Definition: Turning a Vague Request into Verifiable Engineering Constraints

    A vague requirement description is the primary cause of AI coding failures. An input like “make a tank battle game” leaves the model to fill in the gaps by probability, and the result inevitably diverges. A reusable approach is to break the requirement into four layers:

    • Runtime environment layer: specify that the program runs in the firmware Shell, is implemented purely in software, and does not depend on any external runtime.
    • Graphics output layer: agree to obtain the resolution and frame buffer through the graphics output protocol defined in the firmware specification, using 640x480 with BGRA pixel format, with the application writing pixels itself.
    • Gameplay logic layer: fix a top-down map view, player tank movement and shooting, enemy tanks spawning in batches, a base icon that must be protected, destructible brick walls, power-ups including invincibility, armor piercing, and extra lives, clearing all waves to win, and no audio.
    • Non-functional layer: stable 30 FPS refresh, no dynamic memory leaks, and the ability to return to the Shell on abnormal exit without triggering a firmware reset.

    The fourth layer is the easiest to overlook, yet it determines whether the program is merely “runnable” or actually “usable.” In a firmware environment, a single invalid memory access often triggers an exception redirect directly, and debugging costs are far higher than for user-mode programs. Stability therefore must be written into the constraints in advance.

    At the same time, to give the model persistent context, you can create a project description file in Chinese at the project root and lock down the four layers above. Every later round of interaction reads the same “contract.” This step costs very little but significantly reduces the wasted effort caused by repeated explanation.

    3. The First Real Blocker: Adapting the Build Environment

    In practice, the first thing to break is often not the code logic but the build chain.

    The initial attempt chose an emulated execution environment common in the firmware development community as the runtime target. The follow-on tasks piled up: modifying the platform description file to include the new module, adjusting the firmware volume mapping configuration, and resolving conflicts between dependency libraries and compiler options. At this stage the model showed a typical “optimistic retry” pattern: constantly tweaking configuration, repeatedly triggering full builds, and guessing back and forth between error messages, which were themselves highly verbose and further diluted the context.

    A general lesson is worth extracting here: when build errors come from the toolchain itself rather than business code, the marginal return of letting the model keep trying drops toward zero very quickly. There are three signals to watch for:

    1. Several consecutive rounds of changes only move the error location without changing the nature of the error;
    2. The model starts modifying shared configuration files unrelated to the task;
    3. The compute cost of a single round rises noticeably while verifiable progress is zero.

    The correct stop-loss action is to switch the verification target instead of continuing to patch the build chain. Changing the runtime target to a general-purpose system virtualization solution downgrades the problem from “adapting to the firmware build system” to “application logic correctness,” and the latter is what the model is genuinely good at. This decision pulls the cost curve back from exponential growth to linear.

    4. Context Management and Cost Control

    Token consumption for low-level development tasks is far higher than for ordinary business code. The reason is not the number of lines of code but the size of error logs. A single failed full build can produce hundreds of lines of diagnostic output, and feeding it back repeatedly quickly crowds out usable context.

    Actionable optimization strategies include:

    • Layered verification: first ask only for a minimal skeleton that “displays a pixel block and exits on a key press,” confirm the graphics path works, then stack gameplay modules on top.
    • Targeted error feeding: do not paste the full log; extract only the first root-cause error plus a few lines of surrounding context.
    • Milestone settlement: each time a runnable milestone is reached, capture the result and archive the notes so later rollbacks do not lose context.
    • Budget awareness: set a clear limit for “environment exploration,” and switch approaches once it is exceeded instead of investing endlessly.

    This method is not limited to firmware development; it applies to any AI collaboration task that involves an unfamiliar build chain.

    5. Layered Implementation of Logic and Rendering

    Once the runtime environment is working, the game itself can be handed to the model to advance module by module, but the developer needs to hold the architectural boundaries.

    The main loop should use a fixed time step, decoupling logic updates from frame submission so frame rate fluctuations do not cause collision detection drift:

    1. while (running) {
    2. Accumulate elapsed time;
    3. while (accumulated >= FRAME_STEP) {
    4. UpdateInput();
    5. UpdateEntities();
    6. ResolveCollisions();
    7. accumulated -= FRAME_STEP;
    8. }
    9. RenderScene(); // Write the whole frame to the frame buffer
    10. }

    The rendering layer should stick to “full-frame redraw” rather than incremental updates. In a firmware environment without double buffering, incremental updates tend to produce tearing and ghosting; writing the whole frame combined with a fixed step is simple to implement and visually stable. The map is best described by a two-dimensional array: destroying a brick wall just changes the state of the corresponding cell, and collision detection degenerates into a cell lookup, greatly reducing logical complexity.

    The entity system should be managed with an array of structures plus an active flag, avoiding frequent memory allocation and release. Particle effects should have a fixed total cap, and once exceeded the oldest slot is reused, preventing unbounded growth from dragging down the frame rate.

    6. Verification Checklist: From “It Compiles” to “Ready to Ship”

    Whether this kind of low-level graphics program is truly complete should be judged by observable behavior, not by what the model claims:

    • After a cold start, it loads normally in the Shell and enters the welcome screen;
    • Input response has no accumulating latency, and exit returns cleanly to the Shell;
    • After ten minutes of continuous running, there is no memory growth trend and no abnormal restart;
    • All eight maps switch correctly, and the behaviors of the four enemy tank types are distinguishable;
    • All five power-up effects can be triggered and do not stack into illegal states;
    • Both end paths, base destroyed and all waves cleared, trigger correctly.

    Writing this checklist into the project description file up front noticeably improves the model’s convergence, because it no longer has to guess “how far is far enough.”

    7. Conclusion

    The core conclusion of this experiment is not whether a given model is “good enough,” but this: in constrained low-level development scenarios, the success of AI collaboration depends mainly on how formalized the requirements are, the choice of verification target, and stop-loss discipline, rather than raw generation ability. Toolchain problems such as the build environment should be decided quickly by humans, while decomposable and observable problems such as logic and rendering are suited to bulk progress by the model. With this division of labor, an originally high-cost exploratory task becomes a controllable and reproducible engineering practice.