Back to Tools
Coding

Red Blob Games: A* Pathfinding

By Amit Patel / Red Blob Games

Interactive graph-search explanations for choosing BFS, Dijkstra or A*.

guide
A seven-column grid compares a six-step route of cost 21 through expensive terrain with an eight-step detour of cost 8.
Original synthetic pathfinding example. Movement is orthogonal, and the starting cell is not charged. This is not output from an executed game. Original explanatory artwork prepared for GameSlash with AI assistance. Documentation is the factual source only; no source imagery reused. Not an official screenshot or gameplay capture. Concept source

Use it for: Routes around walls or movement budgets with different terrain costs.

Start: 1) Build a small graph with a dead end. 2) Use BFS for equal costs. 3) Add terrain costs and compare Dijkstra with A* using a non-overestimating heuristic.

Concept diagram compares equal-cost BFS, weighted Dijkstra search and A* with score f equals g plus h.
Original overview, not an implementation or guarantee. Graph-search details, heuristic conditions and unreachable goals must be handled correctly. Original explanatory artwork prepared for GameSlash with AI assistance. Documentation is the factual source only; no source imagery reused. Not an official screenshot or gameplay capture. Concept source

Try checking: Compare total path cost, not just tile count, and handle an unreachable destination.

Limits: The output is a graph path. Character motion and changing obstacles still need game-specific handling.

Source: Author’s guide

View source