Well I needed to do some path finding in one of my C# projects so I ported my Pathfinder library to C# which you can grab at http://members.byond.com/Theodis/files/AStar.cs . It uses generics so at least .NET 2.0 is required.
The algorithm and logic are pretty much exactly the same so any functionality should work exactly the same including any bugs if any. The only difference is some syntactical stuff for parameters and I store the bestF in a dictionary rather than directly on the node like in BYOND. I did this for several reasons. First off if I want to tack on information to the nodes themselves then I need to make the nodes being search either derived from one of my classes or they need to have an interface. This could be a problem if you're working with a data structure you don't have access to the code for or for any other reason can't change. Second reason is that storing information about the search on nodes prevents running multiple path searches on seperate threads since each would end up conflicting by messing with and using each others values tacked on the data structure. By doing this with a dictionary in theory it should be safe to run simultaneous searches(though I haven't tested this yet).
The downside is that it is potentially slower. How much slower depends on how the C# dictionary is implemented and its random access time. If it's good and has logrithmic or constant access time it shouldn't be much of an issue which is likely the case.
I don't have any demos on how to use it but it should be similar to how you'd do it in BYOND except that you'd be using delegates rather than passing in paths for the parameters to the functions needed.
ID:34803
![]() Sep 13 2007, 7:32 pm
|
|