Reputation: 605
I have a 2D int array which I processed and got from an image. Each index can be thought as weight of that pixel. I want to find a path between 2 indexes (I'll give these indexes as input) that has the least cost. It would be great if the direction of movements can be modified (like only down&left, up&left. or all. etc. otherwise it may be down, left and right)
How can i do that in C#?
Upvotes: 0
Views: 5350
Reputation: 4561
Regardless of language, I would calculate the cost for a direct path first. This will became the first base line. Then I would recursively search for a shorter path. You can make a few boundary checks to reduce the recursion.
Upvotes: 1
Reputation: 169388
The A* algorithm (as was already tagged :)) is a good choice for this.
See, for example, How to implement an A* algorithm?
Upvotes: 0