# A*算法寻路算法(最短路径???)代码文件3

// myfindgo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include

#include "find_path.h"

#include "windows.h"
#include "mmsystem.h"
#pragma comment(lib, "winmm.lib")

class test_map
{
#define MAP_W_MAX 1000
#define MAP_H_MAX 1000
public:
test_map()
{
memset(map, 0, sizeof(map));
}

static bool go_test(int x, int y)
{
if (x < 0 || y < 0
|| x >= MAP_W_MAX
|| y >= MAP_H_MAX
) return false;

if (0 != map[x][y]) return false;

return true;
};

static bool map[MAP_W_MAX][MAP_H_MAX];
};
bool test_map::map[MAP_W_MAX][MAP_H_MAX];

int x0 = 2;
int y0 = 2;
int x1 = 1;
int y1 = 1;

{
FILE *f;
f = fopen("c://tmp//map.txt","r");
if (NULL == f) return;

int x = 0;
int y = 0;
fscanf(f, "%d, %d/n", &x, &y);
for (int j = 0; j < y; j++)
{
char line[1024] = {0};
fgets(line, x + 1, f);

for (int i = 0; i < x; i++)
{
if (' ' != line[i]) test_map::map[i][j] = 1;

if ('s' == line[i])
{
x0 = i;
y0 = j;
test_map::map[i][j] = 0;
}

if ('e' == line[i])
{
x1 = i;
y1 = j;
test_map::map[i][j] = 0;
}
}
}
fclose(f);
}

int main(int argc, char* argv[])
{
test_map map;
//--初始化地图
//--不可到达的点
//map.map[0][0] = 1;
map.map[2][1] = 1;
map.map[3][1] = 1;
map.map[1][2] = 1;
map.map[3][2] = 1;
map.map[0][2] = 1;

find_pathAB fp;
fp.init(100, 25, test_map::go_test);

int z;

DWORD t1 = timeGetTime();
//--寻路
{
for (int i = 0; i < 1000; i++)
z = fp.go(x0, y0, x1, y1);
}
DWORD t2 = timeGetTime();
DWORD t = t2 - t1;

//--打印路径
for (int i = 0; i <= fp.path_t; i++)
{
printf("x=%d y=%d/r/n"
, fp.path_p[i].x
, fp.path_p[i].y);
}
printf("path_t=%d time_t=%d(ms)/r/n", fp.path_t, t);

getch();
return 0;
}

80,24
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
o                                                                             o
o                                                                             o
o   s                        oooooooooooooo                                   o
o                                         o                                   o
ooooooooooo                               o                                   o
o         o      ooooooo     oooooooooooooo       oooooooo                    o
o    oooooo      o     oooo                       o      o                    o
o                o        o                       ooo  ooo                    o
o                oooo  oooo                                                   o
o                                oooooooooooooooooooooooooooooooooooooooooooooo
o                                                                             o
o                                                                             o
o                                                                             o
oooooooooooooooooooooooooooooooooooooooooooo                                  o
o       o                                                           ooooooooooo
o       o   ooooooo                                      oooooooo             o
o       o         o                                      o      o             o
o       ooooooooooo        oooooooooo                    o      o             o
o                          oe       ooo                  o      o             o
o                          ooooo      o                  o      o             o
o                                     o                  o                    o
o                              o      o                  o                    o
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

• 本文已收录于以下专栏：

举报原因： 您举报文章：A*算法寻路算法(最短路径???)代码文件3 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)