Reinforcement Learning (RL)

Q-learning agent in a grid world

A reinforcement-learning agent learns to navigate a 6×6 grid to the goal (+10) while avoiding traps (−10), starting from zero knowledge. Hit Play and watch the arrows — the agent's best-known move in each cell — sharpen as it learns. Tune the hyperparameters below to see how they change learning speed and stability.

Episode
0
Steps
0
Last reward
0.0
Window success
0/50

Grid world

Arrow shows best action; number below shows the Q-value of that action.

AgentGoal +10Trap −10

Reward per episode

Total reward earned per episode. Trends upward as learning progresses.

Hyperparameters

Learning rate (α)0.10
Discount (γ)0.95
Exploration (ε)0.30
Speed (steps/sec)20

Stopping rule

Success threshold90%
Window size50

Auto-stops when success rate over last N episodes hits threshold. Hard cap: 500 episodes.

How it works

This uses Q-learning, a classic algorithm that learns the value of taking each action in each cell. The agent balances exploration (random moves, set by ε) against exploitation (its current best guess). After every move it updates its estimate using the reward it got plus the discounted value of where it landed (γ), nudged by the learning rate (α). Over many episodes those estimates converge into a policy — the arrows you see — that reliably reaches the goal.