Skip to content

About

Give a model a few seconds of gameplay video. It works out the mechanics, writes the game, plays it, and patches itself.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pixel2Playable

Give a model a few seconds of gameplay video. It works out the mechanics, writes the game, plays its own version, compares it to the recording, and patches itself.

Live showcase · How it works · What the scores mean · Results · What this does not show

Original footage on the left, the model's reconstruction on the right

Left: three seconds of a game. Right: a game written from those pixels alone. 0.97 match.


No source code. No assets. No description of the rules. The model gets a contact sheet of frames and four full-resolution stills, and everything after that is inference.

video -> frames -> perception -> input tape -> game.js -> headless capture -> score -> critic
                        ^                                                       |
                        +--------------------- patch ---------------------------+

How it works

The model does not generate a web page. It generates one JavaScript object:

window.GAME = {
  meta: { title, W, H, controls },
  reset(rng) {},        // full state reset, seeded
  step(input) {},       // advance exactly 1/60 s
  draw(ctx) {},         // flat fills only
  state() {}            // entities, events, score, dead
};

The canvas, the fixed-timestep loop, the keyboard and the sandbox are ours and are always correct. That is what makes the same artifact both playable by a person and measurable by a machine, step by step. The model writes about 150 lines of pure logic instead of a document, which fails far less often than asking for a page.

The pipeline then replays an inferred input tape through the generated game in a headless browser, captures every frame and every state, and scores the result against the footage.

What the scores mean

Three of the four numbers are computed from data. One is the model's opinion, and the interface labels it as such.

trajectory compares the player's path, with both spaces normalised to a unit square. The position on the original side is measured from the frames, not taken from the model's report: tracker.py slides a window sized by the sprite the model described and scores it by colour match over an integral image. Comparison stops at the reconstruction's first death, and coverage records how much of the footage was still comparable. Obstacle placement comes from a seed that pixels cannot reveal, so after the first divergent collision the two runs are no longer the same experiment.

events compares the ordered sequence of consequence events: scores, deaths, collisions. Two exclusions, both deliberate. Input events do not count, because the tape is built from the jumps observed in the footage and scoring those would only prove the tape was replayed. The first version of this metric did count them and reported a perfect 1.00 on a run whose reconstruction never touched a pipe. Timing does not count either, for the same seed reason: a faithfully reconstructed pong collides at a different second, and two runs each producing two collisions were scoring zero on a gap of 0.75s. What survives is order, which is where the information is. Scoring twice and then dying is a different game from dying immediately.

dynamics compares fitted gravity, jump impulse and scroll velocity wherever both sides expose a comparable value. The constants on the original side are fitted from the measured path at a denser sample rate than the model ever sees, because ffmpeg frames are free and model tokens are not. On the flappy demo this recovers 858 px/s2 against a true 960, and an impulse of -300 against a true -330, from pixels alone.

visual is a 0 to 100 judgement by the model on a side-by-side sheet. It is the only model-judged number and the interface prints MODEL-JUDGED next to it.

total is the renormalised weighted mean: trajectory .35, events .25, visual .25, dynamics .15. A component that cannot be compared is dropped, never counted as zero.

Results

Twenty games. Three are familiar shapes with public implementations everywhere: flappy, pong and runner. The other seventeen were written for this project and did not exist beforehand, so nothing could have memorised them. A library of famous clones would prove recall, not reconstruction.

Three reconstructions: runner at 0.97, canyon at 0.57, drift at 0.24

Three reconstructions, best to worst: 0.97, 0.57, 0.24.

games median range
familiar shapes 3 0.87 0.63 to 0.94
written for this project 17 0.50 0.24 to 0.95

The gap is the obvious reading and it is not the interesting one. The original games are not uniformly worse, they are far more spread. The best of them, mosaic at 0.95, sits above every familiar game's median. Variance separates the two groups, not a ceiling.

analyse.py prints the current table. rescore.py regenerates every number from stored artifacts without calling a model, which is how two of the metrics got corrected after the runs had already happened. Some scores went down.

What this does not show

Stated here rather than left for someone else to find.

The familiar side is three games. Running each of them four times produces twelve numbers and still three games, and the comparison is only as strong as that.

Nothing here separates novelty from difficulty. The low scorers may simply be harder games, with more entities or stranger physics. Perturbing a familiar game's rules and re-measuring would tell the two apart, and that experiment was not run.

The model still supplies every semantic answer: which sprite is the player, what colour it is, what the controls are, what the rules are. tracker.py supplies the metric ones. That split is the point, because a verifier that asks the model where the player was is not verifying anything. What remains model-supplied and therefore uncheckable is the consequence-event annotation, since no blob tracker can see a score, and visual.

This works on short, simple 2D gameplay with a visible player and repeatable controls. It is not a claim about 3D games, menu-heavy footage, or games whose rules never appear in a few seconds of play.

