Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 六边形网格,在n步中找到所有可能的路径_Python_Python 3.x - Fatal编程技术网

Python 六边形网格,在n步中找到所有可能的路径

Python 六边形网格,在n步中找到所有可能的路径,python,python-3.x,Python,Python 3.x,我也有同样的问题,比如问题 不幸的是,我需要一个六边形网格中两个字段之间的所有可能路径,精确地分为n步,但没有循环。现在,如果n_步数远大于这些字段之间的最短路径,我将有很多循环 我正在努力寻找一个合适的递归函数,它将帮助我在列表中写下路径 我的函数如下所示: def find_paths_from_to_with_length(self, pos_1,pos_2,n_steps): coordinate_1= self.find_coordinates(pos_1) neigh

我也有同样的问题,比如问题

不幸的是,我需要一个六边形网格中两个字段之间的所有可能路径,精确地分为n步,但没有循环。现在,如果n_步数远大于这些字段之间的最短路径,我将有很多循环

我正在努力寻找一个合适的递归函数,它将帮助我在列表中写下路径

我的函数如下所示:

def find_paths_from_to_with_length(self, pos_1,pos_2,n_steps):
    coordinate_1= self.find_coordinates(pos_1)
    neighbour_pos_1= self.coordinates[coordinate_1].neighbour_list
    if n_steps == 1:
        if pos_2 in neighbour_pos_1:
            return [[(pos_1,pos_2)]]
        return []
    if pos_1 == pos_2:
        return []

    all_paths = []

    for node in neighbour_pos_1:
        neighbor_all_paths = self.find_paths_from_to_with_length(node,pos_2,n_steps-1)
        for path in neighbor_all_paths:
                print("PATH: ",path)
                all_paths.append([(pos_1,node)] + path)
    return all_paths
有人能解决这个问题吗