Q-Learning Grid World Visualiser

Watch a reinforcement learning agent learn to navigate a grid world in real time. Adjust hyperparameters, observe Q-value heatmaps, and see optimal policies emerge step by step.

Please verify you are human to use the visualiser.

How Q-Learning Works

Grid World Environment

The agent navigates a 5×5 grid with walls, hazards, and a goal. It receives +10 for reaching the goal, −5 for stepping on hazards, and −0.1 for each step to encourage efficiency.

Q-Table Learning

The agent maintains a table of Q-values Q(s, a) for every state-action pair. After each step, it updates the Q-value using the Bellman equation to gradually converge on the optimal policy.

Epsilon-Greedy Exploration

With probability ε, the agent takes a random action (exploration). Otherwise, it picks the action with the highest Q-value (exploitation). This balance is critical for discovering optimal paths.

Policy Emergence

As training proceeds, the arrows on the grid converge to show the optimal policy — the shortest safe path from start to goal, avoiding walls and hazards.

The Q-Learning Algorithm

Q-learning is one of the foundational algorithms in reinforcement learning. It learns an action-value function Q(s, a) that estimates the expected cumulative discounted reward of taking action a in state s and then following the optimal policy. The update rule is:

Q(s, a) ← Q(s, a) + α · (r + γ · maxa′ Q(s′, a′) − Q(s, a))

where α is the learning rate, γ is the discount factor, r is the immediate reward, s′ is the next state, and the max is taken over all possible actions in s′. This off-policy update means Q-learning converges to the optimal Q-values regardless of the exploration strategy used, given sufficient exploration.

For a deeper dive into Q-learning with a complete Python implementation, see our tutorial on Q-Learning on FrozenLake from Scratch. To understand how Q-learning extends to deep neural networks, read about Deep Q-Networks with Experience Replay. The reward on this grid is handed to the agent; when a reward is specified rather than given, the policy optimises the proxy instead of the goal, and GRPO from scratch takes the opposite route to a value function, scoring a group of samples against their own mean rather than learning a critic. For the connection between Q-learning and dynamic programming, see Value Iteration and Q-Learning.

The same reward-and-update machinery now sits behind LLM post-training, where preference data replaces the grid and the reward model replaces the environment. Getting that loop into a product is our LLM implementation consulting work. Deciding whether it is worth attempting on a given problem comes first, under AI pilot design.

Related Tools

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Q-Learning Visualiser FAQ

Common questions about Q-learning, grid worlds, and reinforcement learning