How PingPON learns
Genetic Algorithm
A genetic algorithm mimics natural selection. Instead of writing rules for the paddle, we create a population of random neural networks and let them compete.
- Population: 24 neural networks, each with different weights.
- Fitness: each network plays a short round. Networks that hit the ball more often and miss less get higher scores.
- Selection: the top 25% survive to the next generation.
- Crossover and mutation: surviving networks combine weights and add small random changes.
Over many generations the population learns to track the ball and anticipate bounces.
Neural Network
Each paddle controller is a feed-forward network. The right-paddle AI receives five inputs:
- Ball horizontal position
- Ball vertical position
- Ball horizontal velocity
- Ball vertical velocity
- Current paddle position
The inputs flow through a hidden layer and produce one output: the direction and speed the paddle should move.
Lab, Arena, and AI vs AI
The Lab trains the population, shows the live network, and plots fitness over time. The Arena lets you play against the best saved brain. AI vs AI lets two copies of the best brain compete, with the left side using mirrored inputs.
Sessions and Exports
Your current generation and best network are saved in the browser. You can also export the best brain as a JSON file and import it into the Arena on another device.