Learn the return
The agent sees seven discrete values for both paddles, ball position, direction, and speed. Q-learning and SARSA establish the first TD-control baselines.
Five levels · three actions · one rally
A lecture-length walk through the five levels: tabular TD, pixel features, Double DQN, DAgger, and the predictive controller that is the submitted image policy.
The five-stage curriculum
Each level adds one control problem. The observation changes, the opponent improves, or both paddles become learned agents. Every policy returns one action: up, down, or stay.
The agent sees seven discrete values for both paddles, ball position, direction, and speed. Q-learning and SARSA establish the first TD-control baselines.
Expected SARSA learns against a weak opponent. The state now needs to support defense, movement cost, and a scoring shot.
Each rally draws from random, weak, tracking, and strong opponents. The policy must act before it knows which one it faces.
Color masks locate the paddles and ball. Two frames supply velocity. Court geometry supplies the future intercept.
The right observation is mirrored, so one image policy works on either side. Self-play agents train with separate replay buffers and optimizers.
01 · Levels 1 to 3
Levels 1 to 3 bin paddle height, ball pose, heading, and speed
into a tuple. That is a tabular MDP: one Q-value per
(s, a). The catch is size, about 829k tuples, so
most states are never visited.
my_y own paddle height binopp_y opponent paddle height binball_x ball horizontal binball_y ball vertical binball_vx left or rightball_vy up, flat, or downball_speed discrete speed classDrag the paddles and ball. The tuple updates the same way the environment discretizes the court. Highlighted action is the tracking rule we actually submit for these levels: stay while the ball leaves, otherwise chase ball height.
(3, 4, 5, 2, -1, 1, 1)
02 · Lectures 7 and 8
SARSA, Q-learning, and Expected SARSA all store
Q(s, a) and act ε-greedy. They differ only in the
bootstrap target. We trained them on Levels 1 to 3. Held-out
learned tables stayed near 20% win rate, so the submitted
tabular policy is the tracking rule.
y = r + γ Q(s′, a′)
y = r + γ max Q(s′, a′)
y = r + γ Σ π(a′|s′) Q(s′, a′)
Ready. Step update applies one backup to a toy Q-row.
03 · Levels 4 and 5
The score bar is cropped out. Color masks recover left paddle,
right paddle, and ball, each as a normalized
(x, y). Feature DQN, DAgger, and predictive control
all start from this map. Four frames stacked make a 24-D vector
so velocity is implicit.
Move the objects. The vector below is what the pixel agents see.
[0.08, 0.50, 0.92, 0.42, 0.55, 0.30]
04 · Function approximation
A 128×128 MLP trains on the 24-D stack with replay, a target
network, Huber loss, and Double DQN targets
y = r + γ Q_target(s′, argmax Q_online).
Level 4 zoo: 6.7% (n = 30). Level 5 self-play vs tracking: 25%
(n = 20). Residual Double DQN keeps intercept features at test
time and still lost the gate: 10% zoo, 70% Level 5 (n = 10).
Toy trainer: loss and ε only. The real run is in the metrics JSON.
05 · Submitted pixel policy
Two frames give velocity. A triangle-wave fold handles wall bounces. The paddle moves to an impact offset aimed at open court, with a deadband that holds stay when it is already there.
Held-out: 95% Level 4 zoo, 100% Level 5 tracking, n = 20.
student_agent.py uses this for images unless a
promotion gate is true.
Reward ledger
A rally can end with a point or a timeout. On timeout, cumulative reward selects the winner. The final controller stays still while the ball travels away, which saves movement cost without giving up the next interception.
-0.0010.000+0.060+0.020+10.000Rally ready. Select a side and add events.
Imitation learning · Ross et al. 2011
Predictive control already wins the gate. DAgger asks whether a
24-D Q-network can copy that expert from stacked centroids at
test time. The expert is PredictivePixelAgent.
Labels are expert actions.
The failure mode of cloning
Let πE be an expert policy and dπ the
state distribution induced by a learner π. Behavioral cloning
minimizes a classification loss on states drawn from
dπE. At test time the agent acts from
dπ. One wrong action puts the ball on a path the
expert never labeled. The next state is then even farther from
the training support. Ross, Gordon, and Bagnell (AISTATS 2011)
bound the extra cost of this compounding as
O(T²ε) for a horizon-T task when the per-step
classification error is ε.
The DAgger fix
Dataset Aggregation trains πi on the current labeled
set D, rolls out πi (or a mixture with the expert),
asks the expert for the correct action on every visited state,
and appends those pairs to D. The next clone is fit on a mixture
of expert states and learner states. The same paper shows the
extra cost then scales as O(Tε). The name is
literal: the dataset grows by aggregation.
L_BC = CE(Q(s), a_E), s ~ d_{π_E}
a = a_E w.p. β_e, else ε-greedy Q
L = L_Huber + λ CE(Q(s), a_E)
a* = argmax_a Q_θ(s_{t-3:t}, a)
Color masks recover left paddle, right paddle, and ball as
normalized (x, y). Four successive 6-D frames are
stacked into a 24-D vector, the same representation as Feature
DQN. Velocity is implicit in the stack. The bounce fold is not
an input.
PredictivePixelAgent is the expert: two-frame
velocity, triangle-wave wall fold, aim offset 0.60, deadband
0.012. Every DAgger step queries that controller for
a_E ∈ {UP, DOWN, STAY} on the current observation,
even when the learner's action is the one executed in the env.
Q-values are treated as logits. 1,200 Adam steps of cross-entropy on 15,383 expert labels (50 Level 4 demo episodes). Then 220 DAgger episodes with β from 0.80 to 0.10. New states come from the mixture policy. Labels still come from the expert. The expert buffer is a deque of capacity 80,000.
After DAgger, β = 0. The online net trains with Double DQN Huber targets and λ = 0.25 times CE on a minibatch from the expert buffer (Hester et al., DQfD). Level 5 loads those weights and repeats the four stages against tracking noise 0.00, 0.05, and 0.10.
Source: artifacts/metrics/level4_imitation_dqn.json, field eval. Final held-out zoo win rate on a fresh n = 20 seed set is 75%, plotted in Figure 3.
Source: artifacts/metrics/level4_imitation_dqn.json, field bc_losses. Loss is cross-entropy on Q-logits. This stage fits expert actions.
Held-out evaluation
Level 4 uses a 15-second horizon and pixel observations at render
scale 2. Level 5 tests tracking opponents at three noise levels.
Evaluation is deterministic and performs no parameter updates.
Error bars are binomial standard error
√(p(1−p)/n). A bar at 1.00 with n = 20 has SE = 0.
PredictivePixelAgent) held-out
win rate. n = 20 independent seeds per bar. Horizon 15 s.
Level 4 opponents as named. Level 5 is a duel against
TrackingAgent at the stated action noise.
Source: artifacts/metrics/competition_eval.json. Weak is the only Level 4 setting below 95%. All 20 Level 5 episodes were wins at each noise level.
Sources: imitation_vs_predictive.json (n = 20), residual_vs_predictive.json (n = 10), level4_dqn_eval.json (n = 30), level5_selfplay_eval.json (n = 20 vs tracking). Promotion requires matching or beating predictive on both clusters. Both learned gates remain promote: false.
Implementation
The submission class dispatches by observation type. Tuple states
use tabular tracking. Image states use predictive control unless
residual_promoted.json or
imitation_promoted.json sets promote: true.
The score bar is excluded from the agent state.
Color masks find two paddles and the ball.
Velocity and wall geometry locate the next hit.
A deadband limits movement near the target.
Reproduce locally
The repository includes locked dependencies, all training entry points, tests, evaluation, report source, the GIF generator used by this page, and a browser arena under Play.
Read setup notesuv sync
# Fast integration check
bun run train:smoke
# Full training and evaluation
bun run train
bun run eval
# DAgger + Double DQN for Levels 4 and 5
bun run train:imitation
bun run eval:imitation
# Verify the submission agent
uv run python -m unittest discover -s tests -v
# Rebuild this site's GIFs
uv run python tools/generate_site_assets.py
Project artifacts
The report explains the equations and design decisions. Raw JSON records the held-out results. The submission file contains the exact runtime policy.
Methods, equations, experiments, results, and limitations.
JSON · held-outTwenty seeds for every Level 4 and Level 5 setting.
JSON · held-outPredictive vs DAgger + Double DQN on Level 4 zoo and Level 5 tracking.
Python · entry pointObservation dispatch and competition policy construction.
Markdown · complete mapCommands, file inventory, caveats, and next steps.