Reading a clean explanation of Q-learning feels a lot like understanding it. Can you predict what a broken learner will do? In Breaking Bellman, you predict, watch it train in your browser for a few seconds, then repair its update rule by swapping words. There are 17 levels, playable in any order. Menu repairs are easier than inventing PPO, but you still have to find the broken word.

Take CartPole: push a cart left or right to keep its pole upright. The network's guess of future discounted reward is called Q. One run reached 4,700,000 and was still climbing. Hmm. Each step pays 1, each later reward counts 0.99 as much, and episodes stop after 200 steps. Before looking below, pick the largest possible discounted return: (a) 200, (b) about 86.6, (c) unlimited.

Show the return answer

Answer: (b). Add 200 terms: 1 + 0.99 + 0.99² + … = (1 − 0.99²⁰⁰)/(1 − 0.99) ≈ 86.6. Choice (a) is the undiscounted score ceiling. Choice (c) would require both no discount and no time limit. Even with unlimited time, this discount caps the return at 100.

CartPole: how big can Q get?The CartPole update rule written as a sentence with two swappable phrases. The discounted return ceiling is 100 with no time limit and about 86.6 with the 200-step limit. Largest Q estimate and score for four variants: as written, 4,700,000 and still rising, score 9. Replay, 110,000, score 91. Frozen target, 81, score 57. Both, which is DQN, 65, score 144. Panel 4: greedy learners end on the best of 10 machines in 33% of runs, and 78% when 10% of pulls are random. In a two-door world the peak left-door rate is 82% for Q-learning and 16% for Double Q-learning.CartPole: how big can Q get?One learner, one broken rule, two word swaps① The update rule, as the game writes itNudge Q(state, push) toward1 + 0.99 × max Q(next state)learning from [the latest step]with max Q from [the network itself].1 reward for each step the pole stays up0.99 discount γ: each later step counts 0.99 as muchmax Q(next) the network's own guess. A high guessmakes a high target, which trains a higher guess.Swap 1, replay: [the latest step] → [random past steps]Swap 2, frozen target: [the network itself] →[a copy of it, held fixed for a while]Adding the max Q term to a learner that only chased the payoutrebuilt Q-learning (1989). The game names it and links the paper.② The ceiling no honest Q can pass1 + 0.99 + 0.99² + … = 1 / (1 − 0.99) = 100That is the ceiling with no time limit.Stopped at 200 steps: (1 − 0.99²⁰⁰) / (1 − 0.99) ≈ 86.6The game score adds the same rewards with no discount: 0 to 200.③ Largest Q reached (log scale), and score101001k10k100k1M10M4,700,000, still risingAs writtenlatest step + own Qscore 9 / 200110,000Replayrandom past stepsscore 91 / 20081Frozen targeta fixed copy's Qscore 57 / 20065Both = DQNboth swapsscore 144 / 200no-limit ceiling 100In these runs, replay slowed the blow-up, the frozen copystopped it, and both swaps together scored highest.④ The max hides two more trapsGreedy choice: always pull the top-rated machine10 slot machines. Share of runs that end on the best one:always greedy33%random on 10% of pulls78%Max in the target: noisy guesses come out highA max over noisy estimates tends to pick one that came out too high.Two-door world (Sutton and Barto): the left door leads to 10machines that pay −0.1 on average. Peak left-door rate in training:Q-learning82%Double Q-learning16%Double Q-learning picks the action with one estimate and scoresit with a second one.CartPole was meant to show this bias, but there Q sat below thereturns the policy actually earned. The max is still in its target,so the bias is still possible there.
Toy simulations using the game's engine; CartPole differs from physical robot control. The rule paraphrases the game's wording. CartPole rows summarize 5 seeds; training budget, hyperparameters, dispersion and aggregation are unspecified. Panel ④ also lacks run counts, horizons and smoothing. An AI assistant wrote most code and helped run 250+ experiment configurations. Source: EXPERIMENTS.md.

A stable learner can still learn the wrong thing. The bonus level's 2D dog uses PPO to fetch a stick, with +1 for retrieval, −0.01 per step and up to +0.05 per step for facing it. It learned to face the stick and sit, earning about 2.12 per throw. Three times more training made it a better sitter. Let's compare what sitting and fetching actually pay.

Sit or fetch?
  • Assume a 60-step throw and the full 0.05 facing bonus every step.
  • Sit: 60 × (0.05 − 0.01) = 2.4.
  • Hypothetical 15-step fetch: 15 × (0.05 − 0.01) + 1 = 1.6.
  • Sitting wins above a bonus of 0.01 + 1/(60 − 15) = 0.032222… per step; equality gives a tie.
With the facing bonus, the dog faces the stick and stays still: no retrieval after 60 steps and 0% of test throws retrieved.
Facing bonus: no retrieval after 60 steps; 0% of test throws retrieved, with test count unspecified. Inspired by Huggy, in a simpler 2D world.
The same PPO dog retrieves the stick in 16 steps after the facing bonus is replaced with potential-based shaping.
Replace the facing bonus with potential-based shaping: pay in proportion to progress toward the stick and charge for moving away. The same PPO dog retrieves in 16 steps in this depiction.
Predict the round trip
No discount; the dog walks 1 m away, then 1 m back. Scheme 1 pays +1 per meter closer and zero for moving away. Scheme 2 pays the change in potential Φ = −distance, at 1 reward unit per meter. What are their total shaping rewards?
  • (a) +1 and 0
  • (b) 0 and 0
  • (c) +1 and +1
Show the shaping answer

Answer: (a). Scheme 1 pays 0 out and +1 back. Scheme 2 pays −1 out and +1 back. Over longer trips, each middle potential is added once and subtracted once, leaving Φ(end) − Φ(start), which is zero on a closed loop. Choice (b) misses scheme 1's free outward movement; (c) misses scheme 2's outward charge.

More from the casino and the cliff

The casino image shows the greedy trap from panel ④ during a run. Gold bars are true average payouts, blue bars are estimates, and the crown marks the best machine, number 7. The learner has pulled machine 8 a total of 995 times.

Ten slot machines: gold bars show true average payouts, blue bars show estimates. Machine 8 has 995 pulls; the crown marks machine 7 as best.

Exploring has a price too: near the cliff, falls cost −100 each.

A learner exploring near the cliff edge falls, receiving a penalty of minus 100 per fall.

Wondering which estimate to trust in the update? See Recipes for choosing a learning target.

Before your next run, calculate the return ceiling, change one ingredient, and predict what the reward will encourage. Play Breaking Bellman or read the code. The free game is one MIT-licensed HTML file and saves progress in your browser.