据我所知,你从不检查你是否已经参观过广场。此外,您将使用x和y来表示非x,y坐标的值,并检查索引的一端并捕捉另一端的异常。这太复杂了。我的建议是实现实际的算法:def gen_lee(start, size, travelable):
neighbor_offsets = [(0, 1), (1, 0), (0, -1), (-1, 0)]
score = 0
path_map = [[None for _ in xrange(size)] for _ in xrange(size)]
node_list = [start]
path_map[start[0]][start[1]] = 0
for node in node_list:
score = path_map[node[0]][node[1]]
for neighbor_offset in neighbor_offsets:
neighbor_x = node[0] + neighbor_offset[0]
neighbor_y = node[1] + neighbor_offset[1]
if neighbor_x < 0 or \
neighbor_y < 0 or \
neighbor_x >= size or \
neighbor_y >= size:
continue # Skip out of map neighbors
if not travelable[neighbor_x][neighbor_y]:
continue # Skip untravelable neighbors
if path_map[neighbor_x][nei