哪出了问题 《连连看》判断两点是否可以连接

bingouqd 2009-08-09 12:37:36


不知哪出了问题 大家看看 望大家指正








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;
}
...全文
546 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
晒月光的青蛙 2009-08-12
  • 打赏
  • 举报
回复
这项目挺锻炼人的
bingouqd 2009-08-12
  • 打赏
  • 举报
回复

谢谢大家 想了好几天尽于写出来啦 全部通过。。贴出来和大分享。。



#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;
}
LPR_Pro 2009-08-10
  • 打赏
  • 举报
回复
for (int i=0;i<19;i++)
{
if (i<x1&& (!(i==x1&&i==x2))) /* 这个地方,i>x1的情况也需要做处理吧。否则只处理了左边两个直角连接的情况。 */
{
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))) /* i>y1的情形也需要做处理,否则只处理了上边两个直角连接的情况 */
{
if (XLink(x1,y1,y2) && OneCornerLink(x1,i,x2,y2) && chessdata[i][x1]==0)
return TRUE;
}
}
DarkChampion 2009-08-09
  • 打赏
  • 举报
回复
lz把问题描述得更详细一点,大家帮你看
MoXiaoRab 2009-08-09
  • 打赏
  • 举报
回复
这问题,叫人没法回答。
连个背景,设计框架,思路和错误信息都没有

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