AI Coding in Practice: From Model Selection to Delivering a Web Game
This article explains how to use an AI-assisted coding environment to build and validate a small browser-based tank game. It covers the distinct roles of models, coding environments, and agents; how to evaluate model choices and usage limits; how to define permissions and project boundaries; how to turn a vague game idea into testable requirements; and how to organize development, testing, and delivery around evidence rather than generated code alone.
1. From “Models Can Write Code” to “Systems Can Deliver Projects”
Developing a small application with an AI-assisted coding environment often involves a familiar sequence: choose a model, open a project, submit a request, generate code, and preview it locally. The workflow may look simple, but the final result depends on much more than a model’s ability to generate code.
The environment must provide the model with accurate project context. It must also reliably perform file operations, run checks, and return useful error information. A model may generate code that appears correct in isolation but still fails when integrated into the actual project.
For this reason, evaluating an AI coding solution should not focus only on whether it uses a newer model or offers free usage credits. More meaningful questions include: Can it turn natural-language requirements into runnable, understandable, and maintainable software within clear permission boundaries?
This article uses a browser-based tank game as a practical example. The task is large enough to include interaction, state management, collision detection, and UI feedback, yet small enough to reveal a common issue in AI-assisted development: code can be generated successfully while the application itself does not work correctly.
The practices described below are general guidance. They do not represent feature guarantees for any specific tool, and the example should not be treated as a completed benchmark result.
2. Understanding the Roles of Models, Coding Environments, and Agents
1. A Model Handles Reasoning and Generation, but It Is Not a Complete Development System
A language model is mainly responsible for understanding requirements, proposing implementations, generating code, and analyzing errors. It may suggest a sound solution, but it can also miss edge cases or produce code that does not match the project because its context is incomplete.
For example, a model may know how to implement axis-aligned rectangle collision detection. That does not mean it understands the coordinate conventions, rendering scale, or entity data structures used in a particular project. Without accurate context, even locally correct code may not fit into the existing codebase.
2. The Coding Environment Connects the Model to the Project and Its Tools
An AI coding environment handles tasks such as reading files, presenting modifications, executing terminal commands, and returning runtime results. These capabilities form the connection layer between the model and the real project.
If file retrieval is inaccurate, the model may edit the wrong location. If execution results omit key error messages, the model may repeatedly attempt ineffective fixes. If modification scope is not constrained, even a small request can lead to extensive rewrites.
The quality of tool execution and feedback mechanisms is therefore as important as the model itself.
3. Conversational Analysis and Agent Execution Require Different Strategies
AI coding interactions generally fall into two categories:
- Conversational or question-and-answer interaction is useful for explaining code, discussing architecture, identifying possible causes, and reviewing implementation plans. In this mode, ask the model to provide its reasoning before deciding whether to modify the project.
- Execution-oriented agents are better suited to multi-file changes, test additions, command execution, and iterative repair. Before enabling them, define which directories they may access, what tasks they may perform, and when they must stop.
These modes are not simply different levels of capability. They serve different goals and carry different risks. For an unfamiliar codebase, analyzing first and executing later is usually safer than immediately asking an agent to “fix the entire project.”
3. Model Selection and Usage Evaluation: Look Beyond Free Requests
1. Choose Models Based on the Task, Not Only on Model Recency
A web game involves requirement decomposition, interaction logic, basic visual layout, and error correction. When selecting a model, evaluate the following capabilities:
- Can it understand the complete requirement and consistently follow constraints? For example, if the game must run locally, it should not introduce remote services on its own.
- Can it work with project context, including the existing file structure, coding conventions, and run instructions?
- Can it fix issues based on actual errors instead of repeatedly regenerating the entire codebase?
- Is its output maintainable, without excessive duplication, unnecessary abstraction, or avoidable dependencies?
For a simple prototype, a faster model may be sufficient. For multi-file refactoring or difficult debugging, reasoning reliability and context handling are generally more important. Compare models using the same task and acceptance criteria rather than mixing impressions from unrelated tasks.
2. Automatic and Fixed Model Selection Serve Different Purposes
If an environment provides automatic model selection, its routing logic may not be fully visible to users. This can reduce decision-making overhead during daily work, but fixed model selection is usually more reproducible during evaluation.
Record the model identifier, task description, initial project state, execution permissions, and acceptance results. Even when these conditions are the same, generated results may still vary. A single success or failure is not enough to represent overall capability.
3. User Quotas Are Not the Same as Underlying Resource Costs
Some services measure usage by the number of interactions, while others account for input and output volume, compute resources, or other factors. A user interface showing “one task” does not necessarily mean that only one model call occurred underneath.
One agent task may involve multiple reasoning steps, file reads, command executions, and repair attempts. When evaluating quotas, confirm:
- Whether individual tasks have time or scale limits
- Whether tool execution is metered separately
- How failed or interrupted tasks are charged
- How long quotas remain valid and how they can be replenished
- Whether connecting an external model service creates additional costs
For developers, a more useful metric is the resources required to complete one task that passes acceptance testing, rather than the nominal number of available conversations. Free quotas are useful for experimentation, but they should not be treated as a guarantee of long-term cost or service availability.
4. Establish Project and Permission Boundaries Before Execution
1. Use a Separate Project Directory
When validating an AI coding workflow for the first time, use a dedicated experimental directory rather than opening a workspace that contains multiple business projects. Keep only the necessary source code, assets, and documentation in that directory. Do not mix in real customer data, credentials, or internal documents.
If the project already contains code, save a recoverable version first. After each milestone, review and preserve the current state. If later changes introduce issues, you can return to a verified version instead of asking the model to reconstruct prior work from memory.
2. Workspace Trust Prompts Are Not Just Formalities
Granting trust to a workspace may affect the execution of task scripts, runtime configurations, or related extensions. For projects from unknown sources, inspect automatic execution behavior and external dependencies before granting trust.
Allowing an agent to modify files does not mean allowing it to delete arbitrary directories, access external networks, or execute every terminal command. Permissions should be granted only as needed for the current task, while high-risk operations should remain subject to human confirmation.
3. Protect Credentials When Connecting External Model Services
If a coding environment supports model service configuration, store access credentials in controlled configuration locations. Do not place them in source files, commit them to version control, or paste them into ordinary task descriptions.
Also verify the scope and handling rules for request data. Before submitting code, remove sensitive configuration and business data. For enterprise projects, technical connectivity is only one condition; whether the data is allowed to leave the environment requires a separate decision.
5. Turn “Build a Game” into Testable Requirements
Vague instructions encourage models to fill in many features on their own, which can quickly expand the scope. A better approach is to define a minimum runnable version first and extend it in stages.
A task description could be written as follows:
“Develop a single-player tank game that runs in the browser. The player can move and fire bullets. The map includes obstacles, and enemy tanks can move and attack. The interface displays health and score, and the game supports restarting after game over. The first version should use only basic graphics, introduce no remote services, and use no external assets that require authorization. First provide an implementation plan and acceptance checklist, then modify files in stages. Before adding dependencies or performing high-risk operations, explain why they are needed.”
This description defines the deliverable, core functions, implementation boundaries, and execution rules. However, gameplay details still need to be agreed upon.
For example:
- Can tanks move diagonally?
- Do bullets disappear when they hit obstacles?
- Can player and enemy tanks overlap?
- Do enemies continue to spawn?
- Does the game stop updating immediately after game over?
These details directly affect code structure and test cases. They should not all be postponed until after implementation.
For the first stage, focus on a complete gameplay loop: start the game, move and shoot, detect collisions, reduce health, display game-over feedback, and restart. Audio, advanced levels, and sophisticated enemy behavior can be planned as later requirements.
6. Organize Development by Milestones Instead of Generating Everything at Once
1. Build the Basic Structure
Start with the page, game area, status display, and input handling. At this stage, verify that the application starts, graphics can be rendered, and input is captured correctly.
The logic should separate input handling, state updates, and rendering. A small project does not need to be split into many files, but it should also avoid placing all behavior in a single unreadable function.
2. Implement Player Behavior
Add movement, boundary constraints, direction, and shooting. Movement distance should be calculated based on elapsed time rather than using a fixed displacement per frame. Otherwise, speed will vary across different refresh rates.
The basic logic is:
displacement = movement speed × elapsed time for this updatenew position = previous position + movement direction × displacement
If the page is paused and later restored, the elapsed time for one update may become unusually large. Limit the maximum update interval or use a more stable update strategy to prevent the tank from jumping across the map.
3. Add Collision Detection and Object Lifecycles
Basic collision detection can use axis-aligned rectangles. If two rectangles overlap both horizontally and vertically, they can be treated as colliding. Whether touching edges should count as a collision must be defined consistently.
Pay particular attention to relationships between bullets and targets, tanks and obstacles, and entities and map boundaries. A fast bullet may pass through a thin obstacle between two updates. In such cases, consider reducing the update interval, checking movement in smaller steps, or testing the movement path.
Object deletion also requires care. Removing members directly while iterating through a collection can cause later objects to be skipped. A safer approach is to mark invalid objects first and remove them in a separate cleanup step.
4. Add Enemy Behavior and Game-Over States
Enemy behavior can initially follow simple rules, such as changing direction on a timer, selecting a new direction when blocked, and firing based on a cooldown. Prioritize stable behavior before introducing complex decision-making.
At a minimum, game state should distinguish between active gameplay and game over. When the game enters the end state, define which updates stop, which visual feedback remains, and which data must be reset when the player restarts.
7. Acceptance Testing Must Cover More Than “It Runs”
A successful local preview only shows that the application can start under current conditions. It does not prove that the implementation is complete.
Evaluate the game across the following dimensions:
- Functional correctness: Do movement, shooting, collisions, scoring, health, and restarting work as agreed?
- Boundary behavior: What happens when multiple direction keys are pressed, firing continues for a long time, browser focus is lost, or the user switches away from and returns to the page? Are keys stuck or states corrupted?
- Runtime stability: After running for a long time, are expired bullets and defeated enemies cleaned up? Are event listeners and timers registered repeatedly?
- UI adaptation: When the window size or display scale changes, do the rendering area, collision coordinates, and input coordinates remain consistent?
- Delivery completeness: Does the project include startup instructions, implemented features, known limitations, and suggestions for future work?
Issue reports should also include reproduction steps, expected behavior, and actual behavior. For example:
“During gameplay, hold a movement key, switch to another window, release the key, and return to the page. The tank continues moving.”
This is much more actionable than simply saying, “Movement is broken.”
After a fix, do not only verify the reported issue. Check related behavior as well to avoid introducing regressions through a local change.
8. Evaluate AI Coding Results by Delivery Quality, Not Generation Appearance
Large amounts of code, long plans, and fluent explanations do not necessarily indicate project quality. A simple tracking sheet can be used to evaluate requirement coverage, first-run results, manual intervention count, modification scope, repair effectiveness, and final resource usage.
Time should also be broken down into separate stages: requirement clarification, generation, dependency installation, runtime checks, and manual acceptance. This makes it easier to identify whether the bottleneck comes from requirement quality, model capability, tool feedback, or the runtime environment instead of attributing all delays to model speed.
For small experimental projects, an agent may be able to complete much of the execution loop. For existing production systems, work should be divided into narrowly scoped tasks that can be accepted independently. As functionality becomes more complex, human architectural judgment, code review, and release approval become increasingly important.
9. Safety Boundaries Matter Even More When Expanding Beyond Coding Tasks
Agents with file-operation and tool-calling capabilities can also organize documents, transform data, and automate repetitive workflows. However, as task scope expands, it is no longer appropriate to treat the environment like an experimental directory where anything can be modified freely.
Specify the input directory, output directory, permitted data, and operations that require confirmation. Before bulk renaming, overwriting files, deleting content, or sending data externally, generate a preview and require user approval before execution.
In addition, text in project documentation, web pages, or file comments should be treated as data to process. It must not gain higher authority simply because it contains operational instructions. Clearly separating user authorization from external content is an important way to reduce the risk of unintended actions.
10. Conclusion
The core of AI-assisted programming is not finding a way to generate large amounts of code for free. It is building a reliable development loop: define requirements clearly, select an appropriate model, constrain tool permissions, execute work in stages, fix issues based on runtime evidence, and validate the result against an acceptance checklist.
A browser game is a useful vehicle for practicing this process, but successful results on a small game do not imply that complex business systems can be delivered without supervision. The reusable outcome is a clear way to express requirements, a recoverable project management process, and a habit of never treating generated output as proof of correctness.
