Search Wiki:

New Release!

I added a slightly improved version to the archive here. Not a huge improvement, but improvements in many arenas. You can now adjust paths by adding or removing walls anywhere.

Pathfinding C#

This is a resource page for a simple implementation of a pathfinding algorithm in C#. It uses enumerators and objects to find the shortest distance between two points on a field. It is very simple and not very powerful right now.

The program also contains a way to add walls and save and open different maps. I intend to add more features and enhancements to the app, but I think it would be best to release an early version.

Requirements

It works well in Visual Studio 2008 and I hope the code is easy to understand. It will require .NET 3.5 but you doubtless have that if you are using Visual Studio 2008.

Screenshots

Here are a couple screenshots. The first one shows a simple map, with the path being blue and the two points being red. The two points can be thought of as a monster and a hero.

minotaur1.png

Here is another example. Note that you can click on a square to add a wall, which will cause the path to move.

Minotaur2.png

Notes

Maps are stored in plain text. Currently things are very simple but the algorithm works reliably. There is a detailed write up at http://dotnetperls.com/Content/Pathfinding.aspx that you definitely should read if you are interested in this project.

The algorithm uses enumerators on 2D arrays.

Important Links

This is not intended to become a huge blockbuster game! I just want to show the algorithm and maybe encourage some programmers to start a new project similar to this. I think you can have fun working with this stuff and I hope you do.

This is .NET 3.5 C# code. There are many more articles at my site http://dotnetperls.com/, although not any others on this exact topic. Finally my site has more code at http://code.google.com/p/dotnetperls-controls/.
Last edited Oct 29 2008 at 12:57 AM  by smallenucd, version 15
Comments
smallenucd wrote  May 15 2008 at 4:59 AM  
Made the page organized better

smallenucd wrote  May 17 2008 at 3:06 AM  
New release!

smallenucd wrote  May 17 2008 at 3:07 AM  
Formatting fixes

grayaii wrote  May 7 at 2:58 AM  
I'm not sure why I'm getting a significant time hit when Pathfind() is called. I can clearly reproduce this by having a for-loop (30, for example) around the Pathfind() function. It takes ~2 seconds to call Pathfind 30 times. I thought AStar algorithm is super fast and even RTS games use it all the time. Great code, by the way!

Updating...
Page view tracker