这是我第一次blog,写的不好不对的地方请大家一定批评指正.
最近看到论坛上在讨论a*算法,恰好忙完一个项目有空,就花了几天时间研修了一下A*算法.就把一些感想和代码贴上来跟大家分想交流.
一, 一些数据结构.
1,迷宫 二维数组 typedef vector<vector<element> > MAZE;
2,OpenList 用heap实现. my::Heap<element> hp; 另一个版本用list实现 typedef list<element> LE; 具体用宏USE_LIST 控制.
3,CloseList 用vector实现 VE close_list;(因为只涉及到插入(只在末端操作)和查找,所以从各方面考虑vector是最佳选择);
4,元素element看上去有点复杂,其实只是为了对元素进行比较,查找的操作而重载了几个运算符.具体见element.h
#ifndef ELEMENT_H__
#define ELEMENT_H__
#define START 'S'
#define END 'E'
#define WAY '#'
#define BLANK ' '
#define WALL '1'
struct location
... {
int x;
int y;
location(int xx=0,int yy=0):x(xx),y(yy)...{}
location& operator= (const location& other)
...{
if(this ==
#define ELEMENT_H__
#define START 'S'
#define END 'E'
#define WAY '#'
#define BLANK ' '
#define WALL '1'
struct location
... {
int x;
int y;
location(int xx=0,int yy=0):x(xx),y(yy)...{}
location& operator= (const location& other)
...{
if(this ==