Snake, learned by playing itself.
Neural networks trained only against copies of themselves, running live in your browser.
How it works
The game. Each turn every snake sees the board st and picks a move
at∈{↑,↓,←,→}. The only reward is the outcome:
r=+1 for winning, −1 for dying.
The network. One small CNN reads 8 planes centred on its own snake (bodies, heads,
food, health) and outputs a policy and a value:
πθ(a∣s),Vθ(s)≈E[∑kγkrt+k].
Learning. PPO nudges the policy toward moves that turned out better than expected,
but never too far in one update:
L(θ)=Et[min(ρtA^t, clip(ρt,1−ϵ,1+ϵ)A^t)],ρt=πθold(at∣st)πθ(at∣st),
where the advantage A^t=∑l(γλ)lδt+l, with
δt=rt+γV(st+1)−V(st), says how much better a move was than the network expected.
Self-play. Every snake is the same network, so it learns by playing copies of
itself (and older versions of itself). After 2.5 hours on a laptop it beats the best hand-written bot in 91%
of games.
source