最近要用A star算法
推荐一个非常直观的学习A算法的网站
https://www.redblobgames.com/pathfinding/a-star/introduction.html
还有一个各种算法的对比
https://github.com/zhm-real/PathPlanning
下面是自己写的A算法
"""
@Date: 2021/11/10
@Author:Xmmm0569
@Brief: Path Planning:A Star Algorithm
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
maps = np.full((10, 10), 8) # maps[0][0] 起点 maps[9][9] 终点
for i in range(10):
for j in range(10):
if (i == 0 and j == 0) or (j == 9 and i == 9):
continue
if np.random.uniform(0, 10) < 3:
maps[i][j] = 0
# print(maps)
class Astar:
def __init__(self):
self.start = [0, 0]
self.end = [9, 9]
self.open = [] # open表[x, y, detax, detay, g, f]
self.close = [] # 同open表
self.best_path = []
def h_value(self, now):
return abs(now[0] - self.end[0]) + abs(now[1] - self.end[1]