python - Hexagonal grid, find all possible paths in n steps -
i have same problem, this question.
sadly need possible paths between 2 fields in hexagonal grid in n steps, without loops. right now, if n_steps greater shortest path between fields, have lots of loops.
i struggling find fitting recursive function, me write down paths in list of lists.
my function looks this:
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 = [] node in neighbour_pos_1: neighbor_all_paths = self.find_paths_from_to_with_length(node,pos_2,n_steps-1) path in neighbor_all_paths: print("path: ",path) all_paths.append([(pos_1,node)] + path) return all_paths
anyone has solution problem?
Comments
Post a Comment