/************************
## 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