Article
Game Algorithms (Pathfinding Part 3) - Fixing A* on Open Grids with Jump Point Search
On open grids, A* spends a great deal of its time on “another path of the same cost”. JPS skips over those cells in a single straight-line stride and stops only where a turn is genuinely needed; the result is exactly the same as A*, yet it expands an order of magnitude fewer nodes.
A problem with A*
There is another kind of waste in A*, and it is especially bad on open grids.
Walking from A to B across a stretch of open ground, there are often dozens or hundreds of shortest paths of equal cost: diagonal then straight, straight then diagonal, diagonal and straight alternating... A* cannot tell them apart, so it drops every cell on all of those paths into the open list and expands them one by one. This is path symmetry.
JPS (jump point search) was introduced by Daniel Harabor and Alban Grastien in 2011. Its idea: since all those paths are equally good, keep only one of them — travel in a straight line, in one long “jump”, and stop only at cells where a turn might be needed. Those cells are called jump points.

Eight-direction grids
JPS is designed for uniform-cost 8-direction grids, which differ from the maps in the earlier articles in two ways:
8-direction movement: besides up, down, left and right, units can move diagonally. A straight step costs 10 and a diagonal step costs 14 (about 10√2; integers avoid floating-point error).
No terrain cost: every cell is either passable or a wall.
Diagonal movement comes with one further rule: no corner cutting. When a unit steps diagonally out of a cell, the two orthogonally adjacent cells on that side must both be passable, otherwise the unit's model would clip through the corner. The heuristic becomes the octile distance accordingly: take min(dx, dy) diagonal steps first, then straight steps for the remainder.
// 8-direction movement: a straight step costs 10, a diagonal step 14 (≈ 10√2; integers avoid floating-point error)
constexpr int kStraight = 10;
constexpr int kDiagonal = 14;
// Octile distance: min(dx, dy) diagonal steps first, then straight steps for the rest
inline int octile(Cell a, Cell b) {
int dx = std::abs(a.x - b.x), dy = std::abs(a.y - b.y);
return kStraight * (dx + dy) + (kDiagonal - 2 * kStraight) * std::min(dx, dy);
}
// Whether stepping from c towards (dx, dy) is legal. Diagonal steps may not cut corners: the two
// orthogonally adjacent cells on that side must both be passable
inline bool canMove(const Grid& grid, Cell c, int dx, int dy) {
if (!grid.passable({c.x + dx, c.y + dy})) return false;
if (dx != 0 && dy != 0) return grid.passable({c.x + dx, c.y}) && grid.passable({c.x, c.y + dy});
return true;
}
constexpr Cell kDirs8[8] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {-1, -1}, {1, -1}};Switch between a* / jps at the top, edit the map with wall / erase, and drag S and G to move the start and goal. Dark cells are the nodes that were expanded, light cells are the cells that were scanned, the thin lines connect each node to its parent; the circles along the path are jump points.
On the default map:
Algorithm | Nodes expanded | Cells scanned | Path cost |
|---|---|---|---|
A* | 125 | — | 28.4 |
JPS | 17 | 355 | 28.4 |
A few small experiments worth trying:
Switch to a* and look at the area near the start: A* expands the whole room to the left, every cell trailing a short “parent line”. Switch back to jps and the same region is left with only a few long straight lines.
Step through JPS. Every step sets out from the current jump point, sweeps long straight lines in several directions, and comes to rest on just a handful of cells.
Use wall to scatter a few isolated wall cells across the open ground. The more fragmented the walls, the more jump points there are, and the smaller JPS's advantage becomes.
Jumping
At the core of JPS is a single function, jump: set out from a cell and keep going in one direction until one of three things happens:
It hits a wall or leaves the map: there is no jump point in this direction, so return failure.
It reaches the goal: the goal is itself a jump point.
It finds a forced neighbour: this cell has to be stopped at, and it is the jump point.
Forced neighbours
When exactly does it have to stop? Take the right-hand half of figure 1.6. Walking to the right along the middle row, from p to x. Normally the cell n above x can be reached from p diagonally, without going through x, so there is no need to consider it when expanding x.
But if the cell above p is a wall, going from p to n diagonally would cut a corner, which is not allowed. The shortest route to n can only pass through x, so x becomes a “junction”: it has to be stopped at, and the upward direction has to be considered as well. n is called a forced neighbour of x.
The test is very simple: the cell to the side is passable, while the cell behind it is a wall.
Jumping diagonally
When a jump goes diagonally, every step first performs a jump along each of its two straight components (jumping down-right, say, means one jump to the right and one downwards). If either of them finds a jump point, the current cell is itself a jump point, because turning here might lead to a better route.
// Keep walking from c along (dx, dy) until a cell is reached that "has to be stopped at and considered"
// (a jump point). On success write it to *out and return true; return false on hitting a wall or
// leaving the map.
bool jump(Cell c, int dx, int dy, Cell* out) {
for (;;) {
if (!grid_->passable(c)) return false;
scanned_[grid_->index(c)] = 1; // only used for statistics and visualisation
++scanCount_;
if (c == goal_) {
*out = c;
return true;
}
if (dx != 0 && dy != 0) {
// Diagonal: at every step, jump once along each of the two straight components first; if
// either of them finds a jump point, c is itself a jump point
Cell unused;
if (jump({c.x + dx, c.y}, dx, 0, &unused) || jump({c.x, c.y + dy}, 0, dy, &unused)) {
*out = c;
return true;
}
if (!canMove(*grid_, c, dx, dy)) return false;
} else if (dx != 0) {
// Horizontal: a wall directly above or below ends just behind us, so turning here may be
// shorter — a forced neighbour
if ((grid_->passable({c.x, c.y - 1}) && !grid_->passable({c.x - dx, c.y - 1})) ||
(grid_->passable({c.x, c.y + 1}) && !grid_->passable({c.x - dx, c.y + 1}))) {
*out = c;
return true;
}
} else {
if ((grid_->passable({c.x - 1, c.y}) && !grid_->passable({c.x - 1, c.y - dy})) ||
(grid_->passable({c.x + 1, c.y}) && !grid_->passable({c.x + 1, c.y - dy}))) {
*out = c;
return true;
}
}
c = {c.x + dx, c.y + dy};
}
}On corner cutting
Harabor and Grastien's original paper allows corner cutting, and its forced-neighbour test is different from the one here: under that rule, diagonal moves can produce forced neighbours as well. This article uses the “no corner cutting” rule that is more common in games, with a test taken from the open-source library PathFinding.js. The two rules must not be mixed, or optimal paths will be missed.
Pruning: look only in the directions you came from
Expanding a jump point does not mean trying all 8 directions either. Having arrived horizontally from the left, there is no point in looking back; having arrived diagonally from the upper left, all that is worth keeping is the same diagonal and its two straight components.
// Pruning: keep only the directions for which going through c is the better option. The start has no
// direction of arrival, so all 8 directions are kept
int prunedDirections(Cell c, Cell* out) const {
int n = 0;
auto add = [&](int dx, int dy) {
if (canMove(*grid_, c, dx, dy)) out[n++] = {dx, dy};
};
int ci = grid_->index(c);
if (cameFrom_[ci] == ci) {
for (Cell d : kDirs8) add(d.x, d.y);
return n;
}
Cell p = grid_->cellAt(cameFrom_[ci]);
int dx = (c.x > p.x) - (c.x < p.x); // direction of arrival, taken as a sign
int dy = (c.y > p.y) - (c.y < p.y);
if (dx != 0 && dy != 0) {
// Arrived diagonally: keep going diagonally, plus its two straight components
add(dx, 0);
add(0, dy);
add(dx, dy);
} else if (dx != 0) {
// Arrived horizontally: keep going forward, plus both sides (the "forced neighbours" that
// appear once the corner disappears)
add(dx, 0);
add(0, 1);
add(0, -1);
add(dx, 1);
add(dx, -1);
} else {
add(0, dy);
add(1, 0);
add(-1, 0);
add(1, dy);
add(-1, dy);
}
return n;
}Swap the neighbours, change nothing else
With jump and pruning in place, the main loop of JPS is exactly the same as A*'s; the successors are simply no longer the 8 adjacent cells but the jump points found along each direction:
// JPS successors: first prune down to the directions worth exploring given where we came from, then
// jump along each of them to the next jump point
template <class F>
void forEachJumpPoint(Cell c, F&& visit) {
Cell dirs[8];
int n = prunedDirections(c, dirs);
for (int i = 0; i < n; ++i) {
Cell jp;
if (jump({c.x + dirs[i].x, c.y + dirs[i].y}, dirs[i].x, dirs[i].y, &jp)) visit(jp);
}
}// Expand one node. Returns false once the search is over
bool step() {
while (!found_ && !open_.empty()) {
std::pop_heap(open_.begin(), open_.end(), Worse{});
Entry top = open_.back();
open_.pop_back();
int ci = grid_->index(top.cell);
if (closed_[ci]) continue; // stale entry
closed_[ci] = 1;
current_ = top.cell;
hasCurrent_ = true;
++expanded_;
if (top.cell == goal_) {
found_ = true;
return false;
}
auto relax = [&](Cell next) {
int ni = grid_->index(next);
if (closed_[ni]) return;
int g = top.g + octile(top.cell, next); // a jump point may be far away, so cost it by octile distance
if (g_[ni] < 0 || g < g_[ni]) {
g_[ni] = g;
cameFrom_[ni] = ci;
push(next, g);
}
};
if (mode_ == Grid8Mode::AStar) {
for (Cell d : kDirs8) {
if (canMove(*grid_, top.cell, d.x, d.y)) relax({top.cell.x + d.x, top.cell.y + d.y});
}
} else {
forEachJumpPoint(top.cell, relax);
}
return true;
}
return false;
}Note how the cost is computed: a jump point may be a long way from the current node, but the stretch between the two is always purely straight or purely diagonal, so the cost is simply the octile distance between them.
What the search returns is a sequence of jump points. Before handing it to a unit it can be expanded into a cell-by-cell path; if the unit already moves in straight lines, the jump points can be used as they are.
// Expand the sequence of jump points into a cell-by-cell path: the stretch between two consecutive
// jump points is always purely straight or purely diagonal
inline std::vector<Cell> expandJumpPath(const std::vector<Cell>& jumpPoints) {
std::vector<Cell> path;
if (jumpPoints.empty()) return path;
path.push_back(jumpPoints.front());
for (size_t i = 1; i < jumpPoints.size(); ++i) {
Cell a = jumpPoints[i - 1], b = jumpPoints[i];
int dx = (b.x > a.x) - (b.x < a.x), dy = (b.y > a.y) - (b.y < a.y);
while (!(a == b)) {
a = {a.x + dx, a.y + dy};
path.push_back(a);
}
}
return path;
}Measured: JPS does not always win
A* and JPS compared on two kinds of 256×256 map, using the same set of start and goal pairs:
Map | A expanded* | JPS expanded | JPS scanned | JPS speed vs A* |
|---|---|---|---|---|
Room: large open areas + rectangular obstacles | 1534 | 63 | 13531 | about 2–3× |
Noise: every cell is a wall with 25% probability | 3917 | 2049 | 13284 | about 1–1.5× |
Two things are worth noting:
On the room map JPS expands 24 times fewer nodes, yet is only 2–3 times faster. The reason lies in the “scanned” column: JPS does away with heap operations, but a jump has to test for walls cell by cell, and the number of cells scanned is far larger even than the number of cells A* expands. Those tests are much cheaper than heap operations, but they are not free.
On a map littered with fragmented obstacles, forced neighbours are everywhere, jumps stop after only a few cells, and JPS degenerates almost back into A*.
Test environment
Apple M3, Apple clang 21, -O2, fastest of 5 runs; results varied considerably from run to run, so the table gives a range. The code is in cpp/pathfinding/jps/jps_bench.cpp. To keep the comparison with A* fair, neither implementation here uses the buffer reuse from the previous article.
Common pitfalls
Problem | Cause | Fix |
|---|---|---|
The path is occasionally not the shortest | The forced-neighbour rule does not match the corner-cutting rule | The two must go together: if corner cutting is allowed, use the original paper's rule |
Wrong results on maps that have terrain costs | JPS relies on the symmetry of “every step along a line costs the same” | Use it only on uniform-cost grids; use A* when there is terrain |
Slower than A* | Obstacles are fragmented and jump points are dense | Measure on the real map first; consider the precomputed JPS+ |
Stack overflow when jumping diagonally | A recursive | Loop for straight jumps and recurse only one level of straight jumps from the diagonal case (as this article does) |
Units clip through walls when walking between jump points | The stretch between jump points is straight or diagonal, but the unit moves in a straight line at an arbitrary angle | Move only along the 8 directions between jump points, or expand into a cell-by-cell path first |
Applications in games
Grid-based games: roguelikes, tactics games, tower defence, top-down shooters — wherever the map is a uniform-cost grid, JPS can replace A* outright and produce exactly the same path.
JPS+: precompute offline, for every cell, the distance along each of the 8 directions to the next jump point (or wall), then simply look it up at run time; typically several times faster again than JPS. The price is that after a change to the map the affected parts have to be recomputed, which suits static maps.
Destructible terrain: when the map changes frequently, JPS needs no preprocessing at all, and is easier to maintain than JPS+ or the navigation mesh in the next article.
Further reading
Daniel Harabor and Alban Grastien, Online Graph Pruning for Pathfinding on Grid Maps (AAAI 2011): the original JPS paper
Daniel Harabor, Jump Point Search: the author's own blog post, illustrating jump points and forced neighbours
Steve Rabin and Fernando Silva, JPS+: An Extreme A Speed Optimization for Static Uniform Cost Grids*, in Game AI Pro 2
PathFinding.js: JPS implementations under several corner-cutting rules, directly comparable in the browser
Newsletter
Subscribe
Get an email when a new article is published. Unsubscribe anytime.
Copyright
Copyright of this article belongs to its author or rights holder. When reposting or quoting, please follow the applicable license terms and keep the link to this article.
XuYi, “Game Algorithms (Pathfinding Part 3) - Fixing A* on Open Grids with Jump Point Search”, https://xuyi.dev/en/2026-11-27-n03w6l
Comments
Comments
Loading comments…