> I learned about this technique in 2007, then tried writing it up in 2015. I realized that I didn’t understand it enough to be able to explain it. I studied it off and on in 2016, 2018, 2019, 2022, 2024, and 2026. I abandoned and restarted this page many times. And by 2026 I think I understand it well enough to write this page.<p>Outstanding.
Teach Yourself A* in Ten Years
I have an appreciation for people who keep going. Sometimes it doesn't really matter how long it takes you to learn something. I've found it's more valuable to see what you'd do with that knowledge.
There has been a lot of progress in this field in the research community. Two good papers:<p>* <a href="https://ojs.aaai.org/index.php/AAAI/article/view/11027" rel="nofollow">https://ojs.aaai.org/index.php/AAAI/article/view/11027</a>
* <a href="https://arxiv.org/abs/2212.03978" rel="nofollow">https://arxiv.org/abs/2212.03978</a>
Red Blob Games has quite a few S-tier posts, highly recommend exploring further if this is at all interesting to you
Incredible write-up, as usual. I still fondly remember discovering Red Blob Games' Hexagonal Grids [1] guide while building an implementation of the Tzaar board game [2]. The illustrations are enormously helpful!<p>[1] <a href="https://www.redblobgames.com/grids/hexagons" rel="nofollow">https://www.redblobgames.com/grids/hexagons</a><p>[2] <a href="https://boardgamegeek.com/boardgame/31999/tzaar" rel="nofollow">https://boardgamegeek.com/boardgame/31999/tzaar</a>
Finally an interesting article about AI!
The author, Amit Patel, wrote the BBS door game Solar Realms Elite! His brother went on to write Baron Realms Elite.
I don't understand how the multiple landmarks works. If you just max all of the landmark distances wouldn't some landmark near the starting point eventually dominate as you move away from it? Once you get halfway through the path the useful landmarks would be returning lower and lower values while ones behind you return larger and larger values. Or just in general one far-away landmark would complete nullify any input from useful ones.<p>It seems to me that you would need a step to select useful landmarks but the code doesn't seem to do this and I don't see it discussed.
Ah, I figured it out. It is because he isn't using the distance to the landmark as the heuristic but the difference between the distance to the current location and the distance to the target. This means landmarks behind you will be negative (or useful in an undirected graph). This is also important for making the heuristic admissible as otherwise your heuristic would say zero when you are standing on top of the landmark.
Damn, isn't A* fun and intuitive?<p>I'd be interesting to dive into bounds and good properties for sets of landmarks.<p>I imagine that if,
- Every node is at least X cost/distance away from a landmark
- Landmarks are no closer than Y cost/distance from each other<p>You can start promising a lot about the size of your open set on any execution.<p>A* on h* (perfect heuristic) takes O(l) where l is the length of the solution (could expand exactly l nodes, but solving/guessing ties incorrectly might bump this to a multiple around the avg edges per vertex).
I imagine that having good bounds mean you'll take no longer than a certain amount of expansions/depth before you lock-into the railway that h* provides (and you need some extra work to get off it too).
Usually I would not point out a typo, but this one makes it difficult to grasp the magnitude of potential improvements:<p>> the number of nodes A* has to explore decreases from 12693 to 12693
It's a little unclear, but it's a live updating number, if you follow the directions, you'll see the second number decrease.
Good catch. I was thinking people would read that after they have moved the green L but I should handle both before and after moving L.
I see redblobgames, I click
i've always been impressed by NBA*: <a href="https://github.com/anvaka/ngraph.path" rel="nofollow">https://github.com/anvaka/ngraph.path</a><p>demo: <a href="https://anvaka.github.io/ngraph.path.demo/" rel="nofollow">https://anvaka.github.io/ngraph.path.demo/</a>
This Red Blob Games blog post would be accessible to a wider group of readers if it spent just a few sentences up front on motivation and terminology.<p>If you don't already know exactly what the heuristic function is and that L is something called a landmark marker, and anyway what is a landmark marker anyway, you need to read quite a long way through the blog post to make sense of it.<p>And when you do finally get to that point, you realise it is all very simple, so why not just say that at the start?
You’re asking for a different post. More like a science paper where they say the result up front.<p>This blog post is like a story. It doesn’t start with the ending.<p>I read your comment first, expecting to go to the article and see a bunch of undefined math terms, but that isn’t what happened at all.<p>Of course you need to know what a heuristic function is, so maybe you’re right in that sense. You absolutely do not need to know anything about landmarks to enjoy the post. I didn’t, and it was no trouble at all to follow.<p>Perhaps you found the “discovery” method of presentation not to your liking. Discovery means there’s a demo where you move the L around before its purpose is defined. Building an intuitive understanding before producing a rigorous definition is (now) considered a good teaching method.
Before reading about optimizing the A* algorithm, read about the algorithm itself first.
In the event this helps a random developer with some fun experimentation: I had once accidentally independently reinvented drunken pathfinding by adding random additional weights to the node costs, which has the side effect of making an object seeking a path end wander "drunkenly."
It uses df as an example, but it (unlike the others) has the problem that the set of valid paths between any two points can be constantly changing.
The landmark data can be calculated in a background thread. For DF I imagine you'd have a background thread running all the time, updating one landmark every so often. But what happens if you look for a path before the landmark data is updated? I haven't tested this yet but I believe this is how it'd work:<p>1. If the cost of a tile decreases, the precalculated heuristic will be too high, so A* might find a non-shortest but ok path. In game, you can think of the dorf as following the path they already know about, because they don't yet know that there's a shorter way.<p>2. If the cost of a tile increases, the precalculated heuristic will be too low, so A* will find the optimal path but it will take a little bit longer (still not as long as if we weren't using this heuristic). In game, you can think of the dorf as following the path they already know about, but running into a wall, so then they find a path around it.
One of the famous problems with df is that it's very much single threaded. At least the last time I checked, which is some years ago by now.<p>Besides that blocker, your idea sounds like a nice win.
One of the big questions for an algorithm is - when do you recalculate the path? A real "human" doesn't recalculate until they receive information that the chosen bath is blocked/changed (they see the road closed sign, etc).<p>But many games recalculate distance to target (one ping only) over and over again each step, so moving a single block half a map away causes an entire army to repath immediately.
Man I opened this website after so so long, so nostalgic.
From the title I was expecting something about jump point search but this is even more interesting. Bravo!
I love this blog. 10/10
[flagged]
One of my fav LLM tests is asking it to implement A* algorithm, in X language, in a single file, output 80x40 char map with random obstacles and show the path. Ask it to build UI or change path heuristiscs, etc.<p>It's such a quick prompt but can quickly signal how useful the model is in that language or framework, how much you have to constraint output with specs and tests.