From Watching to Playing: Auto-Playing Video Games with a Self-Constructed Code World Model

Yao Tong, Jiaxin Qi, Yan Cui, Yuhua Zheng, Jianqiang HuangarXiv 2026

TL;DR

Vision-language models (VLMs) can play video games by looking at screenshots, but querying a giant neural network at every single frame is painfully slow and expensive. Instead of playing directly, PlaySmith uses a VLM once upfront to watch raw gameplay, deduce the game’s physics, and compile that knowledge into fast, reusable Python code. At runtime, this self-constructed "code world model" plays the game with zero VLM calls, slashing latency by over 15x while actually beating the direct VLM at the game.

What Problem Does This Paper Address?

Imagine playing Flappy Bird, except every time you need to decide whether to flap, you have to mail a screenshot to a remote server, wait four and a half seconds for a committee of philosophers to deliberate, and pay a toll. That is essentially how standard VLM game agents operate. Even when the exact same gravity mechanic applies for the thousandth frame in a row, the VLM re-reasons from scratch.

Figure 1: VLM use in game agents. (a) Existing VLM- based agents call the model at each frame. (b) PlaySmith calls it during development and runs the resulting code during gameplay.

A much smarter approach is to amortize that reasoning into a Code World Model (CWM)—an executable program that simulates how the game world works. Prior attempts at CWMs usually cheat a little: they rely on clean, privileged simulator states, RAM values, or neat grid worlds. Inducing a world model directly from raw pixels is much harder because visual gameplay is messy. Autonomous physics (like pipes scrolling left or gravity pulling a bird down) happen simultaneously with player-driven actions (flapping upward), entangling cause and effect in a sea of changing pixels.

Methods

PlaySmith bridges raw pixels and executable code by acting as an automated scientist: it observes, hypothesizes, tests, and compiles three distinct Python modules during a brief offline development phase.

Figure 2: CWM construction and deployment. A VLM labels gameplay frames to build the Observer, and action- conditioned displacements guide Predictor synthesis and revision. At deployment, the controller scores candidate actions using predicted outcomes.
  1. The Observer (Perception): Using standard vision tools (GroundingDINO and SAM), PlaySmith proposes bounding boxes on recorded frames. A VLM filters these crops to train a lightweight local detector (YOLOv8n), then writes deterministic code to link detections across frames so objects keep persistent IDs over time.
  2. The Predictor (World Physics): This is the core novelty. To untangle player control from background physics, the harness computes Action-Conditioned Displacements (ACD)—pairing every executed action with how much each tracked object moved. A statistical test (Kolmogorov–Smirnov distance) flags when an object's movement distribution shifts significantly under a specific action (e.g., bird $\Delta y$ changes when action = flap). Guided by this statistical evidence and replay feedback, the VLM writes a stateful Python simulator (infer_state, transition, render) that tracks hidden variables like velocity and timers.
  3. The Controller (Planning): Finally, the VLM writes a choose_action function. During live play, it uses the Predictor to mentally simulate candidate action sequences several steps into the future, scores the imagined outcomes, and executes the best move—all in local Python with zero online VLM calls.

Datasets

PlaySmith is evaluated across eight 2D browser-based arcade games: Chrome Dino, Flappy Bird, Doodle Jump, Happy Hop, Asteroids, Fruit Catcher, Road Fighter, and Little Ski. The games retain their native keyboard and pointer interfaces. Each game model is built using just 4 training and 2 development episodes (capped at 400 decisions each) and tested on 10 held-out episodes.

Key Insights and Ideas

  • Causality needs statistics, not just raw logs: In ablation studies, stripping away ACD records tanked prediction accuracy ($h_1$ F1 dropped from 0.835 to 0.536). Even more telling: shuffling the action labels barely helped, and removing the KS statistical test hurt noticeably. Giving a VLM raw trajectory data isn't enough; explicitly contrasting movement distributions across actions is what lets it separate "what I control" from "what the world does on its own."
  • Better eyesight doesn't mean better gameplay: Surprisingly, Observer detection accuracy and final game scores ranked VLM backbones inversely (Spearman $\rho = -0.62$). GPT-6.1 Sol had the worst object detection F1 (0.733, frequently missing tiny bullets or springs) yet achieved the highest gameplay score across all models. Once perception is "good enough," the real bottleneck is writing accurate physics and smart control logic.
  • Lookahead beats reflexes: Disabling the Predictor at runtime—forcing the controller to act purely reactively on current observations—hurt scores across all eight games, proving that multi-step mental rollouts genuinely drive better decisions.

Key Results

Using the shared DeepSeek-V4.1-Flash backbone across 10 evaluation episodes per game, PlaySmith decisively outperformed a direct VLM agent:

Table 3: Direct VLM agent versus PLAYSMITH under the same DeepSeek V4.1 Flash backbone. Native scores and cost over ten evaluation episodes per game. The agent pays input tokens at every decision step. PLAYSMITH spends a one-time construction budget and runs evaluation without further model calls. Token counts are shown in thousands for both. Latency is measured in seconds per step during evaluation. The Mean row reports the eight-game mean normalized return Z (marked ∗), token costs, and per-step latency.
  • Higher Scores: Mean normalized return nearly tripled from 0.103 to 0.299, beating direct VLM play in all eight games (e.g., Asteroids jumped from 580 to 2,240).
  • 15x Faster & Cheaper: Mean per-step latency plummeted from 4.526s to 0.293s. PlaySmith used 67% fewer input tokens overall (507.4k one-time construction vs. 1,527.5k during 10 episodes of direct play)—and playing 100 more episodes costs PlaySmith zero extra tokens.
  • Better Multi-Step Rollouts: Under an equal 50k-token budget, PlaySmith's Predictor beat adapted code-synthesis baselines (like Continual and OPINE-World), achieving 0.835 1-step F1 and 0.694 3-step F1, with much gentler multi-step error degradation. Across eight VLM backbones tested, GPT-6.1 Sol achieved the highest overall normalized return (0.706).

Limitations and Future Work

While the authors do not include a formal limitations section, two clear boundaries emerge from the experiments:

  • Small and rare objects: Six of the eight backbones suffered from recall limits on tiny or infrequent entities like bullets, springs, and moving platforms.
  • Long-horizon drift: Simulating continuous physics from pixels still accumulates error over time; in four of the eight games, strict joint rollout survival hit the floor before five consecutive steps for all tested methods. Future directions are not explicitly discussed in the paper.

Summary updated

BibTeX
@misc{tong2026from,
  author = {Yao Tong and Jiaxin Qi and Yan Cui and Yuhua Zheng and Jianqiang Huang},
  title = {{From Watching to Playing: Auto-Playing Video Games with a Self-Constructed Code World Model}},
  year = {2026},
  eprint = {2611.35702},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.35702},
}
Figure