astar算法c语言实,AStar寻路算法 c语言实现

/************************

## author:Dante Lee

## email:bhlzlx@gmail.com

## qq:583035284

************************/

#ifndef ASTAR_H_INCLUDED

#define ASTAR_H_INCLUDED

#include 

#include 

#include 

#define MAP_INITED  1

// cell types

#define WALKABLE    0

#define UNWALKABLE  1

#define YES         1

#define NO          0

// the struct contains all the basic information for a AStar Cell.

typedefstructAStarCell

{

// the position

intx;

inty;

// attribute

shortintcellType;

} *pAStarCell,AStarCell_;

///contains the enssential information for the Node,

/// for example 1.parent node 2.the node's cost and so on.

typedefstructAStarCellNode

{

//AStarCell

pAStarCell pCell;

//the cost

floatstaticCost;

floatpredictCost;

floattotalCost;

//neighbor cells

structAStarCellNode * lpUp;

structAStarCellNode * lpRightUp;

structAStarCellNode * lpRight;

structAStarCellNode * lpRightDown;

structAStarCellNode * lpDown;

structAStarCellNode * lpLeftDown;

structAStarCellNode * lpLeft;

structAStarCellNode * lpLeftUp;

//neighbor nodes array

structAStarCellNode * neighborArray[8];

//parent node

structAStarCellNode * lpParent;

} *pAStarCellNode,AStarCellNode_;

//AStarMap for manager the cells.

typedefstructAStarMap

{

// 1 means inited.

charinitState;

intwidth;

intheight;

char** lpSourceMatrix;

AStarCellNode_ *** lpCellMatrix;

}*pAStarMap,AStarMap_;

/***********************************

*Openlist & Closelist Structures

*

***********************************/

typedefstructAStarCellListNode

{

structAStarCellListNode * prevNode;

structAStarCellListNode * nextNode;

pAStarCellNode  currentCellNode;

}*pAStarCellListNode,AStarCellListNode_;

typedefstructAStarOpenList

{

intnodeCount;

pAStarMap pMap;

char** assertMap;

pAStarCellListNode headNode;

pAStarCellListNode tailNode;

}*pAStarOpenList,AStarOpenList_;

typedefstructAStarCloseList

{

pAStarMap pMap;

// choose char to instead of boolean type

char** assertMap;

}*pAStarCloseList,AStarCloseList_;

/***************************

*other structure

*

**************************/

typedefstructAStarPoint

{

intx;

inty;

}*pAStarPoint,AStarPoint_;

typedefstructAStarPathNode

{

structAStarPathNode * prevNode;

structAStarPathNode * nextNode;

pAStarCellNode currentNode;

}*pAStarPathNode,AStarPathNode_;

typedefstructAStarPathList

{

pAStarPathNode headNode;

pAStarPathNode tailNode;

intnodesCount;

}*pAStarPathList,AStarPathList_;

typedeffloat(* CalculateCallBack)(pAStarCellNode,pAStarCellNode,pAStarCellNode);

typedefstructAStarMain

{

CalculateCallBack cal_fun;

pAStarMap  pMap;

pAStarCloseList pCloseList;

pAStarOpenList pOpenlist;

}*pAStar,ASTAR,AStar;

///

#include 

// astar cell functions

pAStarCell astar_cell_init(floatx_,floaty_,shortintcellType);

//astar node functions

structAStarCellNode * astar_cellNode_init(structAStarCell * pCell_);

voidastar_cellNode_assignNeighborNodes(

structAStarCellNode * pNode,

pAStarCellNode down_,

pAStarCellNode left_,

pAStarCellNode leftDown_,

pAStarCellNode leftUp_,

pAStarCellNode right_,

pAStarCellNode rightDown_,

pAStarCellNode rightUp_,

pAStarCellNode up_);

voidastar_cellNode_cleanup(structAStarCellNode * pNode);

voidastar_cellNode_reset(structAStarCellNode * pNode);

// astar map functions

//

pAStarMap astar_map_initFromMemery(void* bytesBuffer,intwidth,intheight);

voidastar_map_printBytesMatrix(pAStarMap pMap);

voidastar_map_cleanup(pAStarMap pMap);

/****************************

*Openlist & Closelist utilities

*

****************************/

pAStarCellListNode  astar_cellListNode_init(pAStarCellNode pCellNode);

voidastar_cellListNode_cleanup(pAStarCellListNode pCellListNode);

pAStarOpenList astar_openList_init(pAStarMap pMap);

voidastar_openList_insertCellNode(pAStarOpenList pOpenList,pAStarCellNode pCellNode);

pAStarCellNode astar_openList_removeTheLeaseCostNode(pAStarOpenList pOpenList);

pAStarCellNode astar_openList_retriveTheLeaseCostNode(pAStarOpenList pOpenList);

voidastar_openList_cleanup(pAStarOpenList pOpenList);

voidastar_openList_printList(pAStarOpenList pOpenList);

voidastar_openList_reset(pAStarOpenList pOpenList);

pAStarCloseList astar_closeList_init(pAStarMap pMap);

voidastar_closeList_addCellNode(pAStarCloseList pCloseList,pAStarCellNode pCellNode);

charastar_closeList_assertHasCellNode(pAStarCloseList pCloseList,pAStarCellNode pCellNode);

voidastar_closeList_reset(pAStarCloseList pCloseList);

voidastar_closeList_cleanup(pAStarCloseList pCloseList);

/****************************

*main structures function*

****************************/

ASTAR * astar_main_initAStar(void* ptr,intwidth,intheight);

voidastar_main_cleanup(pAStar astar);

voidastar_main_setCalculateCallBack(pAStar astar,CalculateCallBack callbackfun);

/****************************

*path finding function*

****************************/

charastar_findPath(pAStar astar,AStarPoint_ start,AStarPoint_ end,pAStarPathList pPathOuter);

/****************************

*path creating function*

****************************/

pAStarPathList astar_pathList_init(void);

voidastar_path_insertFront(pAStarPathList pathList,pAStarCellNode pCellNode);

voidastar_path_print(pAStarPathList pPathList);

voidastar_path_cleanup(pAStarPathList pPathList);

/****************************

*the cost calculating function*

****************************/

floatastar_calc_diagonal(pAStarCellNode parentNode,pAStarCellNode currentNode,pAStarCellNode destinationNode);

floatastar_calc_manhatton(pAStarCellNode parentNode,pAStarCellNode currentNode,pAStarCellNode destinationNode);

floatastar_calc_euclidian(pAStarCellNode parentNode,pAStarCellNode currentNode,pAStarCellNode destinationNode);

#endif // ASTAR_H_INCLUDED

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值