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

📄 playerteams.cpp

📁 浙江大学中控杯仿真组机器人源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp )
			== WM->getAgentObjectType()  && !WM->isDeadBallThem() )
		{                                                // if fastest to ball
			Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp );
			soc = intercept( false );                      // intercept the ball
			
			if( soc.commandType == CMD_DASH &&             // if stamina low
				WM->getAgentStamina().getStamina() <
				SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
			{
				soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
				ACT->putCommandInQueue( soc );
			}
			else                                           // if stamina high
			{
				ACT->putCommandInQueue( soc );               // dash as intended
			}
		}
		// 如果以上条件都不满足(球不可踢,我也不是我方能最快截到球的)
		// 且我离我的阵型位置太远了,我就跑到我的阵型位置
		else if( posAgent.getDistanceTo(WM->getStrategicPosition()) >
			1.5 + fabs(posAgent.getX()-posBall.getX())/10.0)
			// if not near strategic pos
		{
			if( WM->getAgentStamina().getStamina() >     // if stamina high
				SS->getRecoverDecThr()*SS->getStaminaMax()+800 )
			{
				soc = moveToPos(WM->getStrategicPosition(),
					PS->getPlayerWhenToTurnAngle());
				ACT->putCommandInQueue( soc );            // move to strategic pos
			}
			else                                        // else watch ball
			{
				ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
			}
		}
		// 如果我离阵型位置很近,我就把身体转向足球,对着球看
		else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball
		{
			ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
		}
		else                                         // nothing to do
			;
	}
	// 一个最简单的视觉: 对着球看
	//
	cmdTurnNeck = turnNeckToObject(OBJECT_BALL, soc);
	ACT->putCommandInQueue(cmdTurnNeck);
	//------------------------------------------------
	return soc;
}

