Skip to content
Permalink
Browse files

merge

  • Loading branch information
YukangChen committed May 10, 2016
2 parents 72d2cdd + e130fb9 commit 1c849824412ac6896fba6a0906de11a2cafd82d7
Showing with 95,297 additions and 146 deletions.
  1. +5 −1 .gitignore
  2. +44 −0 .ninja_log
  3. +3 −5 A_star.cpp
  4. +1 −0 A_star.h
  5. +10 −9 Algorithm.cpp
  6. +57 −56 Algorithm.h
  7. +4 −6 DFS_L.cpp
  8. +4 −6 DFS_R.cpp
  9. +1 −2 DisjSets.cpp
  10. +26 −23 Maze.cpp
  11. +6 −6 Maze.h
  12. +13 −1 README.md
  13. +57 −0 build.ninja
  14. +28 −0 cscope.files
  15. +94,659 −0 cscope.out
  16. +1 −1 glui.h
  17. BIN libmaze.a
  18. +20 −19 main.cpp
  19. +338 −11 makefile
  20. BIN obj/liball.a
  21. +20 −0 obj/main.exe.dSYM/Contents/Info.plist
@@ -1 +1,5 @@
*.o
*.o
*.exe
*.o.d
.ninja_deps
*.a
@@ -0,0 +1,44 @@
# ninja log v5
1 755 0 CMakeFiles/maze.dir/Algorithm.cpp.o 3610f247e2a89264
0 1311 0 Algorithm.o f02d9836aa684578
1 372 0 CMakeFiles/maze.dir/Maze.cpp.o 1b2a8b2d293f4c24
1 565 0 obj/DisjSets.o f4bef513a8a36b2a
1 360 0 CMakeFiles/maze.dir/A_star.cpp.o f8dcb876e2c88284
0 722 0 obj/Algorithm.o 5fef5b771d135e37
2 752 0 DisjSets.o 47e3336f0743c9e1
1 892 0 obj/A_star.o aec7c9dae59f9632
1 722 0 CMakeFiles/maze.dir/DFS_L.cpp.o 26c79e6bb385be75
2 1278 0 Maze.o 21811a9d6602c4f2
1 866 0 obj/DFS_L.o cb45386bcc5b2ef9
0 62 0 build.ninja 90fc65c1669b26eb
807 1497 0 obj/main.exe 617af850dcfb2210
795 1066 0 CMakeFiles/Maze.exe.dir/main.cpp.o 9903e8a1a3e1bb19
1311 1332 0 liball.a 16bb5e95d1489a20
2 871 0 obj/Maze.o fb62b64b2467359f
403 478 0 Maze.exe 48f07671ecb13c3a
3 556 0 CMakeFiles/maze.dir/DisjSets.cpp.o 9747980818295212
722 807 0 obj/liball.a d109a66475468c66
1 861 0 obj/DFS_R.o 41ca1c3369766373
1 711 0 CMakeFiles/maze.dir/DFS_R.cpp.o cabf687068f2e137
0 1186 0 DFS_L.o 886fadf236d05664
0 526 0 main.exe 6b2823bdaefd0c64
0 1217 0 DFS_R.o 5564c6baf4f5e652
372 403 0 libmaze.a da892c5201d372a
0 1279 0 A_star.o f5d1eae60f506e5
1 891 0 obj/DisjSets.o f4bef513a8a36b2a
1 1126 0 obj/DFS_R.o 41ca1c3369766373
1 1126 0 obj/DFS_L.o cb45386bcc5b2ef9
2 1148 0 obj/Maze.o fb62b64b2467359f
0 1148 0 obj/A_star.o aec7c9dae59f9632
0 1185 0 obj/Algorithm.o 5fef5b771d135e37
1185 1307 0 obj/liball.a d109a66475468c66
1307 2015 0 obj/main.exe 617af850dcfb2210
0 9 0 clean a48d12a494ad532f
1 639 0 obj/DisjSets.o f4bef513a8a36b2a
0 971 0 obj/DFS_L.o cb45386bcc5b2ef9
0 992 0 obj/DFS_R.o 41ca1c3369766373
2 1013 0 obj/Maze.o fb62b64b2467359f
0 1014 0 obj/A_star.o aec7c9dae59f9632
0 1083 0 obj/Algorithm.o 5fef5b771d135e37
1083 1140 0 obj/liball.a d109a66475468c66
1141 1859 0 obj/main.exe 617af850dcfb2210
@@ -2,15 +2,13 @@
#include "Maze.h"
#include <math.h>

