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

📄 setplay.cpp

📁 2002年
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	for(i=2;i<=SP_team_size;i++)
	{
		if (i==Agent::MyNumber||Executor==i||!MyPlayer(i).pos_valid()) continue;
		TheirOfPos = formation.GetOffensivePoint(FieldParam::FP_attackness[Idx(i)],FieldParam::FP_leftness[Idx(i)],ball.pos);
		playerline.LineFromTwoPoints(MyOfPos,TheirOfPos);
		if (playerline.InBetween(ball.pos,MyOfPos,TheirOfPos)||//该队员在球的另一侧
			ball.pos.dist(MyOfPos)<ball.pos.dist(TheirOfPos)) continue;
		balltrack.SetValues(ball.pos,(MyOfPos-ball.pos));
		if (fabs(balltrack.StrechAngle(TheirOfPos))>60) continue;
		res=false;
	}
	return res;
}

bool Newsetplay::ExecutorGo(){
	if (ball.kickable())
		return false;
	Vector Execpos=ball.pos+Polar2Vector(ClientParam::reliable_kickarea-ServerParam::ball_size,GetFaceAngle());
	bool success = Agent::motion.smartgoto(Execpos,ClientParam::setplay_speed);
	if (!success){
		float runspeed = ball.kickable() ? Execpos.dist(Self.pos)*(1 - ServerParam::player_decay):Execpos.dist(Self.pos);

		if (Execpos.dist(Self.pos)>0.1f || !ball.kickable())
		{
			if (fabs(NormalizeAngle((Execpos-Self.pos).Angle()-Self.bodyfacing))>15)
				Agent::motion.turn_to(Execpos);
			else
				Agent::motion.run(runspeed);
			return true;
		}
		else
		{
			DoLog(LOG_SETPLAY,"Already get ball");
			return false;
		}
	}
	else
		return true;
}

AngleDeg Newsetplay::GetFaceAngle(){
Vector pos0(Self.pos.x,0),pos1,pos2;
AngleDeg ang0 = 0,ang1,ang2;
float w0,w1,w2;
	if (Self.pos.y>0)
	{
		pos1 = Vector(Self.pos.x,ServerParam::pitch_width/4);
		ang1 = (PitchInfo.l_theirgoalpost-pos1).Angle();
		pos2 = Vector(Self.pos.x,ServerParam::pitch_width/2);
		ang2 = -90;
	}
	else{
		pos1 = Vector(Self.pos.x,-ServerParam::pitch_width/4);
		ang1 = (PitchInfo.r_theirgoalpost-pos1).Angle();
		pos2 = Vector(Self.pos.x,-ServerParam::pitch_width/2);
		ang2 = 90;
	}
	w0 =1.0f/( (pos0 - Self.pos).mod2()+0.01f);
    w1 =1.0f/( (pos1 - Self.pos).mod2()+0.01f);
    w2 =1.0f/( (pos2 - Self.pos).mod2()+0.01f);
    return (w0*ang0+w1*ang1+w2*ang2)/(w0+w1+w2);
}

void Newsetplay::Execute(){
	Command command;
	//move out
}


