// Zebra.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "FindPath.h"
#include <iostream>
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
//int nWidth = 1001;
//int nHeight = 1001;
//
//FindPath::AStar::MapPosItem * pMapInfo = new FindPath::AStar::MapPosItem[nWidth* nHeight];
//if( NULL == pMapInfo )
//{
// std::cout<<"地图内存申请失败"<<std::endl;
//}
//for( int i = 0;i<nWidth;i++)
//{
// for( int j=0;j<nHeight;j++ )
// {
// if( j %2 == 0 && j != 0 && j != 1000 )
// {
// if( (i+j)%29==0 )
// {
// pMapInfo[i*nWidth+j].m_Data = 0;
// pMapInfo[i*nWidth+j].m_Pos.m_x = j;
// pMapInfo[i*nWidth+j].m_Pos.m_y = i;
// }
// else
// {
// pMapInfo[i*nWidth+j].m_Data = 1;
// pMapInfo[i*nWidth+j].m_Pos.m_x = j;
// pMapInfo[i*nWidth+j].m_Pos.m_y = i;
// }
// }
// else
// {
// pMapInfo[i*nWidth+j].m_Data = 0;
// pMapInfo[i*nWidth+j].m_Pos.m_x = j;
// pMapInfo[i*nWidth+j].m_Pos.m_y = i;
// }
// }
//}
//
//std::cout<<"开始加载地图"<<std::endl;
//FindPath::AStar::AStarMap g_Map;
//if( false == g_Map.LoadMap(pMapInfo,nWidth,nHeight ))
//{
// std::cout<<"加载地图失败"<<std::endl;
//}
//FindPath::AStar::AStartFindPath _FindPath( &g_Map );
//
//FindPath::Pos _Begin;
//_Begin.m_x = 0;
//_Begin.m_y = 500;
//FindPath::Pos _End;
//_End.m_x =1000;
//_End.m_y = 500;
//
//std::cout<<"开始寻路 地图大小"<<nWidth<<"*" <<nHeight<<std::endl;
//FindPath::PosPath _ResPath;
//DWORD _TimeBegin = GetTickCount();
//bool _Res =_FindPath.FindPath( _Begin ,_End,_ResPath );
//DWORD _TimeUse = GetTickCount( ) - _TimeBegin;
//if( false == _Res )
//{
// std::cout<<"寻路失败 结点数:"<< _ResPath.size( )<<"用时:"<<_TimeUse <<"毫秒"<<std::endl;
//}
//else
//{
// std::cout<<"寻路成功 结点数:"<< _ResPath.size( )<<"用时:"<<_TimeUse <<"毫秒"<<std::endl;
//}
//
//FindPath::PosPath::const_iterator it = _ResPath.begin();
//int i = 0;
//for( ; it != _ResPath.end() ;it ++ )
//{
// i++;
// if( i%5 == 0 )
// {
// std::cout<<" "<<(*it).m_x <<","<<(*it).m_y<<std::endl;
// }
// else
// {
// std::cout<<" "<<(*it).m_x <<","<<(*it).m_y;
// }
//
//}
FindPath::Dijkstra::DijkMapData * pDijkData = new FindPath::Dijkstra::DijkMapData;
#define EDGE_COUNT 5
pDijkData->m_Count = EDGE_COUNT;
pDijkData->m_pEdge = new FindPath::Dijkstra::Edge[EDGE_COUNT];
pDijkData->m_pEdge[0].m_EdgeNoWeight.m_Begin = FindPath::Pos( 0,0 );
pDijkData->m_pEdge[0].m_EdgeNoWeight.m_End = FindPath::Pos( 0,1 );
pDijkData->m_pEdge[0].m_Weight = 100;
pDijkData->m_pEdge[1].m_EdgeNoWeight.m_Begin = FindPath::Pos( 0,0 );
pDijkData->m_pEdge[1].m_EdgeNoWeight.m_End = FindPath::Pos( 0,2 );
pDijkData->m_pEdge[1].m_Weight = 2;
pDijkData->m_pEdge[2].m_EdgeNoWeight.m_Begin = FindPath::Pos( 0,2);
pDijkData->m_pEdge[2].m_EdgeNoWeight.m_End = FindPath::Pos( 0,3 );
pDijkData->m_pEdge[2].m_Weight = 3;
pDijkData->m_pEdge[3].m_EdgeNoWeight.m_Begin = FindPath::Pos( 0,0 );
pDijkData->m_pEdge[3].m_EdgeNoWeight.m_End = FindPath::Pos( 0,3 );
pDijkData->m_pEdge[3].m_Weight =6;
pDijkData->m_pEdge[4].m_EdgeNoWeight.m_Begin = FindPath::Pos( 0,3 );
pDijkData->m_pEdge[4].m_EdgeNoWeight.m_End = FindPath::Pos( 0,1 );
pDijkData->m_pEdge[4].m_Weight =8;
FindPath::Dijkstra::DijkstraMap _DijkMap;
if( false == _DijkMap.LoadMap((void*)pDijkData))
{
std::cout<<"加载地图失败"<<std::endl;
}
FindPath::Pos _Start(0,0);
FindPath::Dijkstra::DijkStraPathSet _DijkPathSet;
FindPath::Dijkstra::DijkstraFindPath _FindPath(&_DijkMap);
if(false == _FindPath.FindPath( _Start ,_DijkPathSet ))
{
std::cout<<"无法找到路径"<<std::endl;
}
else
{
std::cout<<"寻路成功"<<std::endl;
}
return 0;
}