19,469
社区成员




BOOL CLLKDlg::IsLink(int x1,int y1,int x2,int y2)
{
if (chessdata[y1][x1]==0 && chessdata[y2][x2]==0)//判断两个点不是 没有东西的点
return FALSE;
if (x1=x2)
{
if (XLink(x1,y1,y2))
return TRUE;
}
else if (y1=y2)
{
if (YLink(x1,x2,y1))
return TRUE;
}
if(OneCornerLink(x1,y1,x2,y2))
{
return TRUE;
}
//两个转弯直角的联通方式
else if(TwoCornerLink(x1,y1,x2,y2))
{
return TRUE;
}
//else return FALSE;
return FALSE;
}
// 一条直线直连
BOOL CLLKDlg::XLink(int x,int y1,int y2)
{
if (y1>y2)
{
int y=y1;
y1=y2;
y2=y;
}
int sum=0;
for (int i=y1;i<(y2-y1);i++)
{
sum+=chessdata[i+1][x];
}
if (sum==0) //两点之间没有东西
{
return TRUE;
}
return FALSE;
}
//一条直线直连
BOOL CLLKDlg::YLink(int x1,int x2,int y)
{
if (x1>x2)
{
int x=x1;
x1=x2;
x2=x;
}
int sum=0;
for (int i=x1;i<(x2-x1);i++)
{
sum+=chessdata[y][i+i];
}
if (sum==0)
return TRUE;
return FALSE;
}
//有一个直角的连接
BOOL CLLKDlg::OneCornerLink(int x1,int y1,int x2,int y2)
{
if (x1>x2)
{
int x=x1;
x1=x2;
x2=x;
int y=y1;
y1=y2;
y2=y;
}
if (XLink(x1,y1,y2) && YLink(x1,x2,y2) && chessdata[y2][x1]==0)
return TRUE;
if (XLink(x2,y1,y2) && YLink(x1,x2,y1) && chessdata[y1][x2]==0)
return TRUE;
return FALSE;
}
有两个直角的连接
BOOL CLLKDlg::TwoCornerLink(int x1,int y1,int x2,int y2)
{
if (x1>x2)
{
int x=x1;
x1=x2;
x2=x;
int y=y1;
y1=y2;
y2=y;
}
for (int i=0;i<19;i++)
{
if (i<x1&& (!(i==x1&&i==x2)))
{
if (YLink(i,x1,y1) && OneCornerLink(i,y1,x2,y2) && chessdata[y1][i]==0)
return TRUE;
}
}
for (int i=0;i<11;i++)
{
if (i<y1&& (!(i==y1&&i==y2)))
{
if (XLink(x1,y1,y2) && OneCornerLink(x1,i,x2,y2) && chessdata[i][x1]==0)
return TRUE;
}
}
return FALSE;
}
#include "LLKDlg.h"
BOOL CLLKDlg::IsLink(int x1,int y1,int x2,int y2)
{
if ( x1==x2 && y1==y2)
{return false;}
else if (chessdata[y1][x1]==0 || chessdata[y2][x2]==0)
{return false;}
else if (chessdata[y1][x1]!=chessdata[y2][x2])
{
return false;
}
if (x1==x2 || y1==y2)
{
if (CheckLink(x1,y1,x2,y2))
{
return true;
}
}
if (OneCornerLink(x1,y1,x2,y2))
return true;
else if (TwoCornerLink(x1,y1,x2, y2))
return true;
return false;
}
BOOL CLLKDlg::CheckLink(int x1,int y1,int x2,int y2)
{
if (x1<0 || x1>18 || y1<0 || y1>10 || x2<0 || x2>18 || y2<0 || y2>10)
{
return false;
}
int x,y;
if (x1==x2)
{
if (y1>y2)
{
y=y1;
y1=y2;
y2=y;
}
if (y2-y1>1)
{
for (int i=(y1+1);i<y2;i++)
{
if (chessdata[i][x1]!=0)
{
return false;
}
}
}
else if (y2-y1==1)
{
return true;
}
else
{
return false;
}
}
else if (y1==y2)
{
if (x1>x2)
{
x=x1;
x1=x2;
x2=x;
}
if (x2-x1>1)
{
for (int i=(x1+1);i<x2;i++)
{
if (chessdata[y1][i]!=0)
{
return false;
}
}
}
else if (x2-x1==1)
{
return true;
}
else
{
return false;
}
}
return true;
}
BOOL CLLKDlg::OneCornerLink(int x1,int y1,int x2,int y2)
{
if (x1==x2 || y1==y2)
{
return false;
}
else if (x1>x2)
{
int x=x1;
x1=x2;
x2=x;
int y=y1;
y1=y2;
y2=y;
}
if (CheckLink(x1,y1,x1,y2) && CheckLink(x1,y2,x2,y2) && chessdata[y2][x1]==0 )
return true;
else if (CheckLink(x1,y1,x2,y1) && CheckLink(x2,y1,x2,y2) && chessdata[y1][x2]==0 )
return true;
return false;
}
BOOL CLLKDlg::TwoCornerLink(int x1,int y1,int x2,int y2)
{
for (int i=0;i<19;i++)
{
if (CheckLink(i,y1,i,y2)&&chessdata[y1][i]==0&&chessdata[y2][i]==0)
{
if (CheckLink(i,y1,x1,y1) && CheckLink(i,y2,x2,y2))
return true;
}
}
for (int i=0;i<11;i++)
{
if (CheckLink(x1,i,x2,i) && chessdata[i][x1]==0&& chessdata[i][x2]==0)
{
if (CheckLink(x1,i,x1,y1)&& CheckLink(x2,i,x2,y2))
return true;
}
}
return false;
}