forked from chenyukang/Maze
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFS_R.cpp
More file actions
63 lines (55 loc) · 1.2 KB
/
Copy pathDFS_R.cpp
File metadata and controls
63 lines (55 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "DFS_R.h"
#include "Maze.h"
DFS_R::DFS_R(Maze* maze,int x,int y):AlgorithmBase(maze,x,y)
{
Di[0][0]=0;Di[0][1]=1;
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));
dir_now=0;
cout<<"DFS_R constructed"<<endl;
}
int DFS_R::Turn_AntiClock(int now)
{
int re=now-1;
if(re>=0)
return re;
else return 3;
}
bool DFS_R::search()
{
int dir=(dir_now+1)%4;
int nx=personx+Di[dir][0];
int ny=persony+Di[dir][1];
if(m_pMaze->IsValid(nx,ny)&&
m_pMaze->IsValidNextPath(personx,persony,nx,ny))
{
dir_now=dir;
m_path.push_back(m_pMaze->Getid(nx,ny));
personx=nx;
persony=ny;
return true;
}
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()
{
return m_path;
}
void DFS_R::Draw()
{
return;
}