pathfinding.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:AbricotGame 作者: NB0174 项目源码 文件源码
def linearize(path: List, obstacles: List[Tuple]) ->List:
    """
    Remplit l'espace entre deux cases non consecutives
    :param path: -> Liste de coordonnees du chemin
    :param obstacles: -> Liste de coordonnees des obstacles
    :return: -> Une liste linearisee
    """
    y_dir = 1 if path[0][1] < path[-1][1] else -1
    x_dir = 1 if path[0][0] < path[-1][0] else -1
    list2 = []
    for i in range(1, len(path) + 1):
        try:
            list2.append(path[i - 1])
            if path[i - 1][0] != path[i][0] and path[i - 1][1] != path[i][1]:
                if (path[i - 1][0], path[i - 1][1] + y_dir) not in obstacles:
                    list2.append((path[i - 1][0], path[i - 1][1] + y_dir))
                elif (path[i - 1][0] + x_dir, path[i - 1][1]) not in obstacles:
                    list2.append((path[i - 1][0] + x_dir, path[i - 1][1]))
        except IndexError:
            continue

    return list(remove_duplicates(list2))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号