예제 #1
0
// 重新排列
void CLogic::Realign(BYTE  chess[CHESSCOUNT_H][CHESSCOUNT_W])
{
	CArrayTemplate<CPoint> pos;
	CArrayTemplate<BYTE> data;
	int temp,temp2;

	for(int i=0; i<CHESSCOUNT_H; i++)
	for(int j=0; j<CHESSCOUNT_W; j++)
	{
		if(chess[i][j] != ERROR_ALL)
		{
			pos.InsertAt(pos.GetCount(),CPoint(i,j));
			data.InsertAt(data.GetCount(),chess[i][j]);
		}
		chess[i][j] = ERROR_ALL;
	}
	srand((unsigned int)time(NULL));
	for(; pos.GetCount()>0;)
	{
		temp = rand()%((int)pos.GetCount());
		temp2 = rand()%((int)data.GetCount());
		chess[pos.ElementAt(temp).x][pos.ElementAt(temp).y] = data[temp2];
		pos.RemoveAt(temp);
		data.RemoveAt(temp2);
	}
}
예제 #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;
}