示例#1
0
// 连接提示
bool CLogic::LinkPrompt(BYTE  chess[CHESSCOUNT_H][CHESSCOUNT_W], CPoint * first, CPoint * end)
{
	CPoint t1,t2;
	CArrayTemplate<CPoint> v;

	for(int i=0; i<CHESSCOUNT_H; i++)
	{
		for(int j=0; j<CHESSCOUNT_W; j++)
		{
			for(int _i=0; _i<CHESSCOUNT_H; _i++)
			{
				for(int _j=0; _j<CHESSCOUNT_W; _j++)
				{
					if(i!=_i || j!=_j)
					{
						v.RemoveAll();
						if(chess[i][j]!= ERROR_ALL && chess[i][j] == chess[_i][_j] && IsLink(chess,CPoint(j,i),CPoint(_j,_i),&v,&t1,&t2))
						{
							first->x = j; first->y = i;
							end->x = _j; end->y = _i;
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}
示例#2
0
// 寻找符合条件的最短路径
void CLogic::ShortPath(BYTE  chess[CHESSCOUNT_H][CHESSCOUNT_W],CArrayTemplate<CPoint> * r, CPoint one , CPoint two, CPoint* ipoint)
{
	CArrayTemplate<CPoint> t;
	CPoint hotpoint;
	bool blog = true;


	if( one.x !=two.x)
	{
		for(int i= one.x,j=one.y; i!=two.x; one.x<two.x?i++:i--)
		{
			if(i!=one.x && chess[j][i]!=ERROR_ALL)
			{
				blog = false;
				break;
			}
			else
			{
				t.InsertAt(t.GetCount(),CPoint(i,j));
			}
		}
	}
	if(one.y != two.y)
	{
		hotpoint.x = two.x;
		hotpoint.y = one.y;
		for(int i=two.x,j = one.y;j!=two.y; one.y<two.y ? j++:j--)
		{
			if(chess[j][i]!=ERROR_ALL)
			{
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}
	if(blog)
	{
		for(int i=0; i<t.GetCount(); ++i)
		{
			r->InsertAt(r->GetCount(),CPoint(t.ElementAt(i).x,t.ElementAt(i).y));
			if(ipoint!=NULL)
			{
				ipoint->x = hotpoint.x;
				ipoint->y = hotpoint.y;
			}
		}
		return;
	}
	else
	{
		t.RemoveAll();
		hotpoint.x = ERROR_ALL;
		hotpoint.y = ERROR_ALL;
		blog = true;
	}

	if(one.y != two.y)
	{
		for(int i=one.x,j = one.y;j!= two.y; one.y<two.y ? j++:j--)
		{
			if(j!= one.y&&chess[j][i]!=ERROR_ALL)
			{
				t.RemoveAll();
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}
	if(one.x != two.x)
	{
		hotpoint.x = one.x;
		hotpoint.y = two.y;
		for(int i= one.x,j=two.y; i!=two.x; one.x<two.x?i++:i--)
		{
			if(chess[j][i]!=ERROR_ALL)
			{
				t.RemoveAll();
				blog = false;
				break;
			}
			else
				{
					t.InsertAt(t.GetCount(),CPoint(i,j));
				}
		}
	}

	if(blog)
	{
		for(int i=0; i<t.GetCount(); ++i)
		{
			r->InsertAt(r->GetCount(),CPoint(t.ElementAt(i).x,t.ElementAt(i).y));
			if(ipoint!=NULL)
			{
				ipoint->x = hotpoint.x;
				ipoint->y = hotpoint.y;
			}
		}
		return;
	}
	return;
}