/*!This method is a simple goalie based on the goalie of the simple Team of
   FC Portugal. It defines a rectangle in its penalty area and moves to the
   position on this rectangle where the ball intersects if you make a line
   between the ball position and the center of the goal. If the ball can
   be intercepted in the own penalty area the ball is intercepted and catched.
*/
SoccerCommand Player::deMeer5_goalie(  )
{
	// 首先,把改变视觉模式命令放入队列中
	// 这两行不需要修改
	//
	SoccerCommand cmdChangeView = g_viewAngle.getCommandChangeViewType();
	ACT->putCommandInQueue(cmdChangeView);
	//-------------------------------------------------------------------------

	int i;
	SoccerCommand soc;
	SoccerCommand cmdTurnNeck;  // lm 06.10.11
	VecPosition   posAgent = WM->getAgentGlobalPosition();
	AngDeg        angBody  = WM->getAgentGlobalBodyAngle();
	
	// define the top and bottom position of a rectangle in which keeper moves
	static const VecPosition posLeftTop( -PITCH_LENGTH/2.0 +
		0.7*PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/4.0 );
	static const VecPosition posRightTop( -PITCH_LENGTH/2.0 +
		0.7*PENALTY_AREA_LENGTH, +PENALTY_AREA_WIDTH/4.0 );
	
	// define the borders of this rectangle using the two points.
	static Line  lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop);
	static Line  lineLeft  = Line::makeLineFromTwoPoints(
		VecPosition( -50.0, posLeftTop.getY()), posLeftTop );
	static Line  lineRight = Line::makeLineFromTwoPoints(
		VecPosition( -50.0, posRightTop.getY()),posRightTop );
	
	
	if( WM->isBeforeKickOff( ) )
	{
		if( posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
		{
			ACT->putCommandInQueue( soc=teleportToPos(WM->getStrategicPosition()) );
		}
		else                                            // else turn to center
		{
			ACT->putCommandInQueue( soc = turnBodyToPoint( VecPosition( 0, 0 ), 0 ));
		}
		return soc;
	}
	
	if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
	{                                                // confidence ball too  low
		ACT->putCommandInQueue( searchBall() );        // search ball
	}
	else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() ||
		WM->isCornerKickThem() )               
	{
		if( WM->isBallCatchable() )
		{
			ACT->putCommandInQueue( soc = catchBall() );
		}
		else if( WM->isBallKickable() )
		{
			soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
			ACT->putCommandInQueue( soc );
		}
		else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) &&
			WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) == 
			WM->getAgentObjectType() )
		{
			ACT->putCommandInQueue( soc = intercept( true ) );
		}
		else
		{
			// make line between own goal and the ball
			VecPosition posMyGoal = ( WM->getSide() == SIDE_LEFT )
				? SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_L, SIDE_LEFT )
				: SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_R, SIDE_RIGHT);
			Line lineBall = Line::makeLineFromTwoPoints( WM->getBallPos(),posMyGoal);
			
			// determine where your front line intersects with the line from ball
			VecPosition posIntersect = lineFront.getIntersection( lineBall );
			
			// outside rectangle, use line at side to get intersection
			if (posIntersect.isRightOf( posRightTop ) )
				posIntersect = lineRight.getIntersection( lineBall );
			else if (posIntersect.isLeftOf( posLeftTop )  )
				posIntersect = lineLeft.getIntersection( lineBall );
			
			if( posIntersect.getX() < -49.0 )
				posIntersect.setX( -49.0 );
			
			// and move to this position
			if( posIntersect.getDistanceTo( WM->getAgentGlobalPosition() ) > 0.5 )
			{
				soc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() );
				ACT->putCommandInQueue( soc );
			}
			else
			{
				ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
			}
		}
	}
	else if( WM->isFreeKickUs() == true || WM->isGoalKickUs() == true )
	{
		if( WM->isBallKickable() )
		{
			if( WM->getTimeSinceLastCatch() == 25 && WM->isFreeKickUs() )
			{
				// move to position with lesser opponents.
				if( WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
					Circle(posRightTop, 15.0 )) <
					WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
					Circle(posLeftTop,  15.0 )) )
					soc.makeCommand( CMD_MOVE,posRightTop.getX(),posRightTop.getY(),0.0);
				else
					soc.makeCommand( CMD_MOVE,posLeftTop.getX(), posLeftTop.getY(), 0.0);
				ACT->putCommandInQueue( soc );
			}
			else if( WM->getTimeSinceLastCatch() > 28 )
			{
				soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
				ACT->putCommandInQueue( soc );
			}
			else if( WM->getTimeSinceLastCatch() < 25 )
			{
				VecPosition posSide( 0.0, posAgent.getY() ); 
				if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 )
				{
					soc = turnBodyToPoint( posSide );
					ACT->putCommandInQueue( soc );
				}
			}
		}
		else if( WM->isGoalKickUs()  )
		{
			ACT->putCommandInQueue( soc = intercept( true ) );
		}
		else	//nothing to do
			;
	}
	else
	{
		ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
	}

	// 一个最简单的视觉: 对着球看
	// lm 06.10.11-------------------------------------
	cmdTurnNeck = turnNeckToObject(OBJECT_BALL, soc);
	ACT->putCommandInQueue(cmdTurnNeck);  // lm 06.10.11
	//------------------------------------------------	
	return soc;
}

void Player::sayPassAdvice()
{
	double dist;
	ObjectT ballController = WM->getClosestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL, &dist);
	if (ballController != OBJECT_ILLEGAL && ballController != WM->getAgentObjectType() &&
		dist < WM->getMaximalKickDist(ballController)+0.5 &&
		g_agentPos.getX() < WM->getOffsideX()-0.5)
	{
		double ang = (g_agentPos - WM->getGlobalPosition(ballController)).getDirection();
		if (fabs(ang)>120)
			return;
		for (double speed = 2.7-0.1; speed>=1.5; speed-=0.2)
		{
			VecPosition vel(speed, ang, POLAR);

			int opp = WM->predictFastestOppInterCyc(g_ballPos, vel);
			int our = WM->predictInterCyc(WM->getAgentObjectType(), g_ballPos, vel);

			if (our<opp)
			{
				//cout<<"our("<<our<<"), opp("<<opp<<"), pass "<<vel<<endl;
				coms.SayPassAdv(vel);
				return;
			}
		}		
	}	
}

⌨️ 快捷键说明

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