[英]Path finding on 2D array
I have a 2D int array which I processed and got from an image. 我有一个二维int数组,该数组是我从图像中处理并获得的。 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.
我想找到成本最低的2个索引之间的路径(我将这些索引作为输入)。 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#? 我该如何在C#中做到这一点?
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.
您可以进行一些边界检查以减少递归。
The A* algorithm (as was already tagged :)) is a good choice for this. A *算法(已经标记为:))是一个很好的选择。
See, for example, How to implement an A* algorithm? 参见,例如, 如何实现A *算法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.