int abs ( int v )
{
int abs (int v) {
if( v >= 0 )
return v;
else return -v;
}

A_star::A_star(Maze* maze,int x,int y):AlgorithmBase(maze,x,y)
{
A_star::A_star(Maze* maze,int x,int y):AlgorithmBase(maze,x,y) {
Di[0][0]=-1;Di[0][1]=0;
Di[1][0]=0;Di[1][1]=-1;
Di[2][0]=0;Di[2][1]=1;
@@ -74,5 +72,5 @@ const vector<int>& A_star::GetPath()//return the path from source to target
}
}
return m_path;

}

@@ -4,6 +4,7 @@
#include <queue>
using namespace std;


class A_star:public AlgorithmBase
{
class Node
@@ -1,4 +1,3 @@
#include "Algorithm.h"
#include "Maze.h"
#include <iostream>
#include <iomanip>
@@ -11,11 +10,13 @@ AlgorithmBase::AlgorithmBase(Maze* maze,int x,int y):m_pMaze(maze),personx(x),pe
fromy=y;
}

AlgorithmBase::~AlgorithmBase() {
}

void AlgorithmBase::MovePerson()
{
search();
m_pMaze->SetPerson(personx,persony);
search();
m_pMaze->SetPerson(personx,persony);

}

@@ -30,7 +31,7 @@ DFS::DFS(Maze* maze,int x,int y):AlgorithmBase(maze,x,y)
Di[1][0]=0;Di[1][1]=-1;
Di[2][0]=0;Di[2][1]=1;
Di[3][0]=1;Di[3][1]=0;
m_stack.push(Node(x,y));
m_stack.push(Node(x,y));
cout<<"DFS constructed"<<endl;
}

@@ -52,11 +53,11 @@ bool DFS::search()
m_stack.push(node);
m_pathmap[m_pMaze->Getid(nx,ny)]=m_pMaze->Getid(step.x,step.y);
}
}
}

personx=step.x;
persony=step.y;

}
return false;
}
@@ -118,7 +119,7 @@ bool BFS::search()
m_pMaze->SetCellVisited(nx,ny,true);
}
}

personx=step.x;
persony=step.y;
}
@@ -140,7 +141,7 @@ const vector<int>& BFS::GetPath()//return the path from source to target
}
}
return m_path;

}

void BFS::Draw()
@@ -11,78 +11,79 @@ using namespace std;
class Maze;

enum AlgorithmType{
none,
Dfs,
Bfs,
Left,//靠左走 直到没有路径 右转
Right,//靠右走 直到没有路径 左转
Astar//A* 算法
none,
Dfs,
Bfs,
Left,//靠左走 直到没有路径 右转
Right,//靠右走 直到没有路径 左转
Astar//A* 算法
};

class AlgorithmBase
{
protected:
class Node
{
public:
int x;
int y;
protected:
class Node
{
public:
int x;
int y;

Node(int x,int y):x(x),y(y)
{
}
bool operator==(const Node& node) const
{
return (node.x==x&&node.y==y);
}
};

Maze* m_pMaze;
vector<int> m_path;
int personx,persony;
int fromx;
int fromy;
Node(int x,int y):x(x),y(y)
{}

public:
AlgorithmBase(Maze*,int,int);
virtual bool search()=0;
virtual void Draw()=0;
void MovePerson();
const virtual vector<int>& GetPath();
bool operator==(const Node& node) const
{
return (node.x==x&&node.y==y);
}
};

Maze* m_pMaze;
vector<int> m_path;
int personx,persony;
int fromx;
int fromy;

public:
AlgorithmBase(Maze*, int, int);
virtual ~AlgorithmBase();
virtual bool search()=0;
virtual void Draw()=0;
void MovePerson();
const virtual vector<int>& GetPath();
};


