Evaluating Complex Code Generation and Reasoning in Large Language Models
This article outlines a practical method for evaluating large language models on complex code generation and constraint reasoning, moving beyond short Q&A and single-snippet completion. It defines six observation dimensions and applies them to three representative tasks: an interactive fighting game, a multi-character river-crossing puzzle, and a 3D voxel sandbox, then describes a repeatable scoring process focused on system completeness and stability.
Evaluation Background: From Isolated Q&A to Complex Engineering Tasks
Early evaluations of large language models often used question answering, summarization, translation, or single-block code completion. These tasks usually have clear boundaries and short context. The model only needs to understand meaning or generate a code fragment within a local scope. Difficulty rises sharply when the model must produce a runnable interactive web app, solve a logic puzzle with multi-role constraints, or build a virtual world whose state keeps changing.
Complex tasks share four traits. First, requirements are rarely fully defined in one sentence and often include several implicit constraints. Second, the output is not static text but a system with state, events, loops, and feedback. Third, correctness depends not only on whether the syntax passes, but also on whether runtime behavior matches expectations. Fourth, the model must keep global consistency within a limited context and avoid contradictions.
Evaluating a general-purpose large language model or an AI coding tool therefore cannot stop at “can it generate code.” It should also test requirements decomposition, structural design, state maintenance, error repair, and performance optimization. Using three typical tasks, this article abstracts an evaluation method for complex code generation and constrained reasoning.
Evaluation Dimensions: A Quantifiable Observation Framework
Before the tasks, the observation dimensions should be fixed. Complex work can usually be examined along six axes.
1. Instruction following
Does the model capture both explicit and implicit requirements? If the user asks for blocking, basic attacks, double jump, dodge, multi-element skills, enemy behavior, a scene, and stick-figure presentation, the model should cover as many of these points as possible rather than implementing only one or two.
2. Structural completeness
Does the output form a closed loop, including initialization, input handling, state updates, rendering, collision, win/loss judgment, and restart? Many models can emit local functions but lack an overall architecture, so the code never becomes a runnable system.
3. State consistency
Interactive programs hold a large amount of state: character position, health, skill cooldowns, enemy behavior phases, and time. The model must keep those states from conflicting—for example, jump versus gravity, attack versus hit reaction, and skill use versus resource cost.
4. Runnability and debuggability
Code should not only look plausible; it should actually run. Evaluation should check for obvious syntax errors, undefined variables, failed event bindings, and broken render loops. Clear structure and separated modules also affect later debugging cost.
5. Experience and performance
For games and 3D scenes, feel and performance matter: timely control feedback, reasonable collision, a stable camera, controllable resource generation, and the absence of obvious stutter.
6. Reasoning stability
For logic puzzles or constraint-satisfaction problems, the model must keep multi-step reasoning consistent without external tools. Evaluation should check whether it finds hidden constraints, avoids dropped conditions, and stays stable across repeated trials.
Task 1: Generating an Interactive Fighting Game
The first typical task is a single-file web fighting game. Requirements include blocking, basic attacks, double jump, and dodge, plus five elemental skills—wind, earth, water, fire, and lightning—along with complete mechanics, enemy behavior, scene presentation, and simplified line-art characters.
This looks like front-end code generation, but it tests system modeling. A high-quality output usually includes the following modules.
1. Input system
Keyboard or touch input must be mapped to action intent. For example:
input event -> action intent -> character state machine -> physics and collision -> render feedback
If the model only listens for keys and writes coordinates directly, actions collide: the character may still move freely during an attack, or jump state may be overwritten by gravity logic.
2. Character state machine
State management is central to a fighting game. Common states include idle, move, jump, fall, attack, hit, block, dodge, and skill cast. The model must define transition conditions, for example:
if current state == idle and jump key pressed:switch to jumpif current state == attack and attack animation finished:return to idle
Without a state machine, actions stack, cooldowns fail, and hit detection becomes inconsistent.
3. Combat resolution
Basic attacks, skills, and blocking all need resolution logic. Evaluation should check whether the model distinguishes attack boxes, hurt boxes, block direction, skill range, and active frames. Wind can be designed as ranged displacement or pull, earth as defense or terrain blocking, water as slow or combo linking, fire as damage over time, and lightning as instant high damage or a chain effect.
4. Enemy behavior
Enemy behavior should not be random movement alone. A more reasonable design has three layers—perception, decision, and execution:
sense player distance -> choose approach, defend, attack, or retreat -> execute the action and update cooldowns
Evaluation can check whether enemies chase, block, change attacks when the player jumps, and whether difficulty is configurable.
5. Scene and presentation
The scene is not only a background; it should participate in play through platform height, obstacles, boundaries, and camera follow. If the model can produce a wide scene, a camera that tracks the character, skill effects, and hit feedback, it shows stronger end-to-end implementation ability.
Evaluation takeaway: this task tests whether the model can organize many gameplay points into a runnable system. A strong result need not look elaborate, but mechanics must be complete, state must be clear, and control feedback must be stable.
Task 2: Reasoning About a Multi-Character River Crossing
The second task is a classic multi-character river-crossing problem. Family members and pets share a boat that holds only two at a time, and only some characters can row. Several mutually exclusive constraints apply—for example, when one character is absent, another harms a specific target. The goal is a safe crossing plan.
This task does not depend on running code. It depends on pure language reasoning and tests whether the model can extract entities, roles, constraints, and the goal from natural language, then search states over multiple steps.
Evaluation focuses include:
1. Whether constraint extraction is complete
The model must identify every character, who can row, boat capacity, danger relations, and trigger conditions. If it misses “only some characters can row” or “the boat holds only two,” later reasoning will fail.
2. Whether state representation is clear
A more robust model abstracts the problem as a state set, for example:
state = left-bank character set + right-bank character set + boat position + rower
New states are produced by legal moves. If the model only tries moves in prose, it easily repeats or omits steps.
3. Whether illegal intermediate states are avoided
After every move, both banks must satisfy the safety constraints. The model must check the state before and after the move, not only the final goal.
4. Stability across repeated trials
Constraint reasoning is sensitive to randomness. Evaluation should not rely on a single run. Repeat the test several times and record success rate, error types, and response time. Without external tools, performance better reflects the model’s own planning ability.
Evaluation takeaway: this task works as a logic-reasoning baseline. It does not directly show engineering skill, but it reveals whether the model can plan stably across many steps under complex constraints.
Task 3: Generating and Optimizing a 3D Voxel Sandbox Web Page
The third task is a single-file 3D voxel-style sandbox web page. Requirements include a pixelated look, terrain and tree generation, creatures, placement and destruction, day-night change, weather, infinite terrain, and performance optimization. This is far more complex than an ordinary web page because it combines rendering, resource management, input control, world generation, and performance tradeoffs.
Evaluation can be split into an initial generation stage and an iterative optimization stage.
1. Initial generation
The first version should establish a basic framework:
- Can it render a 3D scene?
- Can it generate terrain and vegetation?
- Does it support movement, camera look, and jumping?
- Can blocks be placed or destroyed?
- Are there obvious direction errors or failed controls?
If the first version reverses movement, cannot jump, or breaks place-and-destroy, the model is weak at input mapping and state updates.
2. Optimization rounds
When the user then asks to fix direction, add jump and flight, refine textures, add lighting and shadow, time passage, sun and moon, weather, infinite terrain, and performance optimization, the model must handle more complex incremental requirements. Evaluation then focuses on:
- Whether it can modify the existing structure locally instead of starting over
- Whether it can introduce a time system that drives lighting
- Whether it can control performance through chunk loading
- Whether it can avoid unbounded memory growth in an infinite terrain
- Whether control feel and visual style stay consistent
3. Balancing performance and experience
An infinite world is not the same as generating without limit. A reasonable approach usually includes chunk management, distance culling, object reuse, lazy loading, and resource reclamation. Evaluation should check whether the model understands these general engineering principles rather than simply stacking features.
A schematic structure:
world managerchunk loaderterrain generatorentity managerrenderercameralightingmaterialsinput controllermovementlookinteractiontime and environment systemday and nightweather
Evaluation takeaway: this task tests incremental development inside a complex system. A strong model can produce an initial version, locate problems from feedback, fix control logic, and keep the overall architecture stable as features grow.
A Combined Method: From One-Off Demos to Repeatable Experiments
To reduce subjective judgment, use a structured evaluation process.
1. Define the task type
Separate code generation, logical reasoning, incremental optimization, and performance tuning. Weights differ by type. Code generation should emphasize runnability; logical reasoning should emphasize constraint completeness.
2. Design a score sheet
A 100-point scale or a five-level scale can be used:
instruction coverage 20%structural completeness 20%runtime correctness 25%experience and performance 15%reasoning stability 10%maintainability 10%
3. Repeat each test
A single result can be affected by randomness. Run each task at least three times, record full success, partial success, and failure, and summarize why failures occur.
4. Separate tool-free and tool-assisted settings
A tool-free setting tests the model’s own planning. A tool-assisted setting tests its ability to call external capabilities, verify results, and correct errors. The two should not be mixed.
5. Pay attention to failure modes
Failures are more informative than successes. Common modes include missed constraints, state conflicts, reversed controls, runaway performance, messy code structure, and inability to modify incrementally. Evaluators should record failure types rather than only a total score.
Conclusion: System Ability and Stability Are the Core of Complex-Task Evaluation
Taken together, complex code generation and constrained reasoning reflect model ability more realistically. A strong model is not defined by whether it can emit a piece of code that looks complicated. It is defined by whether it can stay structurally clear, logically consistent, and stable at runtime under multiple constraints, and whether it can keep improving after feedback.
Developers should not judge this ability from a single output or surface polish. A sounder approach is a task set, a score sheet, and repeated experiments, judged across instruction following, state management, runnability, experience and performance, and reasoning stability. Only then can the model’s applicable range and limits in real engineering work be identified more accurately.
