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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
void gogo(vector<vector<int> > &maze, int p, int q){
int ways=0, go;
srand(time(NULL));
go=rand()%4;
maze[p][q]=3;
if(maze[p-1][q]==0||maze[p-1][q]>=201){
ways++;
}
if(maze[p+1][q]==0||maze[p+1][q]>=201){
ways++;
}
if(maze[p][q-1]==0||maze[p][q-1]>=201){
ways++;
}
if(maze[p][q+1]==0||maze[p][q+1]>=201){
ways++;
}
if(ways>=2){
r=p;
k=q;
}
else if(ways<=1){
r=r;
k=k;
}
//system("pause");
//////////////////////////////////
if(go==0&&(maze[p-1][q]==0||maze[p-1][q]>=201)){
maze[p-1][q]==3;
printrealmaze(maze);
gogo(maze,p-1,q);
}
if(go==1&&(maze[p+1][q]==0||maze[p+1][q]>=201)){
maze[p+1][q]=3;
printrealmaze(maze);
gogo(maze,p+1,q);
}
if(go==2&&(maze[p][q+1]==0||maze[p][q+1]>=201)){
maze[p][q+1]=3;
printrealmaze(maze);
gogo(maze,p,q+1);
}
if(go==3&&(maze[p][q-1]==0||maze[p][q-1]>=201)){
maze[p][q-1]=3;
printrealmaze(maze);
gogo(maze,p,q-1);
}
////////////////////////////////
if(go==0&&maze[p-1][q]!=0&&maze[p-1][q]<200&&ways!=0){
gogo(maze,p,q);
}
else if(go==1&&maze[p+1][q]!=0&&maze[p+1][q]<200&&ways!=0){
gogo(maze,p,q);
}
else if(go==2&&maze[p][q+1]!=0&&maze[p][q+1]<200&&ways!=0){
gogo(maze,p,q);
}
else if(go==3&&maze[p][q-1]!=0&&maze[p][q-1]<200&&ways!=0){
gogo(maze,p,q);
}
///////////////////////////////////
else if(ways==0&&(p!=-3+maze[0].size()&&q!=-3+maze.size())){//
p=r;
q=k;
gogo(maze,p,q);
}
cout<<"GG"<<endl;
exit(1);
}
|