background image

/* 找到两个 CELL 之间的路径,成功返回 true */
int FindPath(CELL *c1,CELL *c2)
{
    int i,j,path,min1,max1,min2,max2,left,right,top,bottom;
    /*---------------(0

 

)判断是否点中相同块! ------------*/

    if(Board[c1->x][c1->y][1] != Board[c2->x][c2->y][1])
        return false;
    /*---------------(1)查找水平方向公共区域!-----------*/
    min1=max1=c1->x;
    min2=max2=c2->x;
    while(min1-1>=0 && Board[min1-1][c1->y][0]==0) min1--;
    while(min2-1>=0 && Board[min2-1][c2->y][0]==0) min2--;
    left=max(min1,min2);    /* 

 

左边界 */

    while(max1+1<BoardWidth && Board[max1+1][c1->y][0]==0) max1++;
    while(max2+1<BoardWidth && Board[max2+1][c2->y][0]==0) max2++;
    right=min(max1,max2); /* 

 

右边界 */

    /* 检查两条水平线之间是否有公垂线连通!*/
    /* 

 

可以在边缘连通 */

    if(left==0)
    {
        /* 

 

左边缘连通 */

        DrawPath(c1->x,c1->y,  -1,c1->y,  -1,c2->y,  c2->x,c2->y, LineColor);
        delay(6000);
        DrawPath(c1->x,c1->y,  -1,c1->y,  -1,c2->y,  c2->x,c2->y, BkGndColor);/*
插除线条!*/
        return true;
    }
    if(right==(BoardWidth-1))
    {
                DrawPath(c1->x,c1->y,    BoardWidth,c1->y,    BoardWidth,c2->y,    c2-
>x,c2->y, LineColor);
        delay(6000);
                DrawPath(c1->x,c1->y,    BoardWidth,c1->y,    BoardWidth,c2->y,    c2-
>x,c2->y, BkGndColor);/*插除线条!*/
        return true;
    }

    for(i=left;i<=right;i++)
    {
        path=0;/*统计垂直的公垂线长度!*/
        for(j=min(c1->y,c2->y)+1;j<max(c1->y,c2->y);j++)
        {