//球心计算 递归算法
//球矩的计算更为准确
//dm是向左运动的点数,逐渐递增
int BCentMakeLeft(int x,int y1,int y2,int dm)
{
char str[10234];
sprintf(str,"BCentMakeLeft:x %d,y[%d,%d]%d \r\n",x,y1,y2,dm);
UPDATEStates(DEBUG_BCENTMAKE,str);
if(dm>DD)
return dm;
if(y1>y2)
return dm;
//计算y的范围缩
int y;
//y内缩
int ynear;
int nearLen=999;
int n=0;
for(y=y1;y<=y2;y++)
if(CRisballtypeS(x,y))
{
UPDATEStates(DEBUG_BCENTMAKE,"内缩..\r\n");
n=1;
if(abs(y-(y1+y2)/2)<nearLen)
{
nearLen=abs(y-(y1+y2)/2);
ynear=y;
}
//break;
}
//选出的离中间最近的有效点
y=ynear;
//内缩失败,此时已经到边缘了
if(n==0)
return dm;
//内缩终于找到一个有效的点
y1=y;
y2=y;
//y外扩
n=0;
while(CRisballtypeS(x,y1))
{
UPDATEStates(DEBUG_BCENTMAKE,"上扩..\r\n");
n++;
y1--;
if(n>DD)
break;
}
if(n)
y1++;
n=0;
while(CRisballtypeS(x,y2))
{
UPDATEStates(DEBUG_BCENTMAKE,"下扩..\r\n");
n++;
y2++;
if(n>DD)
break;
}
if(n)
y2--;
//至此找到y的范围
//向左递推
return BCentMakeLeft(x-1,y1,y2,dm+1);
}
示例:
QQ桌球瞄准器 智能QQ2D桌球瞄准器 QQ2D桌球瞄准器 智能QQ桌球瞄准器