Live data from Hacker News

Age of Empires Definitive Edition's pathing and movement

richg42.blogspot.com

51–60 of 94 posts

Re: Age of Empires Definitive Edition's pathing and movement

#51
post #47

Talk about a thankless job! That's an extensive list of bugs and working on someone else's (very old) playground is incredibly difficult.

I imagine its more of a passion project. If I had free time, I would love to delve into the internals of the game that I played so many times as a kid. Side note: Age of Empires 2 was the first computer game that got me truly hooked on to computers. I was never interested in the shoot em ups, but a strategy game, with such gorgeous graphics (for the time) and compelling semi-historical storyline... it was enchanting!

    > gorgeous graphics (for the time)
Google image search "age of empires 2." Those graphics are still amazing and can't really get much better, which is why all they need is HD remastering.

Gorgeous and captivating 2D work, just like booting up the game Pharaoh after all these years. Just needed a user-made patch to allow higher resolution support.

Re: Age of Empires Definitive Edition's pathing and movement

#53

The fact that this post seems to be engendered by a comment on a forum ("The pathfinding in the game is terrible.") reminds me of 'Designing Video Games is Hard Work, But the Millions of Angry Players Make It All Worthwhile' http://thehardtimes.net/harddrive/designing-video-games-hard...

I use to be a high level Age of Kings player (Even got an invite to the first World Cyber Olympics in NYC).

The pathing was ALWAYS horrible but the PATCHING by the developer was even worse. There were times when the community just banned certain things because they were just broken (Teuten's Town halls were only costing wood but did more damage than high costing resource units and buildings).

As a high level player a broken pathing allowed me to micro my troops and get an advantage over other players. Most players play with the speed of a 4X and there were few of us who played by trying to make 150+ commands a minute.

So this horrible pathing was seen as an advantage by faster players.

Scale APM Description ~50 Casual player ~75 Experienced player ~150 Proficient player >200 Proficient player with superfluous actions

Re: Age of Empires Definitive Edition's pathing and movement

#54
Cool. I've coded a RTS myself, and I might be able to add some information.

DE's pather gives up if after many thousands of iterations it can't make forward progress towards the goal, to avoid spending CPU cycles on hopeless pathing unnecessarily. (It's more complex than this, but that's the gist of it.)

The right way to do that is to make a unit pop the action on top of its stack if it cant perform it. So if a unit cant move somewhere, it just removes the action that says it should move there. Now, the trick is: a user click pushes an action which isnt the actual move but which generate actions with actual move. It allows the unit to not give up when it cant perform an action on a user order but make it retry later, say in half a second.

I implemented the A early exploration optimization*

I did something similar. The way I did that was that a unit of the group would perform an A* but on a grid that has say 64x less cells. The path would be marked and the following, per unit, precise A* would not push into the openlist a cell that's not in the marked grid. Subsequently, if another unit of the group starts a precise A* but is not itself on a marked cell, it performs again a big cell A* marking (union-ed with the previous one). Note that when you select units and perform actions with them, 1) they will have the same actions by definition and 2) they will group if you move them, which 3) makes that algorithm quickly efficient in practice.

The only requirement is a map of the walls at the size of the "big grid". Could be problematic I guess in some cases. Not that it doesn't take into account dynamic walls which is ok (units and such).

For short range paths, straight line paths are preferred vs. the tile path returned by findPath() if the straight line path is safe to traverse

I understand the constraint of this new Age of Empire. Still it's a good introduction for the next topic. I dont know what the guys from blizzard used in SC2 but here is what I did to improve the grid system.

Essentially it all goes down to 2 constraints: 1) you dont want a non-idle unit to be ever blocked by friendly idle units and 2) you want the attacking units to block any unit - because you dont want an attacking unit to move because eh, it's making damage right now. The difficulty is that (1) seems incompatible with (2) at first, when using A* (on a grid or anything else). (1) makes multiple units to be on one node, (2) and more generally combat, make you dramatically want a node to have only one unit for obvious reasons: you want a unit to be able to fire immediately if at order range and to block the other units.

The way I solved that is by using marching squares. All units moves freely on the map, at the "pixel scale", the floating point scale - though it's all integers because the network algorithm, the lockstep, needs integer. Anyway, so you have some fix point math which divide a cell into say, 1024 integer-units.

When performing a pathfinding, a marching square mesh is first built (environment can be precomputed, attacking units are dynamic walls I recall). But the trick and the cool thing is that, when building that marching square mesh, you can actually and easily make a graph of it, which includes a lot of the original cells nodes. Now that you have a graph, you can do an A* and (1) and (2) are all solved. It's quite super simple to implement and as fast as the grid basically. There is also an added benefit: it's easy to make units go straight all the time because the marching squares will gives you the vertex that are reflexes and units can jump from reflexes right away.

The magic moment is that when you select a group of unit and make it attack a single target, the units will form a circle in a very elegant way. Here: https://gfycat.com/TediousThoseKitty

Re: Age of Empires Definitive Edition's pathing and movement

#55
post #4

