提交 645daef0 编写于 作者: Z zx_lhb

添加A星寻路算法头文件

上级 e035d2ee
#pragma once
#include<memory>
#include<vector>
class Grid
{
public:
// 坐标位置
int x, y;
// fcost,gcost,hcost
double f, g, h;
// 当前点的父节点
std::shared_ptr<Grid> parent;
public:
// 构造函数
Grid(int x_, int y_);
// 析构函数
~Grid(){}
// 更新grid
void updateGrid(std::shared_ptr<Grid> parent, const std::shared_ptr<Grid> end);
};
class AStar
{
private:
int mazeRow, mazeColum;
std::vector<std::vector<int>> maze;
void findMinGrid(std::vector<std::shared_ptr<Grid>>& openList,
std::shared_ptr<Grid>& currentGrid);
void findNeighbors(std::shared_ptr<Grid> grid,
std::vector<std::shared_ptr<Grid>>& open_list,
std::vector<std::shared_ptr<Grid>>& close_list,
std::vector<std::shared_ptr<Grid>>& neighbors);
bool isValidGrid(int x_, int y_,
std::vector<std::shared_ptr<Grid>>& open_list,
std::vector<std::shared_ptr<Grid>>& close_list);
bool containGrid(const std::vector<std::shared_ptr<Grid>>& grids_, int x_, int y_);
public:
AStar(const int maze_rows, const int maze_colums,
const std::vector<std::vector<int>>& maze_) :mazeRow(maze_rows), mazeColum(maze_colums),maze(maze_) {}
/// <summary>
/// A星寻路算法
/// </summary>
/// <param name="re_end">返回的结果格子</param>
/// <param name="start">开始格子</param>
/// <param name="end">终点格子</param>
void aStarSearch(std::shared_ptr<Grid>& re_end,
std::shared_ptr<Grid> start,
std::shared_ptr<Grid> end);
/// <summary>
/// 由找到的终点回溯路径
/// </summary>
/// <param name="re_grid">找到的终点</param>
/// <param name="path_">回溯到的路径</param>
void getPath(std::shared_ptr<Grid> re_grid,
std::vector<std::shared_ptr<Grid>>& path_);
void printPath(const std::shared_ptr<Grid> start_,
const std::shared_ptr<Grid> end_,
const std::vector<std::shared_ptr<Grid>>& path_);
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册