Пример #1
0
AngleDeg PositionInfo::GetShootAngle(AngleDeg left,AngleDeg right, const PlayerState & state , AngleDeg & interval)
{
	vector< pair<Unum, AngleDeg> > tmp;
	for (vector<PlayerState*>::const_iterator it = mpWorldState->GetPlayerList().begin(); it != mpWorldState->GetPlayerList().end(); ++it){
    if ((*it)->IsAlive() && (*it)->GetPosConf() > FLOAT_EPS && (*it)->GetUnum() != state.GetUnum() &&((*it)->GetPos()-state.GetPos()).Dir() + Rad2Deg(1/10) >left&&((*it)->GetPos()-state.GetPos()).Dir() - Rad2Deg(1/10) <right){//介于左右门柱之间
		tmp.push_back(pair<Unum, AngleDeg>((*it)->GetUnum(), ((*it)->GetPos()-state.GetPos()).Dir()));
	}
	}
	if(tmp.size()!=0){
		sort(tmp.begin(),tmp.end(),PlayerDirCompare());
			vector<pair<int,AngleDeg> > dis;
			int i=0;
	vector<pair<int,AngleDeg> >::const_iterator it;
	for(it = tmp.begin(); it != tmp.end();++it){
			if(i==0){
				dis.push_back(pair<int,AngleDeg>(i++,((*it).second-left/* - Rad2Deg(1/10) - Rad2Deg(1/3)*/)));
				}
			else{
				dis.push_back(pair<int,AngleDeg>(i++,((*it).second-(*(it-1)).second)/*- 2*Rad2Deg(1/10) - Rad2Deg(1/3)*/));
			}
			}
				dis.push_back(pair<int,AngleDeg>(i,(right-(*(it-1)).second)/*- Rad2Deg(1/10) - Rad2Deg(1/3)*/));
		sort(dis.begin(),dis.end(),PlayerDirCompare());

		if(dis.back().first==0){
			interval = dis.back().second-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0);
			return MinMax(left + 1,dis.back().second/2+left-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0),right -1 );
		}
		else if(dis.back().first == i){
			interval = dis.back().second-Rad2Deg(1.0/10.0)-Rad2Deg(1.0/4.0);
			return MinMax(left + 1,right -dis.back().second/2+Rad2Deg(1.0/10.0)+Rad2Deg(1.0/4.0),right -1);
		}
		else{
			interval = dis.back().second  - 2* Rad2Deg(1.0/10.0) - Rad2Deg(1.0/4.0);
			return MinMax(left +1,(*(tmp.begin()+dis.back().first-1)).second + dis.back().second/2 ,right -1);
		}
	}
	else {
		interval = right-left  ;
		return (left+right)/2;
	}
}
Пример #2
0
bool Tackler::MayDangerousIfTackle(const PlayerState & tackler, const WorldState & world_state)
{
	if (tackler.GetTackleProb(false) < FLOAT_EPS && tackler.GetTackleProb(true) < FLOAT_EPS) { //不可铲
		return false;
	}

	const Vector tackler_pos = tackler.GetPos();
	const Vector ball_pos = world_state.GetBall().GetPos();
	const Vector ball_2_tackler = ball_pos - tackler_pos;
	const double ball_dist2 = ball_2_tackler.Mod2();
	const AngleDeg ball_dir = ball_2_tackler.Dir();

	for (unsigned i = 0; i < world_state.GetPlayerList().size(); ++i) {
		const PlayerState & opp = *world_state.GetPlayerList()[i];

		if (!opp.IsAlive()) continue; //dead
		if (opp.GetUnum() * tackler.GetUnum() > 0) continue; //not opp
		if (opp.IsIdling()) continue; //idling
		if (!opp.IsKickable()) continue; //not kickable

		//cond. 1. opp no dashing -- 无从知晓,这里认为对手一定会dash
		//cond. 2. ball near -- 球离自己更近,不构成危险情况
		Vector opp_2_tackler = opp.GetPos() - tackler_pos;
		if (opp_2_tackler.Mod2() > ball_dist2) continue;
		//cond. 3. behind or big y_diff -- 对手在自己与球连线方向上在自己身后或错开位置太大,不构成危险情况
		opp_2_tackler = opp_2_tackler.Rotate(-ball_dir);
		if (opp_2_tackler.X() < 0.0 || std::fabs( opp_2_tackler.Y() ) > opp.GetPlayerSize() + tackler.GetPlayerSize()) continue;
		//cond. 4. over body_diff -- 对手身体角度跟自己与球连线方向的夹角大于90度,不构成危险情况
		AngleDeg body_diff = std::fabs( GetNormalizeAngleDeg( opp.GetBodyDir() - ball_dir ) );
		if (body_diff > 90.0) continue;

		return true;
	}

	return false;
}