15 ms·
Introduction to the A* Algorithm (2014)
- JohnKemeny 1y agoIt's that time of year again. I like A* as much as the next one, but it seems a bit excessive a times. Title should have a (2014) in it: Introduction to the A* Algorithm (2014). 1 points, 8 months ago, 1 comments: Introduction to the a* Algorithm (https://news.ycombinator.com/item?id=41897736 https://news.ycombinator.com/item?id=41897736) 202 points, 3 years ago, 30 comments: Introduction to the A* Algorithm (2014) (https://news.ycombinator.com/item?id=30287733 https://news.ycombinator.com/item?id=30287733) 4 points, 5 years ago, 1 comments: Introduction to the a* Algorithm (https://news.ycombinator.com/item?id=24146045 https://news.ycombinator.com/item?id=24146045) 201 points, 7 years ago, 14 comments: Introduction to A* (2014) (https://news.ycombinator.com/item?id=18642462 https://news.ycombinator.com/item?id=18642462) 5 points, 7 years ago, 0 comments: Introduction to A* (https://news.ycombinator.com/item?id=16190604 https://news.ycombinator.com/item?id=16190604)
- bandoti 1y agoPlease consider some folks might be new to A*, and perhaps even HN, so maybe this is the first time they’ve seen it! :) Also, I have ten books on perspective drawing, and my understanding isn’t complete without all ten of them Or, if I’m teaching a subject on A*, perhaps ONE of those articles conveys the materials best for my students. Thank you for providing links to the others though! I’m sure it will be helpful for someone.
- add-sub-mul-div 1y agoYeah people live by this leaky abstraction that an article having been posted before means everyone was online that day and saw it and now it has expired. And for some reason they chase these hall monitor points for pointing it out. Let's see what a discussion would be like from today's point of view.
- tialaramex 1y agoThe cheapest available model once you have Theory of Mind (the idea that the other things in the environment might be thinking like you do) is that they're you again. The Smarties test (What's in this Smarties tube - look it's not Smarties, ok now what does somebody else think is in the tube?) shows that humans need a further step to discover that model isn't enough. But it's still cheaper and it's pretty good. It will correctly predict that this person you've never met before probably wants cake not death, just like you. It won't reliably predict whether they prefer lemon cake or coffee cake. But it's a good first guess.
- dspillett 1y agoAlso: some people seem to get an amount of pleasure from pointing out repeats, as if remembering that something was posted before is knowledge enough to make them a better person than the poster, us all, or just the person they thought they were themselves. This is fine when something is posted far too often, or is reposted by a point-farming bot (presumably the users running such bots hope to use the reputation of the account somehow in future), but is often done overzealously.
- dspillett 1y agoI agree, though to be a pedant: > perhaps ONE of those articles It is the same article each time, though the comments coming off the different postings of it might have unique nuggets of useful information to dig for. > Thank you for providing links to the others though! I’m sure it will be helpful for someone. It isn't as prominent as on other sites, so it isn't difficult to miss sat right at the bottom of the main page, but HN does have a working search function. I find searching for older posts this way can be quite useful for the above reason, when something comes up that has existed for a few years.
- bandoti 1y agoPersonally, I don’t bother searching because I only consume the headlines, on other news sites too, come to think of it. There’s lots of interesting things people post but frankly I’d rather pay for a good book on any subject. hides from the dreaded downvoters I used to spend more time browsing when reading an actual newspaper or magazine. The discourse on opinion pieces and such is more thought out too—many people, myself included, post too quickly before thinking because we’re always on the go. Something about the online experience consuming news is less satisfying. Perhaps a hacker out there can set up a print version of HN archives, and print it on a Gutenberg Press. :)
- schneems 1y agoI wish there was a “evergreen” feature for social sites where it tracked resubmissions and would auto suggest them to people who haven’t seen them and periodically surface them to those who have and ask “is this still relevant” That way really good content keeps being recommended to those who need it and you get fewer complaints from old timers who don’t have to see it N times.
- dietr1ch 1y agoMy dream is a knowledge-aware Wikipedia that can be more relevant by understanding what the reader knows, might know and might find interesting w/o being overwhelming. I guess you can make this social too and have discussion groups, but it's already too large of a project in my mind.
- giancarlostoro 1y ago> Also, I have ten books on perspective drawing, and my understanding isn’t complete without all ten of them Which books might those be? ;)
- pmichaud 1y agoI think it's just the first, most obvious thing to teach people just starting in pathfinding. It works in real life, it's easy to visualize and compute. Therefore all the tutorials are about it :)
- msk-lywenn 1y agoPlease think of all the lucky few. (xkcd 1053)
- devrandoom 1y agoThere are a lot of people on HN that aren't you.
- dunham 1y agoI was surprised to see this article because it's not that time of year. Typically A* shows up around December, because people discover it via Advent of Code. (And that's the only place I've used it.)
- raincole 1y agoHow could the OP submit this link anyway? When I submit a link that has been posted on HN before, it just redirects me to the old post.
- random3 1y agoMaybe there's a secret guide on how to build up karma :))
- teo_zero 1y agoI think the real reason this article keeps coming back is how good it is at teaching through examples and visualization, rather than the A* algorithm itself.
- repiret 1y agoI think A* deserves the popularity. It’s a simple variation on depth-first and breadth-first graph traversal that everyone learns in CS101, massively useful in some situations, yet for some reason isn’t a standard part of CS education. It’s a marvelous thing the first time you learn about it. It’s even more marvelous if it helps you recognize that the difference between BFS and DFS is how you pick the next node to explore out of your bag of unexplored nodes. That symmetry is easily lost if DFS is only taught as a recursive algorithm. Let it keep coming up every couple years to marvel a new generation of programmers.
- hoseja 1y agoI don't like A* It's a performance hack, not how entities trying to get somewhere behave.
- herman_toothrot 1y agoWhat is your preference?
- FrustratedMonky 1y agojust take all right turns?
- hoseja 1y agoSee the target/know which direction it is? Go that direction unless you see an obstacle, in that case go around the obstacle, eventually even backtracking if it turns out the obstacle was worse than you could see. Don't see/know the target? Brownian motion until you do or get tired. Have pathfinded to the target previously? The shortest path you saw while walking there. Al these require deep and complicated simulation of the entity though instead of solving a graph problem from omniscient perspective. Many topdown games really break my immersion when I see things just blatantly a-staring places. Basically, things usually have limited information and it's weird to see them behave as if they don't. Plus on grids there's the cringe "diagonal and then straight" movement pattern.
- dweekly 1y agoI'm not sure your complaint is actually that A* is bad, it's that the heuristic function is unfair (to the player, by giving the mob data they shouldn't have). A more sophisticated game could use a more interesting function like an estimate as to what direction the player's movement sound would be heard from.
- HelloNurse 1y agoOptimal pathfinding isn't always the right objective: for a good looking game agent reasonable pathfinding can often be enough, or even better. For example, in a RTS making units follow a leader in formation can be more natural and less expensive than performing independent optimal pathfinding for all of them, while in environments with many obstacles staying away from walls (on a simplified graph of good positions) is usually more elegant than hugging corners (on a much more complex graph).
- aiuniverse 1y ago[flagged]
- ecshafer 1y agoRed Blob Games is a great blog if you are interested in game development. The explanations are solid, they have at least pseudo code or an implementation for most of their posts, and they have great animations on a lot of their bigger posts to help build intuition.
- Barrin92 1y agoI remember one of the Advent of Code challenges had a hex grid puzzle on it, and Red Blob Games hex grid guide was so good the site got hugged to death because of it for a while. Used that later when I built a civ clone too, it's a fantastic resource. https://www.redblobgames.com/grids/hexagons/ https://www.redblobgames.com/grids/hexagons/
- vismit2000 1y agoProblem: https://adventofcode.com/2020/day/24 https://adventofcode.com/2020/day/24 My solution: https://github.com/vismit2000/compCode-II/blob/cb3041d2f5110d7754ee214d1593600017362b10/Advent-of-Code/2020/day24.py https://github.com/vismit2000/compCode-II/blob/cb3041d2f5110...
- lelandfe 1y agoI still remember a decade on the little pop of joy of realizing that not only do all the graphics on that blog post change when moving from flat to pointy, the code animates too. The interactive graphics evoke all the fun of being a child in a science museum.
- S0y 1y agoI came here to say the same thing. Red Blob Games is such a gold mine of resources for anyone looking to get into gamedev.
- cmrdporcupine 1y agoRed Blob Games is also "amitp", one of the earliest Google employees. #7 or something like that.
- upghost 1y agoInteresting that this used to be called "AI". I'm still trying to figure out what to call the umbrella field of Artificial Intelligence now that "AI" has come to mean the genAI subset of DL which is a subset of ML which is a subset of what used to be called "AI".
- diggan 1y agoThe definition of "AI" has for a long time now been basically "We know it works somehow, but only few people really understand it", which is a moving target. At one point in the future, the LLMs we use today won't even be called AI anymore.
- Al-Khwarizmi 1y agohttps://en.m.wikipedia.org/wiki/AI_effect https://en.m.wikipedia.org/wiki/AI_effect PS: the wiki article needs updating with more confirmation from the LLM era, if anyone's up for it... :)
- ecshafer 1y agoI took a course in grad school on "Game AI" that put different path finding approaches and methods of making decisions into a useful bucket away from ML and AI.
- dspillett 1y ago> Interesting that this used to be called "AI". What has been called AI in gaming in the past is rich and varied, and goes all the way down to a computer control opponent “seeing” a player and opening fire, moving towards, or moving away. Any code controlling NPC was referred to as “the AI of the game” even if all the code was doing was applying a few simple rote rules rather than following an exactly pre-specified sequence. “AI” in gaming means (or has previously meant) a lot less than “AI” has meant in other fields, but with the increasing use of “AI” in all contexts this will soon no longer be the case.
- kccqzy 1y agoThere is also certainly more sophisticated AI in gaming. Remember the AI used by Deep Blue in chess? Or the AI used by DeepMind in Go against Lee Sedol? Classic games like chess or Go receive more attention from the AI community than contemporary video games.
- apnorton 1y agoThe article doesn't explicitly state it in this manner in one concise place, but the way I would always think about A* from a "practical/easy-to-remember" perspective back when I was doing competitive programming is that they're all the same algorithm, but with different priorities on the priority queue: Breadth-first Search: Priority is order of discovery of edges (that is, no priority queue/just a regular queue) Dijkstra: Priority is distance so far + next edge distance A*: Priority is distance so far + next edge distance + estimate of distance to target node. This also helps me remember whether the estimate must over- or under-estimate: Since Dijkstra is making the estimate "0", clearly the "admissible heuristic" criteria must be an under-estimation.
- breckognize 1y agoAnd depth first search is just a stack!
- dietr1ch 1y agoYes, but it doesn't come right away. When preferring deeper nodes for a moment you have a loop-safe Depth-first traversal, and then when simplifying things in case the Graph is a Tree you get your regular stack-based Depth-first traversal, in which if you settle for the first goal you get back a tail-call optimised DFS.
- tonyhart7 1y agowell they all just loop???
- bcrosby95 1y agoSimplifications help people memorize things but if you get too reductive it becomes useless.
- salamanderman 1y agoBreadth-first is a queue. Depth-first is a stack. A* is a priority queue.
- k2xl 1y agoAs a game developer for a grid based puzzle game (https://thinky.gg https://thinky.gg - one of the games Pathology is a game where you have to go from Point A to Point B in shortest amount of steps). I have found A* fascinating not because of the optimization but also from the various heuristics that can be built on top of it make it more generalized for other types of pathfinding. Some devs have built solvers that use techniques like bidirectional search, precomputed pattern databases, and dead locking detection.
- ncr100 1y agoJust a note about bidirectional, or "double-ended" as I learned it - this can be very useful (i read 30% speed-up) for City / National Road searches. One also has multiple layers of roadways of varying arterial significance, allowing higher speed (lower weight) travel, with real-world roads. It was used at a mapping job to great boon by our backend.
- 0manrho 1y agoI have a perhaps overly simplistic question, but how is this meant to be pronounced? A-star? Ah-sterisk?
- Ao7bei3s 1y agoAy-star.
- cryptomic22 1y agoPath finding visualization, highlighting A*: https://youtube.com/shorts/L8t0tt1Vrsw https://youtube.com/shorts/L8t0tt1Vrsw
- deadbabe 1y agoA* is simple enough, but how do you handle pathfinding when the environment isn’t known to the entity?
- lightbendover 1y ago[dead]
- ViscountPenguin 1y agoIirc, the best approaches for this nowadays are machine learning based. Otherwise, you probably want to do an exploration step first, and bake in the environment.
- gradstudent 1y agoML methods are poor pathfinders. I'm unaware of any pathfinding problem where SOTA is not dominated by state-space search.
- ViscountPenguin 1y agoI can't find any benchmarks, but here's an example of the sort of approach I was talking about: https://www.researchgate.net/publication/355761412_Path_planning_in_an_unknown_environment_based_on_deep_reinforcement_learning_with_prior_knowledge https://www.researchgate.net/publication/355761412_Path_plan... GOFAI techniques are: A) Usually unable to incorporate posteri knowledge of the environments they're working on. And B) Often entirely infeasible to adapt to take exploration costs into account. I've heard of some GOFAI techniques for optimal unbiased pathfinding in unknown environments using optimal transport theory and the like. But unbiased methods are obviously going to lose out in real environments.
- SnowflakeOnIce 1y agohttps://en.m.wikipedia.org/wiki/Simultaneous_localization_and_mapping https://en.m.wikipedia.org/wiki/Simultaneous_localization_an...
- mysteria 1y agoFunny enough I got a hit of nostalgia seeing this as I learned A* for a school project many years ago using this exact same tutorial.
- leftnode 1y agoI have a deep love of A* because it was the first complex algorithm I fully understood. In my first data structures and algorithms in college (early 2000's), we had to pick an algorithm to study, code, and write a paper on and I picked A*. I spent hours painstakingly drawing similar grids that the author of this article made and manually doing the calculations [0]. I still have these notes somewhere, even though they're over 20 years old at this point, because I was so proud of the work I put into it. At any rate, thanks for this article and the trip down memory lane. [0] https://imgur.com/a/zRYaodL https://imgur.com/a/zRYaodL (apologies for the Imgur link)
- deleted 1y ago[deleted]
- Kye 1y agoNot to be confused with Sagittarius A*. https://en.wikipedia.org/wiki/Sagittarius_A https://en.wikipedia.org/wiki/Sagittarius_A*
- lblume 1y agoThe star appears to have been cut off from the link, leaving an article about the corresponding radio source, Sagittarius A. This (official Wikipedia) short link leads to the desired article: https://w.wiki/5A7e https://w.wiki/5A7e
- Kye 1y agoHN escaped the * when I posted. I tried to escape the escape, but it kept adding escapes to my escapes. After a while I conceded defeat and decided folks might enjoy taking the scenic route through disambiguation. I never got in the habit of using share links, so it's interesting to learn Wikipedia has a URL shortener.
- kazinator 1y agoSomeone send this to the idiots at Garmin, because their navigators will tell you to drive in a straight line across mountains or water water to an unreachable destination. It's like AI that never says "I don't know".
- kriro 1y agoBest introduction to A* in my opinion is travelling in Romania :) AI a Modern Approach.
- JohnKemeny 1y agoI always use A* when going to Bucharest.
- throwawayoldie 1y ago"This problem assumes that the reader is not familiar with Romanian geography. We apologize to those who are unable to take advantage of this pedagogical device." (Or words to that effect, it's been 20+ years since I read it.)
- lukeyoo 1y agoRelavants of mine - https://lukeyoo.fyi/recap/2025/5/a-star https://lukeyoo.fyi/recap/2025/5/a-star - https://github.com/micttyoid/quantized-pathfinding https://github.com/micttyoid/quantized-pathfinding
- 90s_dev 1y agoI have this bookmarked under "path finding" along with https://juhrjuhr.itch.io/deep-space-exploitation/devlog/945428/9-pathfinding https://juhrjuhr.itch.io/deep-space-exploitation/devlog/9454... and https://www.redblobgames.com/grids/hexagons/ https://www.redblobgames.com/grids/hexagons/
- curtisszmania 1y ago[dead]