void Newsetplay::going(){
	UNum i;
	if (!ball.pos_valid())
		return;
	else
	{		
		switch (situation.SetPlayState) {
		case SPST_Initialize:
			Counter=0;
			for (i=1;i<=SP_team_size;i++)
				if (MyPlayer(i).pos_valid())
					Trackmark[i]=MyPlayer(i).pos;
				else 
					Trackmark[i]=Vector(ServerParam::pitch_length,ServerParam::pitch_width);
			for (i=1;i<=SP_team_size;i++)
				HeadingToBall[i]=1.0f;
			situation.ChangeSetPlay(SPST_Prego);
		case SPST_Prego:	
			
			Executor=JudgeExecutor();
			DoLog(LOG_SETPLAY,"Executor %d ball(%.0f,%.0f)", Executor, ball.pos.x, ball.pos.y);
			
			if (Executor==Agent::MyNumber)
			{
				if (!ExecutorGo())
				{
					situation.ChangeSetPlay(SPST_ExecWait);
					Counter = Max(2 * ClientParam::setplay_wait_time - (ServerParam::drop_ball_time + situation.ModeChangedTime - situation.CurrentTime),0);
				}
			}
			
			else
			{
				Agent::positioning.Position();
				if (situation.CurrentTime - situation.ModeChangedTime >6)
				{
					if (Player::IsMyPlayer(situation.ballcontroller)&&(situation.ballcontroller==Agent::MyNumber||
						MyPlayer(situation.ballcontroller).balldist<0.9*ball.distance)
						&&(situation.IsGoalieKick || FieldInfo.mygoalie != situation.ballcontroller))
					{
						situation.ChangeSetPlay(SPST_ExecWait);
						Counter = Max(2 * ClientParam::setplay_wait_time - (ServerParam::drop_ball_time + situation.ModeChangedTime - situation.CurrentTime),0);
					}
				}
			}
			
			break;
		case SPST_ExecWait:
		case SPST_Executing:
			
			my_error("On Execute %d",Executor);
			DoLog(LOG_SETPLAY,"On Execute %.0f",(float)Executor);
			if (Executor==Agent::MyNumber)
				Execute();			
			else
				Agent::positioning.Position();	
			break;
		case SPST_AfterExec:
			DoLog(LOG_SETPLAY,"(SP)Should Not get here!!");
			my_error("Should not get here!!");
			break;
		default:
			break;
		}
		Counter++;
		DoLog(LOG_SETPLAY,"(SP) Counter %d", Counter);
	}
}

GoalieSetPlay::GoalieSetPlay(){
	MovePoint[0]=Vector(-47,-15);
	MovePoint[1]=Vector(-47,15);
	MovePoint[2]=Vector(-40,-10);
	MovePoint[3]=Vector(-40,10);
	MovePoint[4]=Vector(-43.5,-15);
	MovePoint[5]=Vector(-43.5,15);
	movetime = -1;
}

float GoalieSetPlay::CalcAngle(Vector ATpos,Vector DFpos){
	/*以ATPOS点所面向的角度与守门员-球门张角之比
		作为危险度的估算量,符合
		1。守门员远离球门移动,函数单调增
		2。进攻队员远离球门移动,函数单调减
		3。守门员对进攻队员封堵角度越好,函数值越小
	*/
	AngleDeg dfangle=float(fabs(Ray(DFpos,(PitchInfo.l_mygoalpost-DFpos).Angle()).StrechAngle(PitchInfo.r_mygoalpost)));
	if (ATpos.dist(DFpos)<9) 
		ATpos=DFpos+Polar2Vector(9,(ATpos-DFpos).Angle());
	Ray lcourse(ATpos,(PitchInfo.l_mygoalpost-ATpos).Angle());
	Ray rcourse(ATpos,(PitchInfo.r_mygoalpost-ATpos).Angle());
	AngleDeg atangle1=float(fabs(lcourse.StrechAngle(DFpos)));
	AngleDeg atangle2=float(fabs(rcourse.StrechAngle(DFpos)));
	if (atangle1+atangle2>dfangle) return 1;
	else return (atangle1+atangle2)/dfangle;
}


float GoalieSetPlay::GetControl(int mynum,int oppnum)
{
	if (oppnum==0) return 1.0f;
	float factop,factmine;
	if (oppnum==1) factop=0.2f;
	else if (oppnum==2) factop=0.5f;
	else factop=0.8f;

	if (mynum==1) factmine=0.1f;
	else if (oppnum==2) factmine=0.3f;
	else factmine=0.4f;

	if (factmine>factop) return 1.0f;
	else
		return 1.0f+factmine-factop;

}

