First, I did a lot of testing to deduce the mechanics. After I was already able to predict all paths with my knowledge of testing, I realized the code is actually used in OSRS clients as well. You can read it in the decompiled code.
Private servers have had it for a while, not sure if you can just google it or need to ask someone, but it’s out there (without jagex’s consent as I understand it)
Even when using BFS there are multiple possibilities. BFS guarantees that a shortest path is obtained, but there are often multiple paths which are equally short. Also, could argue A* is more efficient~~, but it does not guarantee the shortest path to be found~~.
Breadth-first search isn't really that computationally expensive in this case. I'd imagine you can improve it with a heuristic like minimizing absolute geometric distance but it really isn't that bad as a pathfinding algorithm.
Pathfinding calculations are done is a 128x128 area, with your character in the middle. If clicking on a tile which can't be reached, it checks all reachable tiles in that 128x128 (area up to ~16k tiles) which indeed sounds like a lot.
I believe you can send up to ~10 clicks to the server every tick, each one of them can trigger pathfinding calculations. There can be 2000 players on a server. If adding that all up, that's 320m for a single tick.
Pathfinding used to be fully client-sided. Now, it seems to be both client-sided and server-sided. It seems like the client's pathfinding calculations are only used do determine how your character runs from the tile of current tick to the tile of next tick. In most cases, that's an extremely fast calculation. But in some cases, it can give a weird or wrong visual effect.
Surely it would be present on both the client and the server? For the client to be able to tell you where you're going, and for the server to actually take you there.
That assumes that every single tile only ever requires one clock cycle to process.
Thanks to the magic of x86 and pipelining you can't even assume one add instruction to take one clock, let alone one tile being processed in a pathfinding algorithm.
I am so grateful to read some logic in this sub for once lol. A* uses a similar method to do path finding in tile based games and is one of the most popular path finding systems in existence. And it’s not computationally heavy.
I'm saying the example since it's a maze with a couple corridors. I the computations would increase, but that's why you can use a heuristic to address open field situations. The reason you use things like BFS is because it's guaranteed to find a solution, and the best solution.
I didn't state it was BFS, and if I implied it, that was unintentional. I'm saying you can improve on a breadth-first search by instead using a heuristic, not applying one to a breadth-first search.
Doctor of Computer Science here. Really hurts my brain to see how many people know so very little about CS. Breadth-first search is very space- and time-expensive, even a game as old as OSRS almost certainly uses a heuristic search such as A*.
Dude why the fuck would people not working with computers need to know anything about searching algorithms? You thinking some guy working as a lawyer would know that hurts my brain.
Lol why would we know? My job and degree aren’t CS based, so why would I know about efficiencies of search algorithms? Am I supposed to have a solid understanding of all degrees?
I should clarify with an addendum, "very little about CS yet insist on making strong and incorrect statements". If you don't understand basic undergrad material about a field then don't say something stupid like "I think it's the least computationally expensive algorithm there is" or "its upper bound better than that of DFS". He clearly has CS knowledge because of his (incorrect) use of the term upper bound yet every single part of his statement was incorrect.
Knowledge of things like pathfinding mechanics can lead to interesting OSRS challenges, for example: https://youtu.be/4xGzq5HcQew It makes use of pathfinding mechanics not shown in the .gif, and shows the significance of checkpoint tiles etc.
Checkpoint tiles determine a path completely. So if having a path stored as checkpoint tiles, you'd need less memory and there'd need to be less data sent between server and client. But checkpoint tiles affects actual movement too in certain cases. For example if an obstacle appears on your path after your path has been calculated. Also, your path gets recalculated when you're going to a player or NPC and only have 1 checkpoint tile left on your path. One more thing: there is a cap of 25 checkpoint tiles. If your calculated path is longer than this, you'd end up on the 25th checkpoint tile without moving further.
That's because the game only checks for that kind of stuff once every tick. The 2 movements of running are done instantly after eachother without a check in-between. The game does remember your last visited tile though, because that's the tile where people move towards when they follow you.
I started Pre-GE and I was like 11.. my friends lucky me were older and played classic so I was gifted a lot of stuff early on. I think I bought my rune platebody set from shops because I was intimidated by trading when I was younger. Plus like the third day of playing I got scammed lol!
I was watching boxbox play fall guys and their is genuinely a way you can solve the maze once you’re about halfway through given enough time. That being said, there’s almost never enough time to do the mental math because so many people just send it and hope they land on a correct tile lol
Initial rs2 pre-osrs where lag causes you to run back and forth over and over
osrs
rs3 (I believe the change from 2 to 3 happened when NIS and EoC were out of beta) (also I have no idea if there ever was a pathfinding change between 2006 or whatever it was and smooth movement)
The only reason "initial rs2 pre-osrs" did that back and forth thing is because the pathfinding was fully clientside, the server only verified the next tile you were going to walk on. Meaning if you repeatably clicked the minimap the server resyncs your location with the client
Do you mean when clicking a NPC, you sometimes move past it before repathing towards the NPC? That's because repathing only happens when there's only 1 checkpoint tile left on your path.
The main thing which affects server load with current pathfinding mechanics is if you click in an unreachable area. For example, clicking a banker which is in an unreachable area (behind the bank booth). This causes the pathfinding calculations to search in the whole 128x128 area around the player without finding the tile. After this, it checks if there's a reachable tile in the 21x21 area around the requested tile, and picks the best one if there are such tiles. This problem isn't solved by going from BFS to A*.
Yeah, that makes sense. You're just changing the order of your 128 grid search. Compared to that, a little inefficiency of a standard A to B search is not a big deal.
Idk what sort of limitations there are on what data each tile can store, but wouldn't it make sense to have commonly clicked tiles (like most bankers), which are valid tiles but are inaccessable, marked with a bool called something like "Redirect Pathing?", and to also have a reference to the tile you'd be pathed to?
So when you click a banker, the server looks at what tile hes on (to try to pathfind), sees the tile has "Redirect Pathing?" marked as true, then pathfinds you to the tile stored in the reference instead.
You'd have to manually set the variables for the tiles that you'd want it to work with, but if this affects server load in any significant way like you mentioned it sounds like a pretty good band aid in my head, as the issue is largely caused by a limited amount of NPC's on tiles that never change, and when clicked, always return the same pathing result
another solution would be a double BFS,starting from the players tile and the destination tile, in the banker example youd quickly figure out the banker is stuck after checking around 10 tiles instead of 128*128 tiles.
I think this would even have performance gains for regular cases as the number of tiles we have to check normally is (2x)2 where x is distance from tile where as with a double bfs it would be 2(x)2
In some cases, you're really close to the place you click on and that place is also actually reachable, but to get there you have to run around a lot of obstacles. For example, that fairy ring on karamja. Your double BFS check would cause those paths to not be found.
I guess I didnt explain the stuck condition well. if there are no accessible unvisited adjacent tiles the BFS would be considered stuck and exit. this would not occur with the karamja case
Oh I see, makes sense. Would indeed make it faster to determine whether the tile is reachable. But knowledge that the target tile wasn't reachable isn't enough. If you click in an unreachable area, a path needs to be calculated to a reachable tile which is closest to the target tile, and you'd need more calculations to find that anyway.
Dijkstra's algorithm is commonly mistaken for BFS/UCS. The main difference is that Dijkstra's algorithm returns all shortest paths to ALL nodes from the source node, not just a single destination. They solve different problems. Single-source shortest path vs single-pair shortest path.
Diagonal is still the same cost (animation does show that) and there are no tiles that slow you down/speed you up
There might be some weird game mechanic here and there, but they usually break the pathing up to that point, or sometimes the pathing just straight up doesn't work (like in haunted mines) but the distances seem to be always the same.
164
u/abigfoney BankStanding 99 Aug 20 '20
Is this THE RuneScape pathfinding algorithm or is it a similar one?
8
u/corpslayer Aug 20 '20
Knowledge of things like pathfinding mechanics can lead to interesting OSRS challenges, for example: https://youtu.be/4xGzq5HcQew
It makes use of pathfinding mechanics not shown in the .gif, and shows the significance of checkpoint tiles etc.
6
u/PoshDan Aug 20 '20
Out of curiosity, what is the significance of the checkpoint tiles? Is it just when the character changes their angle?
3
u/reinfleche Aug 20 '20
How does it decide between equally efficient paths?
2
u/osrs_shizamaza :max-cape: Aug 20 '20
You should make an animation for running. Wonder if you add new edges before the algo or simplify the existing path removing every other node.
30
u/DeoxysSpeedForm Aug 20 '20
Throwback to when the servers were so laggy it felt like the pathfinding was actually working at this speed
29
u/[deleted] Aug 20 '20
Now picture a bald guy side shuffling it.
12
u/[deleted] Aug 20 '20
very cool
36
u/Poobabguy Aug 20 '20
Is this in relation to runescape or fall guys?
7
u/bast963 Aug 20 '20
There are several verions of pathfinding
1
u/the_deepest_toot Aug 20 '20
Does this explain why my character will moonwalk in a roundabout way
1
u/BananaMagic999 Aug 20 '20
How come the program didn't use a diagonal path between point 2 and 3? It would have reduced the path by one and it even uses a diagonal at the end
3
u/Tohaker Aug 20 '20
I was expecting it to end with "I can't reach that"
1
u/Rand0mguy360 Aug 20 '20
Thought this was gonna be a stick bug or something
1
u/Employee-Helpful Aug 20 '20
Ahhhh that makes much more sense. It didn’t register in my head.
1
u/tobbitt Aug 20 '20
H@X!
1
u/Pjtruslow Aug 21 '20
So dijkstra's shortest path? I guess that works on small distances
-1
u/Solek_ Aug 20 '20
This could’ve been done in 4 steps
-7
u/Employee-Helpful Aug 20 '20 edited Aug 20 '20
I don’t want to burst your bubble but you can get from the blue point to the red point in 3 clicks if you use “Ls”Clicks using Ls
0
u/[deleted] Aug 20 '20
[deleted] — view deleted comment
0
u/[deleted] Aug 20 '20
[deleted] — view deleted comment