⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.cpp

📁 本程序是2005年参加中国机器人大赛的比赛程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			{
				if( this->Get_vPos().y<p.y )//在目标点左方
				{
					double t2=200;//经验值
					BasicAct(20,1,0, MAX_VELOCITY,t2);
					return t2;
				}
				else
				{
					double t2=200;//经验值
					BasicAct(20,1,0, MAX_VELOCITY,t2);
					return t2;
				}
			}
			else//运动到该点
			{
				if( fabs(this->Get_m_Angle()-rb.GetAngle())>15 )
				{
					TurnTo(p);
					return 100;
				}
				else 
				{
					double t3=rb.mod()*5;
					BasicAct(0,0,1,MAX_VELOCITY,t3);
					return t3;
				}
			}
	}
	else//在点的前面,先返回到与点并排的地方,再做正向处理,最后射门(运动到该点)
	{
		if( (  fabs( rb.GetAngle()-180 )<15  )&& ( fabs(this->Get_m_Angle())<15 ) )//射门条件
		{
			double t1=rb.mod()*6;//根据距离来确定时间
			BasicAct(0,0,1,MAX_VELOCITY,t1);
			return t1;
		}
		else
		{
			if ( (rb.mod()<10) && (fabs(this->Get_m_Angle())<45 ) )//正向处理条件
				{
					if( this->Get_vPos().y<p.y )//在目标点左方
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,1,0, MAX_VELOCITY,200);
						return t2;
					}
					else
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,0,0, MAX_VELOCITY,200);
						return t2;
					}
				}
				else//运动到该点
				{
					if( fabs(this->Get_m_Angle()-rb.GetAngle())>30 )
					{
						TurnTo(p);
						return 150;
					}
					else 
					{
						double t3=rb.mod()*5;
						BasicAct(0,0,1,MAX_VELOCITY,t3);
						return t3;
					}
				}
		}
	}
}
*/
/*
void Player::ShootPeterDeffense(Vector p)
{
	Vector rb=Vector(p.x-this->Get_vPos().x , p.y-this->Get_vPos().y);
	if( this->Get_vPos().x>p.x )//在点的后面,暂时不考虑,情况较简单
	{
		if ( (rb.mod()<10) && (fabs(this->Get_m_Angle())<90 ) )//正向处理条件
				{
					if( this->Get_vPos().y<p.y )//在目标点左方
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,1,0, MAX_VELOCITY,t2);
						return;
					}
					else
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,1,0, MAX_VELOCITY,t2);
						return;
					}
				}
				else//运动到该点
				{
					if( fabs(this->Get_m_Angle()-rb.GetAngle())>15 )
					{
						TurnTo(p);
						return;
					}
					else 
					{
						double t3=rb.mod()*5;
						BasicAct(0,0,1,MAX_VELOCITY,t3);
						return;
					}
				}
	}
	else//在点的前面,先返回到与点并排的地方,再做正向处理,最后射门(运动到该点)
	{
		if( (  fabs( rb.GetAngle()-180 )<15  )&& ( fabs(this->Get_m_Angle())<15 ) )//射门条件
		{
			double t1=rb.mod()*5;//根据距离来确定时间
			BasicAct(0,0,1,MAX_VELOCITY,t1);
			return;
		}
		else
		{
			if ( (rb.mod()<10) && (fabs(this->Get_m_Angle())<90 ) )//正向处理条件
				{
					if( this->Get_vPos().y<p.y )//在目标点左方
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,1,0, MAX_VELOCITY,t2);
						return;
					}
					else
					{
						double t2=200;//经验值100毫秒
						BasicAct(20,1,0, MAX_VELOCITY,t2);
						return;
					}
				}
				else//运动到该点
				{
					if( fabs(this->Get_m_Angle()-rb.GetAngle())>15 )
					{
						TurnTo(p);
						return;
					}
					else 
					{
						double t3=rb.mod()*5;
						BasicAct(0,0,1,MAX_VELOCITY,t3);
						return;
					}
				}
		}
	}
	return;
}
*/
/*
double  Player::DPosition(Vector dest)
{
	
//	BoundaryProc(CRect(100,100,100,100));
	Vector d=Vector(g_Ball.Get_vPos().x-this->Get_vPos().x, g_Ball.Get_vPos().y-this->Get_vPos().y);
	//if( (this->Get_vPos().x<50)||(this->Get_vPos().x>620)||(this->Get_vPos().y>470)||(this->Get_vPos().y<10))//如果车到了边界上则后退一段距离
//	{
//		this->BasicAct(0,0,1,-MAX_VELOCITY,200);
//		return 200;
//	}
	if( this->Get_vPos().x>g_Ball.Get_vPos().x )
	{
		Vector goal=Vector(g_Ball.Get_vPos().x,this->Get_vPos().y);
		if( ( fabs (fabs(d.GetAngle())-180)<20) ||	(fabs(d.mod())<20) )
		{
			if( this->Get_vPos().y<g_Ball.Get_vPos().y ) 
			{
				Vector des=Vector(this->Get_vPos().x,this->Get_vPos().y-30);
				MoveToNoOA(des);	
				return d.mod()*5;
			}
			if( this->Get_vPos().y>g_Ball.Get_vPos().y )
			{
				Vector des=Vector(this->Get_vPos().x,this->Get_vPos().y+30);
				MoveToNoOA(des);
				return d.mod()*5;
			}
		}
		if( fabs(fabs(d.GetAngle())-180)<20)
		{
			goal=Vector(g_Ball.Get_vPos().x, this->Get_vPos().y+30);
		}
		MoveToNoOA(goal);
		return 300;
	}
	if( fabs( fabs( this->Get_m_Angle())-180 )<15 )
	{
		if( this->Get_vPos().y<g_Ball.Get_vPos().y )
		{
			BasicAct(d.mod()/2, 1,0,d.mod()*10,d.mod()*6);
			return d.mod()*6;
		}
		else
		{
			BasicAct(d.mod()/2, 0,0,d.mod()*10,d.mod()*6);
			return d.mod()*6;
		}
	}
	if( fabs(this->Get_m_Angle()-d.GetAngle())>15 )
	{
		TurnTo(g_Ball.Get_vPos());
		return 150;
	}
	BasicAct(0,0,1,MAX_VELOCITY,d.mod()*6);
	return d.mod()*6;
}

*/
/*
void Player::DPosition2(Vector dest)//无时间控制的一种算法
{
	
//	BoundaryProc(CRect(100,100,100,100));
	Vector d=Vector(dest.x-this->Get_vPos().x, dest.y-this->Get_vPos().y);

	if( this->Get_vPos().x>g_Ball.Get_vPos().x )
	{
		Vector goal=Vector(g_Ball.Get_vPos().x,this->Get_vPos().y);
		if( ( fabs (fabs(d.GetAngle())-180)<20) ||	(fabs(d.mod())<20) )
		{
			if( this->Get_vPos().y<g_Ball.Get_vPos().y ) 
			{
				Vector des=Vector(this->Get_vPos().x,this->Get_vPos().y-30);
				MoveToNoOA2(des);	
				return ;
			}
			if( this->Get_vPos().y>g_Ball.Get_vPos().y )
			{
				Vector des=Vector(this->Get_vPos().x,this->Get_vPos().y+30);
				MoveToNoOA2(des);
				return ;
			}
		}
		if( fabs(fabs(d.GetAngle())-180)<30)
		{
			goal=Vector(g_Ball.Get_vPos().x, this->Get_vPos().y+30);
		}
		MoveToNoOA2(goal);
		return ;
	}
	if( fabs( fabs( this->Get_m_Angle())-180 )<30 )
	{
		if( this->Get_vPos().y<g_Ball.Get_vPos().y )
		{
			BasicAct(d.mod()/2, 1,0,d.mod()*10,0);
			return ;
		}
		else
		{
			BasicAct(d.mod()/2, 0,0,d.mod()*10,0);
			return ;
		}
	}
	if( fabs(this->Get_m_Angle()-d.GetAngle())>30 )
	{
		TurnTo(g_Ball.Get_vPos());
		return ;
	}
	BasicAct(0,0,1,8*MAX_VELOCITY/8,0);
	return;
}
*/
/*
BOOL Player::MoveToNoOA2(Vector destPos)//不停止的转角和直线运动
{
	Vector d=Vector(g_Ball.Get_vPos().x-this->Get_vPos().x, g_Ball.Get_vPos().y-this->Get_vPos().y);
	if( fabs(d.GetAngle()-this->Get_m_Angle())>30 )
	{
		TurnTo(g_Ball.Get_vPos());//转角需要考虑时间控制!!
		return 0;
	}
	BasicAct(0,0,1,6*MAX_VELOCITY/8,0);
	return 0;
}
*/
/*
BOOL Player::Turn(Vector dest)//无时间控制的转角
{

	Vector d=Vector(dest.x-this->Get_vPos().x, dest.y-this->Get_vPos().y);
	double delta=this->Get_m_Angle()-d.GetAngle();
	if( (delta>0 )&& (delta<90) )
		//机器人的朝向-机器人与球的连线,机器人在右边时向左转
	{
		this->BasicAct(d.mod(),0,0,MAX_VELOCITY,0);
		return 0;
	}
	if( (delta<0)&&(delta>-90) )//机器人在左边时
	{
		this->BasicAct(d.mod(),1,0,MAX_VELOCITY,0);
		return 0;
	}	
	BasicAct(0,0,0,-MAX_VELOCITY,0);

	return 0;
}
*/
void Player::InitDiffMatrix()
{
//	for(int i=0;i<128;i++)
//	{
		g_MyTeam[0].diff[127].delta_L=0;
		g_MyTeam[0].diff[127].delta_R=0;
	
//	}
}