class DFS:public AlgorithmBase
{
private:
stack<Node> m_stack;
bool search();
void Draw();
void ProcessPath(int id);
map<int,int> m_pathmap;
int Di[4][2];
public:
DFS(Maze*,int,int);
~DFS() {}
const virtual vector<int>& GetPath();
private:
stack<Node> m_stack;
bool search();
void Draw();
void ProcessPath(int id);
map<int,int> m_pathmap;
int Di[4][2];
public:
DFS(Maze*,int,int);
~DFS() {}
const virtual vector<int>& GetPath();

};

class BFS:public AlgorithmBase
{
private:
queue<Node> m_queue;
bool search();
void Draw();
void ProcessPath(int id);
map<int,int> m_pathmap;
int Di[4][2];
public:
BFS(Maze*,int,int);
~BFS() {}
const virtual vector<int>& GetPath();
private:
queue<Node> m_queue;
bool search();
void Draw();
void ProcessPath(int id);
map<int,int> m_pathmap;
int Di[4][2];

public:
BFS(Maze*,int,int);
~BFS() {}
const virtual vector<int>& GetPath();
};


#endif
@@ -7,7 +7,7 @@ DFS_L::DFS_L(Maze* maze,int x,int y):AlgorithmBase(maze,x,y)
Di[1][0]=1;Di[1][1]=0;
Di[2][0]=0;Di[2][1]=-1;
Di[3][0]=-1;Di[3][1]=0;
m_stack.push(Node(x,y));
m_stack.push(Node(x,y));
dir_now=0;
cout<<"DFS_L constructed"<<endl;
}
@@ -37,19 +37,19 @@ bool DFS_L::search()
while(1){
nx=personx+Di[dir_now][0];
ny=persony+Di[dir_now][1];

if(m_pMaze->IsValid(nx,ny)&&
m_pMaze->IsValidNextPath(personx,persony,nx,ny))
{
personx=nx;
persony=ny;
m_path.push_back(m_pMaze->Getid(nx,ny));

return true;
}
dir_now=(dir_now+1)%4;
}

}

const vector<int>& DFS_L::GetPath()
@@ -61,5 +61,3 @@ void DFS_L::Draw()
{
return;
}


@@ -7,7 +7,7 @@ DFS_R::DFS_R(Maze* maze,int x,int y):AlgorithmBase(maze,x,y)
Di[1][0]=1;Di[1][1]=0;
Di[2][0]=0;Di[2][1]=-1;
Di[3][0]=-1;Di[3][1]=0;
m_stack.push(Node(x,y));
m_stack.push(Node(x,y));
dir_now=0;
cout<<"DFS_R constructed"<<endl;
}
@@ -37,19 +37,19 @@ bool DFS_R::search()
while(1){
nx=personx+Di[dir_now][0];
ny=persony+Di[dir_now][1];

if(m_pMaze->IsValid(nx,ny)&&
m_pMaze->IsValidNextPath(personx,persony,nx,ny))
{
personx=nx;
persony=ny;
m_path.push_back(m_pMaze->Getid(nx,ny));

return true;
}
dir_now=Turn_AntiClock(dir_now);
}

}

const vector<int>& DFS_R::GetPath()
@@ -61,5 +61,3 @@ void DFS_R::Draw()
{
return;
}


@@ -12,7 +12,7 @@ Disjsets::Disjsets(int numElements):s(numElements)

void Disjsets::unionSets(int root1,int root2)
{

if( s[root2] < s[root1] )//root2 is deeper
s[root1] = root2; //make root2 new root
else
@@ -30,4 +30,3 @@ int Disjsets::find(int x) const
else
return find( s[x] );// find the x's root, return it
}

0 comments on commit 1c84982

Please sign in to comment.
You can’t perform that action at this time.