float GoalieSetPlay::CalcPoint(Vector pos){
	if (PitchInfo.my_goaltenderbox.IsWithin(pos))
		return 0;
	AngleDeg direction=NormalizeAngle((pos-PitchInfo.mygoal).Angle());
	int N_N_Teammates=FieldInfo.NumTeammatesInCone(pos,direction,15,150);
	int N_M_Teammates=FieldInfo.NumTeammatesInCone(pos,direction,30,150)-N_N_Teammates;
	int N_F_Teammates=FieldInfo.NumTeammatesInCone(pos,direction,40,150)-N_M_Teammates-N_N_Teammates;
	int N_N_Opponents=FieldInfo.NumOpponentsInCone(pos,direction,15,150);
	int N_M_Opponents=FieldInfo.NumOpponentsInCone(pos,direction,30,150)-N_N_Opponents;
	int N_F_Opponents=FieldInfo.NumOpponentsInCone(pos,direction,40,150)-N_M_Opponents-N_N_Opponents;
	return GetControl(N_N_Teammates,N_N_Opponents)*0.5f+GetControl(N_M_Teammates,N_M_Opponents)*0.3f
		+GetControl(N_F_Teammates,N_F_Opponents)*0.2f;
}

AngleDeg GoalieSetPlay::MyFaceAngle(Vector pos){
	return 0;
	AngleDeg res = NormalizeAngle((pos-PitchInfo.mygoal).Angle());
	if (res>45) res = 45;
	if (res<-45) res = -45;
	return res;
}

bool GoalieSetPlay::ShouldMove(){
	UNum j,bestpnt=0;
	float calcpr,movepr,nativepr;
	if (situation.SightTime <= movetime)
		return false;
	if (situation.playmode!=PM_My_Free_Kick||movecount == 0)
		return false;
	else
	{
		if (passpriority>0.7f) return false;
		if (!RecentSeen())
		return false;

		nativepr = CalcPoint(Self.pos);
		DoLog(LOG_SETPLAY,"(GSP)native (%f %f) calcvalue %f",Self.pos.x,Self.pos.y,nativepr);
		movepr=0.0f;
		for (j=0;j<CP_NumGoalieMovePoint;j++)
		{
			calcpr=CalcPoint(MovePoint[j]);
			DoLog(LOG_SETPLAY,"(GSP)point (%f %f) calcvalue %f",MovePoint[j].x,MovePoint[j].y,calcpr);
			if (movepr<calcpr)
			{	bestpnt=j;
				movepr=calcpr;
			}
		}

		if ((movecount==ServerParam::goalie_max_moves && movepr>1.1*nativepr || movepr>1.2*nativepr
			||deadtime>=ClientParam::setplay_wait_time-3)&&MovePoint[bestpnt].dist(Self.pos)>4)
		{
			DoLog(LOG_SETPLAY,"(GSP)Move %.0f to (%f %f) ",3.0f-movecount,MovePoint[bestpnt].x,MovePoint[bestpnt].y);
			Skill::action.move(MovePoint[bestpnt]);
//			Agent::motion.FaceTo(MyFaceAngle(MovePoint[bestpnt]));
			movetime = situation.CurrentTime;
			deadtime = Max(2 * ClientParam::setplay_wait_time - (ServerParam::drop_ball_time + situation.ModeChangedTime - situation.CurrentTime),0);
			movecount--;
			return true;
		}
		else
		{
//			if (FieldInfo.DirConf((MovePoint[bestpnt]-Self.pos).Angle())<0.8f&&RecentSeen())
//				Agent::mediator.enroll(PriorityA,(MovePoint[bestpnt]-Self.pos).Angle());
			return false;
		}
	}
}

bool GoalieSetPlay::CanKickOut(){
	if (situation.SetPlayState !=SPST_Executing && situation.CurrentTime - situation.ModeChangedTime < 6)
		return false;
	if (FieldInfo.Num_MyVisiblePlayers() > 0 && FieldInfo.MyPlayer_Close2Me(0).distance < 6.0f)
	{
		return false;
	}
	if (!(RecentSeen()||situation.IsSetPlayState(SPST_Executing))||(situation.SightTime <= movetime))
	{
		return false;
	}
	if ((Skill::action.cancatch(situation.CurrentTime) || situation.playmode == PM_My_Goal_Kick)&& passpriority > 0.2f)
		return true;
	else 
		return false;

}

bool GoalieSetPlay::KickOut(){		
	situation.ChangeSetPlay(SPST_Executing);
	return true;
}

 void GoalieSetPlay::going(){
	if (!ball.pos_valid())
		return;
	//moved out

}

⌨️ 快捷键说明

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