I would've guessed that bad pathfinding in these old games was caused by very aggressive optimizations to improve performance but then the author starts off by saying: >DE's pathing system's findPath() function was speeded up by approx 3-4x faster vs. Age1's So the old code was just that bad? It's a bit odd, you'd expect such a critical piece of code in an RTS to be reasonably well written and optimized.

Machines and compilers have different constraints and heuristics today than back then. It may be that the old code was optimal given compilers at the time and the relative performance of memory access versus CPU, but that today's compilers and memory hierarchies have changed that.

Re: Age of Empires Definitive Edition's pathing and movement

#56
post #24

Earlier quoted context omitted.

Are you for real? The good path finding algorithms were devised in 80s and are described in detail in chestnuts like Cormen, Leiserson, Rivest, Stein Introduction to Algorithms. Released in 1990. I can understand skimping $40 on a book... but not the argument that it was hard to find those things.

'Pathfinding' in the scope of an RTS means a little more than just 'pathfinding' in the scope of a graph. If you had read the article you would have seen that there is a lot of dynamics behavior going on that is essential for the gameplay, but mostly unrelated to the A* search itself. I don't think you would find many books from the 80s about pathfinding for RTS games.

Actually, it is not, other than the fact that you have a limited time budget. In the old days, it was even simpler as you did not have to take multithreading or asynchronous behaviour into consideration. (Games still often run AI and physics on hard realtime tick but it is changing.)

About the only thing necessary is to stabilise pathing so that it doesn't return vastly different path on every tick and handling inter object collisions well. This may mean additionally handling swarm movement algorithms for which were already known way back in early 90s. Also in widely known books.

Games like Total Annihilation handled fast movement of hundreds of units at a time with decent to good pathing and a strong enough CPU - scaling the quality of pathing automatically with available CPU power to boot. Way better than AoE and it was released at about the same time - plus it has actually smooth terrain penalty unlike AoE chunky model underneath...

Three challenge was rarely algorithm but instead engineering. Time crunch was as real then as nowadays.

Re: Age of Empires Definitive Edition's pathing and movement

#57
post #24

Earlier quoted context omitted.

'Pathfinding' in the scope of an RTS means a little more than just 'pathfinding' in the scope of a graph. If you had read the article you would have seen that there is a lot of dynamics behavior going on that is essential for the gameplay, but mostly unrelated to the A* search itself. I don't think you would find many books from the 80s about pathfinding for RTS games.

Exactly. There's a huge difference between a theoretical algorithm in a book (that performs 1 search) vs having 120 real time units all trying to walk together, or even worse, through each other. In the 80's and 90's you were lucky to dig up docs from BBS releases that had math and graphics tutorials in them, it was very hard to find anything practical.

120 real units. By that you mean plotting 120 paths simultaneously using a common flow algorithm used by internet routers which is more than fast enough and reasonably easy to speed up or truncate.

The tricky part is on assigning nodes on a contiguous map or reducing number of nodes. (Or expanding node resolution on demand.)

Of course many games of the time side stepped it by using greedy truncated pathing instead. Easy, dirty, mediocre results.

Re: Age of Empires Definitive Edition's pathing and movement

#58
post #52

Sounds like many player complain about, that the game is too much like AoE1 :D So far I played only one match but that felt pretty much like the AoE1.

As someone who was a big RTS fan back in the 90s, the level of enthusiasm for AoE seems kind of odd to me. I always thought of it as an also-ran. I remember it coming out kind of late, only a little before Blizzard released StarCraft and basically killed the genre.

It did have a fairly unique setting among RTSes at least. So I could see the niche among historical enthusiasts who also wanted to play RTS. That wasn't me though.

Re: Age of Empires Definitive Edition's pathing and movement

#59

Earlier quoted context omitted.

Are you for real? The good path finding algorithms were devised in 80s and are described in detail in chestnuts like Cormen, Leiserson, Rivest, Stein Introduction to Algorithms. Released in 1990. I can understand skimping $40 on a book... but not the argument that it was hard to find those things.

Most of the interesting optimizations specific to the problem domain of games (e.g. JPS, Theta*) appeared after 2000. Anyway, the path finding feature is not finished once you have a graph traversal solution. Routing large armies with formations, varying unit sizes, dynamic terrain and collision detection remains fairly challenging in practice.

Indeed. But mostly due to engineering and time crunch, not because the algorithms are hard or unknown.

Re: Age of Empires Definitive Edition's pathing and movement

#60
post #5
post #4

I would've guessed that bad pathfinding in these old games was caused by very aggressive optimizations to improve performance but then the author starts off by saying: >DE's pathing system's findPath() function was speeded up by approx 3-4x faster vs. Age1's So the old code was just that bad? It's a bit odd, you'd expect such a critical piece of code in an RTS to be reasonably well written and optimized.

The old-timey pathfinding was probably optimising for memory usage, not speed or correctness.

Actually memory usage is and was speed too. Now CPUs are even faster still than memory.

Just like then, you cannot just load a many megabyte map of nodes and expect pathing to churn it in 120 fps. Even with good cache locality.

As a matter of fact, most pathing is local or inaccurate. The few exceptions I can think of are grand strategies and certain FPS that simulate world living beyond player's reach (immersive sims).

Post reply on HN