void Player::SimpleAction(int n)
{
	switch(n)
	{
	case 0:		
		{
			Set_vL( 255*MAX_VELOCITY/255);//新机器人需要降速!!512
			Set_vR( 255*MAX_VELOCITY/255);
			SendCommand( 300 );			
			break;
		}
	case 1:	
		{
	
			Set_vL(255*MAX_VELOCITY/256);
			Set_vR(230*MAX_VELOCITY/256);
		//	Set_vR(190*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 2:	
		{
			Set_vL(255*MAX_VELOCITY/256);
			Set_vR(210*MAX_VELOCITY/256);
		//	Set_vR(190*MAX_VELOCITY/256);
			SendCommand( 300 );
		
			break;
		}
	case 3:	
		{
			Set_vL(255*MAX_VELOCITY/256);
			Set_vR(190*MAX_VELOCITY/256);
		//	Set_vR(170*MAX_VELOCITY/256);
			SendCommand( 300 );
		
			break;
		}
	case 4:	
		{
			Set_vL(-255*MAX_VELOCITY/256);
			Set_vR(-230*MAX_VELOCITY/256);
		//	Set_vR(-150*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 5:	
		{
			Set_vL(-255*MAX_VELOCITY/256);
			Set_vR(-210*MAX_VELOCITY/256);
		//	Set_vR(-200*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 6:	
		{
			Set_vL(-255*MAX_VELOCITY/256);
			Set_vR(-255*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 7:	
		{
		//	Set_vL(-180*MAX_VELOCITY/256);
			Set_vL(-230*MAX_VELOCITY/256);
			Set_vR(-255*MAX_VELOCITY/256);
			SendCommand( 300 );
		
			break;
		}
	case 8:	
		{
		//	Set_vL(-160*MAX_VELOCITY/256);
			Set_vL(-210*MAX_VELOCITY/256);
			Set_vR(-255*MAX_VELOCITY/256);
			SendCommand( 300 );
		
			break;
		}
	case 9:	
		{	
			Set_vL(-190*MAX_VELOCITY/256);
			Set_vR(-255*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 10:	
		{
			Set_vL(210*MAX_VELOCITY/256);
			Set_vR(255*MAX_VELOCITY/256);
			SendCommand( 300 );
	
			break;
		}
	case 11:	
		{
			Set_vL(230*MAX_VELOCITY/256);
			Set_vR(255*MAX_VELOCITY/256);
			SendCommand( 300 );
		
			break;
		}
	case 12:	//向左转一个角度
		{
			Set_vL(-255*MAX_VELOCITY/256);
			Set_vR(255*MAX_VELOCITY/256);
			SendCommand( 300 );
			break;
		}
	case 13:	//左转
		{
			Set_vL(-255*MAX_VELOCITY/256);
			Set_vR(255*MAX_VELOCITY/256);
			SendCommand( 300 );
			break;
		}
		case 14:	//右转
		{
			Set_vL(255*MAX_VELOCITY/256);
			Set_vR(-255*MAX_VELOCITY/256);
			SendCommand( 300 );
			break;
		}
		case 15:	//停止
		{
			this->BasicAct(0,0,0,0);
			break;
		}
		default:
			return;
	}
	return;
}

BOOL Player::HaveObstacle(Vector des)
{//所有的机器人都算做障碍,但是球没算
	for(int i=0; i<5; i++)
	{
		if( this->bIsHaveObstacle( g_MyTeam[i].Get_vPos(),des)==TRUE )
		{
			return TRUE;
		}
		if( this->bIsHaveObstacle(g_TheirTeam[i].Get_vPos(),des)==TRUE )
		{
			return TRUE;
		}
	}
	return FALSE;
}
/*
void Player::IntegrateAction()
{
//	g_MyTeam[0].TurnTo(g_MyTeam[0].destPos);
	

/*	g_MyTeam[1].TurnTo(g_MyTeam[1].destPos);
	g_MyTeam[2].TurnTo(g_MyTeam[2].destPos);
	g_MyTeam[3].TurnTo(g_MyTeam[3].destPos);
	g_MyTeam[4].TurnTo(g_MyTeam[4].destPos);
*/
//}	


BOOL Player::HaveObstacleBall(Vector des)
{
	for(int i=0; i<5; i++)
	{
		if( this->bIsHaveObstacle( g_MyTeam[i].Get_vPos(),des)==TRUE )
		{
			return TRUE;
		}
		if( this->bIsHaveObstacle(g_TheirTeam[i].Get_vPos(),des)==TRUE )
		{
			return TRUE;
		}
		if( this->bIsHaveObstacle(g_Ball.Get_vPos(), des)==TRUE)
		{
			return TRUE;
		}
	}
	return FALSE;
}


Vector Player::ChooseFP(Ball ball)//右前锋(右后卫)的点的选择
{	double dest[8];
	double value[8];
	if(ball.Get_vPos().y>MIDDLEPOINTY)//球在左方则在右选一点
	{
		for(int i=0; i<8; i++)
		{
			if(this->m_Num!=i)
			{
				dest[i]=MIDDLEPOINTY-(i+1)*LENGTH;
				Vector d=Vector(ball.Get_vPos().x,dest[i]);
				if(d.NearRobot()==TRUE)
				{
					value[i]=0;
				}
				else
				{
					value[i]=1;
				}
			}
			else
			{
				value[i]=1;
			}
		}
		for(i=0;i<8; i++)
		{
			if(value[i]==1)
			{
				if(ball.Get_vPos().x<DEFFENSEX)
				{
					return Vector(DEFFENSEX,dest[i]);
				}
				if(ball.Get_vPos().x>OPPONENTDIFFENSEX)
				{	
					return Vector(OPPONENTDIFFENSEX,dest[i]);
				}
				return Vector(ball.Get_vPos().x,dest[i]);
			}
		}
	}
	else//球在右方则直接追球
	{
		return ball.Get_vPos();
	}
	return Vector(0,0);
}

Vector Player::ChooseSP(Ball ball)
{//左前锋(左后卫的选点方法)
	//在球和自己一边的时候去尽力抢球,否则和球保持对应关系
	double dest[8];
	double value[8];
	if(ball.Get_vPos().y<MIDDLEPOINTY)
	{
		for(int i=0; i<8; i++)
		{
			if(this->m_Num!=i)
			{
				dest[i]=MIDDLEPOINTY+(i+1)*LENGTH;
				Vector d=Vector(ball.Get_vPos().x,dest[i]);
				if(d.NearRobot()==TRUE)
				{
					value[i]=0;
				}
				else
				{
					value[i]=1;
				}
			}
			else
			{
				value[i]=1;
			}
		}
		for(i=0;i<8; i++)
		{
			if(value[i]!=0)
			{
				if(ball.Get_vPos().x<DEFFENSEX)
				{
					return Vector(DEFFENSEX,dest[i]);
				}
				if(ball.Get_vPos().x>OPPONENTDIFFENSEX)
				{	
					return Vector(OPPONENTDIFFENSEX,dest[i]);
				}
				return Vector(ball.Get_vPos().x,dest[i]);
			}
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -