📄 mazeanaly.h
字号:
#include "head.h"
int crossNum(int graph[CONST_MAZEX][CONST_MAZEY],int,int);
int mazeAnaly(int graph[CONST_MAZEX][CONST_MAZEY],int,int,int,int,int,int &);
int crossNum(int graph[CONST_MAZEX][CONST_MAZEY],int x,int y)
{
int num=0;
if(graph[x-1][y]==0)
num++;
if(graph[x+1][y]==0)
num++;
if(graph[x][y-1]==0)
num++;
if(graph[x][y+1]==0)
num++;
return num;
}
int mazeAnaly(int graph[CONST_MAZEX][CONST_MAZEY],int currX,int currY,
int lastX,int lastY,int height,int &tempMax)
{
// first time call this function the height is initialed as 1
int tempX,tempY;
int bifurcate=0;
int sonMax[4]={0};
if(crossNum(graph,currX,currY)<3 || graph[currX][currY]==1)
height--;
tempMax=height;
if(graph[currX][currY]==1)
return -1;
if(currX>SIZEX_MAZE-1 || currX<0 || currY>SIZEY_MAZE || currY<0)
return -1;
for(int num=0;num<4;num++)
{
tempX=currX;
tempY=currY;
if(num==0)
if(currX!=lastX+1 || currY!=lastY)//go upwards
tempX=currX-1;
else
continue;
else if(num==1 )
if(currX!=lastX || currY!=lastY-1) //go rightwards
tempY=currY+1;
else
continue;
else if(num==2 )
if(currX!=lastX-1 || currY!=lastY) //go downwards
tempX=currX+1;
else
continue;
else if(num==3)
if(currX!=lastX || currY!=lastY+1) //go leftwards
tempY=currY-1;
else
continue;
if(mazeAnaly(graph,tempX,tempY,currX,currY,height+1,sonMax[num])!=-1)
bifurcate++;
}
if(bifurcate>1) //it is an bifurcate at least
{
totalEdge=totalEdge+bifurcate;
int max=sonMax[0];
int secondMax=sonMax[0];
int temp=0;
for(int k=1;k<4;k++)
{
if(sonMax[k]>max)
{
max=sonMax[k];
temp=k;
}
}
if(temp==0)
secondMax=sonMax[1];
for(k=0;k<4;k++)
{
if(k==temp)
continue;
if(sonMax[k]>secondMax)
secondMax=sonMax[k];
}
imbalance=imbalance+max-secondMax;
tempMax=max;
}
else if(bifurcate==0)
{
if(height>treeHeight)
treeHeight=height;
totalLevel+=height;
::levelNum++;
}
else
{
tempMax=sonMax[0];
for(int k=1;k<4;k++)
if(sonMax[k]>tempMax)
tempMax=sonMax[k];
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -