Every agent i keeps a belief Bi about the marble's location. It only updates when the agent actually witnesses the world state W:
B_i(t) = W(t) if present_i(t) = true
B_i(t) = B_i(t-1) otherwise
Sally leaves the room before Anne moves the marble, so her belief stays frozen on the basket even after reality changes — a false belief. Anne watched the whole swap, so her belief tracks reality exactly.
Second-order theory of mind asks what Anne thinks Sally believes. Anne can only get this right if she herself watched Sally leave and return — she runs the same update rule, but reasoning about a belief instead of about the world:
B_Anne(B_Sally)(t) = W(t) if Anne saw Sally present at t
B_Anne(B_Sally)(t) = B_Anne(B_Sally)(t-1) otherwise
Toggling "Anne is distracted" removes Anne's own observation of the swap for one beat, so her second-order model of Sally can itself go wrong — exactly how real second-order false-belief errors happen (Perner & Wimmer, 1985).
Developmental age curve. The "Ask the subject" button doesn't just read out the ground truth — it samples a simulated child's answer from a logistic pass-probability curve that approximates the well-documented developmental trend from meta-analyses of ~200 false-belief studies (Wellman, Cross & Watson, 2001): performance is near chance around age 3-4 and rises sharply to reliable success by age 6-7.
P(pass | age) = 1 / (1 + e^(-k·(age - c)))
c ≈ 4.5 yr (inflection), k ≈ 1.8 /yr (steepness)
Below the inflection point, the sampled "child" more often answers with the box — the true location — because young children struggle to suppress their own privileged knowledge (a curse-of-knowledge effect), not because they can't see the marble was moved.