An earlier version of this section claimed a clean memorisation gap, on partial data. The full set did not support it.

The failure worth reading

On the first end-to-end run the generated game was correct, reproducing its specified gravity to a rounding error, and the reported scores were near zero. Perception was at fault: the model stated a gravity of 920 px/s2 and then reported per-frame positions that fit 24. The metrics measured a real disagreement and blamed the wrong side.

Underneath that sat a sampling bug. A fixed budget of frames was being spread across the whole clip, so a 14 second recording was sampled at 1.7 fps against a roughly 2 Hz flap cycle. The positions were right and the fitted physics was meaningless, because you cannot recover a parabola from samples further apart than the motion itself.

Three things came out of it, all in the code. tracker.py, which stopped the verifier depending on the thing it verifies. A critic image that is six legible rows instead of twenty-four unreadable cells, which had been scoring noise. And a sampler that uses a fixed rate over a fixed window.

A run can score low for two different reasons, and the run directory tells them apart. Compare fitted.original against fitted.reconstruction in iter_*/score.json. If the reconstruction's constants match worldmodel.json and the original's do not, the simulation is right and the perception is wrong.

Everything is inspectable

runs/<id>/ keeps the frames, every request and response in calls.jsonl, the tape, the traces, the generated games, and the score inputs, including both player (measured) and player_claimed (reported).

That directory is a quarter of a gigabyte of PNGs and stays out of the repository, which for a while made the claim above true only on the machine that produced it. export_evidence.py writes evidence/, five megabytes of the text that settles arguments: per run, the world model, the generated source, the tape, the scores with the fitted constants from both sides, and the call log. evidence/index.json lists every run with the models that served it. That field, not any label in the interface, is the one to check.

Running it

uv venv && uv pip install -e .
cp .env.example .env          # add a z.ai key
uv run python make_demo_videos.py    # record the twenty reference games
uv run python pipeline.py static/demos/orbital.mp4
uv run uvicorn app:app --reload      # http://127.0.0.1:8000

preflight.py answers whether this is ready to ship in about five seconds, and checks provenance from the call logs rather than from a label. LAUNCH.md is the release checklist.

Replaying a stored run makes no model call, so the library is browsable with no key configured and no network.

Which model answered

glm.py is the only file that talks to a model, and it talks to one: Z.ai, on the model named by P2P_MODEL, which defaults to glm-5.3-flash. The name the interface shows is that same value, because a label that can disagree with the transport is a label worth nothing.

Every call is appended to runs/<id>/calls.jsonl with the model that served it, before anything is scored. evidence/index.json collects that field per run, and preflight.py fails on any finished run whose call log names a model other than the configured one. That file, not the header in the interface, is the thing to check. A false claim about which model did the work is the one mistake here that cannot be walked back.

Sessions, authorship and the library

A session is a random id in the visitor's browser, not an account. A handle can be typed in and travels as a header on the request that starts a run, then lands in the run's manifest, where the library reads it back.

Sign in with X is OAuth 2.0 with PKCE, and a verified handle is drawn differently from a typed one, because a self-declared name presented as verified would be a worse lie than having no accounts at all. The access token is deliberately not stored. Identity is all this needs, and keeping a token to post on someone's behalf when nothing posts on their behalf is holding a credential for no reason.

seed_library.py fills the library by driving the real API the way the browser does, one full pipeline run per row. The runs are real and inspectable. Only the author labels are seeded, and those handles are shaped so they cannot be mistaken for a real person's account.

Bring your own key

The idle screen offers use your own next to the demo key. The key stays in the browser's localStorage, is sent as an X-Zai-Key header on the single request that starts a run, held in server memory for that run, and then dropped. It is never written to disk, so unlike everything else in the run directory it does not reach calls.jsonl or the manifest.

Sharing

Every run has a permanent link at /r/<run_id> that opens on that reconstruction, with a preview card generated from the run's own frames: source footage on the left, the model's game on the right, the score between them. The two panels are the same size on purpose. A card that gave the reconstruction more room would be arguing rather than showing.

Share card: original and reconstruction side by side with the score

Layout

pipeline.py perceive, tape, codegen, capture, score, critic, loop
tracker.py finds the player in the real frames
metrics.py the four scores, pure functions
runner.py deterministic headless capture
glm.py the only file that talks to a model
static/runtime.js the harness the generated game runs inside
games/ twenty reference games, all against the same contract
share.py, make_reel.py, make_video.py preview cards, reel, submission video
analyse.py, rescore.py, preflight.py read the results, recompute them, check them
SPEC.md the contract everything above is written against

Built for the GLM-5.3 Flash Lightning hackathon.

About

Give a model a few seconds of gameplay video. It works out the mechanics, writes the game, plays it, and patches itself.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages