sp; printf("\e[1;31m%02d\e[0m ",map[x][y]);
else
printf("%02d ",map[x][y]);
}
printf("\n");
}
}
//-------------------------search path--------------------
//检查直接连接,返回成功或者失败
bool havePathCorner0(_point p1,_point p2){
if (p1.x != p2.x && p1.y != p2.y)
return FALSE; // not in the same line
int min,max;
if (p1.x == p2.x){
min = p1.y < p2.y ? p1.y : p2.y;
max = p1.y > p2.y ? p1.y : p2.y;
for(min++;min < max;min++){
if(map[p1.x][min] != empty)
return FALSE; //have block false
}
} else {
min = p1.x < p2.x ? p1.x : p2.x;
max = p1.x > p2.x ? p1.x : p2.x;
for(min++;min < max;min++){
if(map[min][p1.y] != empty)
return FALSE; //have block false
}
}
return TRUE;
}
//检查1折连接,返回1个点,
//如果点的坐标为负表示不存在1折连接
_point havePathCorner1(_point p1,_point p2){
_point nullPoint;
nullPoint.x=nullPoint.y=-1;
if (p1.x == p2.x || p1.y == p2.y)
return nullPoint;
_point c1,c2;
c1.x=p1.x;
c1.y=p2.y;
c2.x=p2.x;
c2.y=p1.y;
if (map[c1.x][c1.y] == empty){
bool b1=havePathCorner0(p1,c1);
bool b2=havePathCorner0(c1,p2);
if (b1 && b2)
return c1;
}
if (map[c2.x][c2.y] == empty){
bool b1=havePathCorner0(p1,c2);
bool b2=havePathCorner0(c2,p2);
if (b1 && b2)
return c2;
}
return nullPoint;
}
//检查两折连接,返回两个点,
//返回点坐标为负表示不存在两折连接
//其中使用了4个方向的循环查找
_point result[2];
_point *havePathCorner2(_point p1,_point p2){
int i;
_point *r=result;
//search direction 1
for(i=p1.y+1;i<_height;i++){
if (map[p1.x][i] == empty){
_point c1;
c1.x=p1.x;
c1.y=i;
_point d1=havePathCorner1(c1,p2);
if (d1.x != -1){
r[0].x=c1.x;
r[0].y=c1.y;
r[1].x=d1.x;
r[1].y=d1.y;
return r;
}