Evaluating LLM-Generated Interactive Programs: Methods and Best Practices
A practical, model- and library-agnostic framework for evaluating interactive code generated by large language models. It shows how to define pass/fail criteria before judging visuals, verify instruction consistency against the rendered output, check geometric and physical plausibility, align reinforcement-learning maze visualizations, and record reproducible results across multiple independent retries.
Interactive code generation is becoming a common way to measure the engineering ability of large models: a single prompt may ask for layout, animation, physics constraints, and an operable interface at once, and sometimes even a visualization of the learning process. A flashy result does not mean the task is done. If the chain of thought claims a certain style but the final output has none of it; if the spacing between objects violates common sense and makes the target action impossible under the rules; if a control has too little contrast against the background and the user cannot even see the object to operate — all of these should be recorded as failures, not as “the visuals are fine.”
This article abstracts these tasks into a practical evaluation method that is not tied to any specific model or graphics library. It applies to browser-based 2D or 3D demos, sliding puzzles, simple physics games, and reinforcement-learning visualizations on a grid world.
Define “passing” before judging the visuals
Break acceptance into must-have items and bonus items. Must-have items include: the program starts, the main loop does not break, interactive objects are recognizable, the core rules are executable, and key geometric relationships are correct. Bonus items include lighting, particles, material style, and whether numeric labels look good. When a must-have item fails, bonus items must not rewrite the conclusion into a pass.
One generation is not enough. Interactive programs are sensitive to random seeds, canvas size, and resource loading order, so you should retry independently several times under the same prompt and record the failure mode of each attempt, rather than representing capability with the single best run. If four attempts respectively show an oversized subject, a missing scene, an inoperable interface, and misaligned layers, the problem is structural, not an occasional typo.
Instruction consistency: chain of thought cannot replace the rendered result
Models often promise styles like “ink wash” or “antique wood grain” in their reasoning text, but the final pixels are a generic gradient or solid color blocks. Evaluate based on the running screen. When a style cannot be genuinely implemented with the current tech stack, the reasonable behavior is to explicitly degrade and state the limitation, not to fabricate that it has already been implemented in the chain of thought.
Three things can be checked. First, whether the style words in the prompt map to actual drawing parameters — such as brush-stroke texture, low-saturation palette, paper texture, or wood-grain textures — rather than appearing only in comments. Second, if resource loading fails, whether there is a visible fallback rather than silently switching to another style. Third, the acceptance script should compare the “claim” against the “pixels or scene graph”: if it claims ink wash but the scene samples no texture at all, record it as inconsistent.
Geometry and physics common sense
The passing line for sliding-block puzzles is: the occupied cells of the blocks do not overlap, the exit and the slidable directions follow the rules, and the initial layout can be enumerated or is at least solvable by hand. A model aligning the grid only shows that the layout data structure is basically correct; it does not show that the solver or hint animation is correct.
Physics-based games rely more on spacing. Take a bowling-style clear-the-pins game as an example: the pin formation should satisfy that the gap between adjacent pins is smaller than the “transmissible collision” range allowed by the ball’s effective collision diameter plus the pin width, and the first throw should have a chance to knock down more pins through a chain reaction. If the pin spacing is enlarged so that the ball can only hit isolated targets and clearing all pins in one throw is geometrically impossible, that is a rule-modeling error, not a matter of feel. If the darkness is too high and the ball, pins, and background are nearly the same color, that is a visibility failure: even if a collision happens, the evaluator cannot confirm it.
It is recommended to export read-only debug values in the scene: pin-center coordinates, pin radius, ball radius, minimum gap, and an approximate contrast value. When the gap is on the order of the ball diameter or larger, judge it as a failure directly, without relying on the naked-eye “feeling that it can’t be hit.”
Reinforcement-learning maze: alignment before convergence
Grid-world visualizations commonly fail in four ways.
First, the agent sprite is far larger than a single cell, covering half the map, so even a correct policy cannot be observed. The sprite should be limited to about 0.6–0.8 times the cell width, with the anchor at the cell center.
Second, the maze geometry is not generated: there is only an empty canvas or incomplete walls. Assert the counts of walls, paths, start, and goal before allowing the training loop to start.
Third, the interface exists but cannot be operated. Common causes are events bound to the wrong canvas, pointer events swallowed by an overlay, or the training thread blocking rendering. Gameplay acceptance should include at least reset, single-step, and pause. If any one of the three is unavailable, it has not passed.
Fourth, the action layer and the terrain layer are misaligned. The policy’s cell index does not match the drawing row/column, or the camera, zoom, and padding are not accounted for in the coordinate transform, showing up as the agent “walking inside walls” or a Q value stuck to an adjacent cell. Use the same row/col → x/y function everywhere, and forbid using the cell center in one place and the cell corner in another.
The illustrative coordinate convention is as follows; it only shows the alignment approach and is not the interface of any particular product:
cell = maze[row][col]x = padding + col * cellSize + cellSize / 2y = padding + row * cellSize + cellSize / 2agent.anchor = centerqLabel.position = (x, y)
Printing Q values on the floor is a reasonable, explainable design: the values change with iterations, making it easy to see whether exploration has spread out. But “the final loss or TD error appears to decrease” only shows signs of convergence in the optimization process; it cannot make up for being unplayable or having misaligned layers. The evaluation order should be: terrain is valid → the agent can move and does not pass through walls → a human can operate it → then check whether the values converge and the labels are readable.
If other implementations diverge during training, record the learning rate, discount factor, exploration-rate decay, and whether the reward is sparse at the same time. Divergence and misalignment are different defects; do not merge them into one “did not pass.”
How to write useful evaluation records
Fix the following for each trial: the original prompt, the canvas resolution, the retry index, the failure category, whether it is playable, key geometric quantities, and whether training brought the TD error below the threshold within the set number of steps. Recommended failure categories form a closed set: not rendered, not interactive, geometry violation, style inconsistency, layer misalignment, non-convergence, performance freeze.
For regression, use the same set of assertions rather than re-“feeling it out.” For example: the pin gap is below a given upper limit; the agent’s bounding box falls entirely within the current cell; there is no standable marker on a wall cell; when a style resource is missing, the interface shows an explicit degradation message. This way the conclusions from multiple retries can be compared and will not be swayed by lighting and particles.
Practical advice for prompts and implementation
The prompt should state the hard constraints clearly: cell size, upper limit on pin spacing, minimum contrast, the ratio of the sprite to the cell width, the buttons that must be provided, and “explicitly degrade styles you cannot achieve.” Putting verifiable conditions at the end of the prompt is more effective than piling on adjectives.
For implementation, layer things: terrain data, policy table, rendering, and input should not directly rewrite each other’s indices. Rendering only reads the terrain and the Q table. Input only changes the “current cell” and performs collision queries. Decouple the training step from the drawing step to avoid long loops freezing the interface.
Resource and style failures must be visible. When loading a texture fails, use a high-contrast solid color and show the degradation reason, avoiding a nearly all-black screen. Debug builds can overlay grid lines and indices; turn them off in release builds.
Summary
The quality of an interactive program depends on whether the rules hold, whether objects are visible, whether layers are aligned, whether claims are delivered, and — after these prerequisites are met — whether the learning process converges. Visual effects can only count as a bonus. Do multiple independent retries against the must-have items, and replace subjective impressions with geometric quantities and operability assertions, to reliably judge whether a code generation truly passes.
