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

📄 analyzer.cpp

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					return -1;
				}
				if(dist<kickableDist){
					found=true;
					player=i;
				}
				if(found) break;
			}
		}
	//一直到球出界或者有个球员能踢到球为止
	}while(ballx<52.5 && ballx>-52.5 && bally<34   && bally>-34	&& !found);
	//如果找到能拦截到球的球员则返回该球员否则返回-1
	if(found) 
		return player;
	else
		return -1;
}

//计算在指定周期内一个球员能跑的最远距离
double CAnalyzer::caclPlayerDashDist(int cycle)
{
	return 0.8*cycle;
}

//计算行为是射门的可能性
double CAnalyzer::caclShootProbability(int side)
{//side 0:left 1:right
	double p=0;
	double goalLine=(side?FIELDLENGTH/2:-FIELDLENGTH/2);
	double ballvx=_sCycleInfo.ball.deltax;
	if(goalLine*ballvx<0) return 0;
	double ballvy=_sCycleInfo.ball.deltay;
	double ballSpeed=sqrt(ballvx*ballvx+ballvy*ballvy);
	double ballx=_sCycleInfo.ball.x;
	double bally=_sCycleInfo.ball.y;
	if(fabs(_sCycleInfo.ball.deltax)<0.01) return 0;
	double dist=sqrt((ballx-goalLine)*(ballx-goalLine)+bally*bally);
	if(dist>SHOOTDISTANCETHRESHOLD) return 0;
	double slop=ballvy/ballvx;
	double impulsion=(SHOOTDISTANCETHRESHOLD-dist)*ballSpeed/(SHOOTDISTANCETHRESHOLD*MAXBALLSPEED);
	double yIntersection=bally+slop*(goalLine-ballx);
	double bias=(fabs(yIntersection)<GOALWIDTH/2)?0:((fabs(yIntersection)>GOALWIDTH)?1:(fabs(yIntersection)-GOALWIDTH/2)/GOALWIDTH);
	p=impulsion*(1-bias);
	return p;
}

bool CAnalyzer::areTeammate(int p1,int p2)
{
	if(p1<MAX_PLAYER && p1>=0 && p2<MAX_PLAYER && p2>=0
		|| p1>=MAX_PLAYER && p1<MAX_PLAYER*2 && p2>=MAX_PLAYER && p2<MAX_PLAYER*2)
		return true;
	else
		return false;
}

int CAnalyzer::player2Unum(int player)
{
	if(player<MAX_PLAYER && player>=0)
		return player+1;
	else if(player>=MAX_PLAYER && player<MAX_PLAYER*2)
		return player-10+100;
	else
		return -1;
}

string CAnalyzer::behavior2str(int behavior)
{
	switch(behavior){
		case BB_NONE:
			return "BB_NONE";
			break;
		case BB_SHOOT:
			return "BB_SHOOT";
			break;
		case BB_PASS:
			return "BB_PASS";
			break;
		case BB_DRIBBLE:
			return "BB_DRIBBLE";
			break;
		case BB_CLEARBALL:
			return "BB_CLEARBALL";
			break;
		case BB_ADJUST:
			return "BB_ADJUST";
			break;
		case BB_RECEIVE:
			return "BB_RECEIVE";
			break;
		case BB_INTERCEPT:
			return "BB_INTERCEPT";
			break;
		case BB_POSITION:
			return "BB_POSITION";
			break;
		default:
			return "?????";
			break;
	}
}

int CAnalyzer::statData()
{
	if(!_sInnerState.logLoaded) return -1;
	//只能调用一次(有待改进)
	if(_sInnerState.statDataInvoked) return -1;
	else _sInnerState.statDataInvoked=true;

	//initialize the stat data......
	resetStatData(false);

	int time=0;
	int team=vBasicEvent[0].team;
	int region=0;
	for(int i=0;i<(int)vBasicEvent.size();i++){
		switch(vBasicEvent[i].type){
			case BB_SHOOT:
				_sStatData.nPlayerShootCount[vBasicEvent[i].player]++;
				_sStatData.nTeamShootCount[vBasicEvent[i].team]++;
				if(vBasicEvent[i].success){
					_sStatData.nPlayerSuccessShootCount[vBasicEvent[i].player]++;
					_sStatData.nTeamSuccessShootCount[vBasicEvent[i].team]++;
				}
				break;
			case BB_PASS:
				_sStatData.nPlayerPassCount[vBasicEvent[i].player]++;
				_sStatData.nTeamPassCount[vBasicEvent[i].team]++;
				if(vBasicEvent[i].success){
					_sStatData.nPlayerSuccessPassCount[vBasicEvent[i].player]++;
					_sStatData.nTeamSuccessPassCount[vBasicEvent[i].team]++;
				}
				break;
			case BB_DRIBBLE:
				_sStatData.nPlayerDribbleCount[vBasicEvent[i].player]++;
				_sStatData.nTeamDribbleCount[vBasicEvent[i].team]++;
				if(vBasicEvent[i].success){
					_sStatData.nPlayerSuccessDribbleCount[vBasicEvent[i].player]++;
					_sStatData.nTeamSuccessDribbleCount[vBasicEvent[i].team]++;
				}
				break;
			case BB_CLEARBALL:
			case BB_ADJUST:
			case BB_RECEIVE:
			case BB_INTERCEPT:
				_sStatData.nPlayerInterceptCount[vBasicEvent[i].player]++;
				_sStatData.nTeamInterceptCount[vBasicEvent[i].team]++;
				if(vBasicEvent[i].success){
					_sStatData.nPlayerSuccessInterceptCount[vBasicEvent[i].player]++;
					_sStatData.nTeamSuccessInterceptCount[vBasicEvent[i].team]++;
				}
				break;
			case BB_POSITION:
			default:
				break;
		}

		if(vPlayerPosition[vBasicEvent[i].time].ball.x<LEFTFIELDTHRESHOLD)	region=-1;
		else if(vPlayerPosition[vBasicEvent[i].time].ball.x<RIGHTFIELDTHRESHOLD) region=0;
		else region=1;
		if(i>0)
		if(region==-1){
			_sStatData.nTeamLeftFieldControlBallCycleCount[team]+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
			_sStatData.nBallInLeftCycleCount+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
		}else if(region==0){
			_sStatData.nTeamMiddleFieldControlBallCycleCount[team]+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
			_sStatData.nballInMiddleCycleCount+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
		}else if(region==1){
			_sStatData.nTeamRightFieldControlBallCycleCount[team]+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
			_sStatData.nBallInRightCycleCount+=(vBasicEvent[i].time-vBasicEvent[i-1].time);
		}

		if(vBasicEvent[i].team!=team){
			_sStatData.nTeamWithBallCycleCount[team]+=(vBasicEvent[i].time-time);
			time=vBasicEvent[i].time;
			team=vBasicEvent[i].team;
		}
	}
	for(int j=0;j<MAX_PLAYER * 2;j++){
		if(_sStatData.nPlayerPassCount[j]==0)
			_sStatData.dPlayerPassSuccessRate[j]=0;
		else
			_sStatData.dPlayerPassSuccessRate[j]=(double)_sStatData.nPlayerSuccessPassCount[j]/(double)_sStatData.nPlayerPassCount[j];
		if(_sStatData.nPlayerShootCount[j]==0)
			_sStatData.dPlayerShootSuccessRate[j]=0;
		else
			_sStatData.dPlayerShootSuccessRate[j]=(double)_sStatData.nPlayerSuccessShootCount[j]/(double)_sStatData.nPlayerShootCount[j];
		if(_sStatData.nPlayerInterceptCount[j]==0)
			_sStatData.dPlayInterceptSuccessRate[j]=0;
		else
			_sStatData.dPlayInterceptSuccessRate[j]=(double)_sStatData.nPlayerSuccessInterceptCount[j]/(double)_sStatData.nPlayerSuccessInterceptCount[j];
		if(_sStatData.nPlayerDribbleCount[j]==0)
			_sStatData.dPlayerDribbleSuccessRate[j]=0;
		else
			_sStatData.dPlayerDribbleSuccessRate[j]=(double)_sStatData.nPlayerSuccessDribbleCount[j]/(double)_sStatData.nPlayerDribbleCount[j];
		//计算球员平均位置
		if((int)vPlayerPosition.size()>0)
		for(int indx=0;indx<(int)vPlayerPosition.size();indx++){
			_sStatData.pPlayerExpectedPosition[j].x+=vPlayerPosition[indx].pFrame[j].x;
			_sStatData.pPlayerExpectedPosition[j].y+=vPlayerPosition[indx].pFrame[j].y;
		}
		_sStatData.pPlayerExpectedPosition[j].x/=(int)vPlayerPosition.size();
		_sStatData.pPlayerExpectedPosition[j].y/=(int)vPlayerPosition.size();
	}
	for(int k=0;k<2;k++){
		if(_sStatData.nTeamPassCount[k]==0)
			_sStatData.dTeamPassSuccessRate[k]=0;
		else
			_sStatData.dTeamPassSuccessRate[k]=((double)_sStatData.nTeamSuccessPassCount[k])/((double)_sStatData.nTeamPassCount[k]);
		if(_sStatData.nTeamShootCount[k]==0)
			_sStatData.dTeamShootSuccessRate[k]=0;
		else
			_sStatData.dTeamShootSuccessRate[k]=((double)_sStatData.nTeamSuccessShootCount[k])/((double)_sStatData.nTeamShootCount[k]);
		if(_sStatData.nTeamInterceptCount[k]==0)
			_sStatData.dTeamInterceptSuccessRate[k]=0;
		else
			_sStatData.dTeamInterceptSuccessRate[k]=(double)_sStatData.nTeamSuccessInterceptCount[k]/(double)_sStatData.nTeamInterceptCount[k];
		if(_sStatData.nTeamDribbleCount[k]==0)
			_sStatData.dTeamDribbleSuccessRate[k]=0;
		else
			_sStatData.dTeamDribbleSuccessRate[k]=(double)_sStatData.nTeamSuccessDribbleCount[k]/(double)_sStatData.nTeamDribbleCount[k];

		double tempSum=(_sStatData.nTeamLeftFieldControlBallCycleCount[k]+_sStatData.nTeamMiddleFieldControlBallCycleCount[k]+_sStatData.nTeamRightFieldControlBallCycleCount[k]);
		if(tempSum==0){
			_sStatData.dTeamLeftFieldControlBallCycleRate[k]=0;
			_sStatData.dTeamMiddleFieldControlBallCycleRate[k]=0;
			_sStatData.dTeamRightFieldControlBallCycleRate[k]=0;
		}else{
			_sStatData.dTeamLeftFieldControlBallCycleRate[k]=(double)_sStatData.nTeamLeftFieldControlBallCycleCount[k]/tempSum;
			_sStatData.dTeamMiddleFieldControlBallCycleRate[k]=(double)_sStatData.nTeamMiddleFieldControlBallCycleCount[k]/tempSum;
			_sStatData.dTeamRightFieldControlBallCycleRate[k]=(double)_sStatData.nTeamRightFieldControlBallCycleCount[k]/tempSum;
		}
	}
	double tempSum=_sStatData.nBallInLeftCycleCount+_sStatData.nballInMiddleCycleCount+_sStatData.nBallInRightCycleCount;
	if(tempSum==0){
		_sStatData.dBallInLeftCycleRate=0;
		_sStatData.dBallInMiddleCycleRate=0;
		_sStatData.dBallInRightCycleRate=0;
	}else{
		_sStatData.dBallInLeftCycleRate=(double)_sStatData.nBallInLeftCycleCount/tempSum;
		_sStatData.dBallInMiddleCycleRate=(double)_sStatData.nballInMiddleCycleCount/tempSum;
		_sStatData.dBallInRightCycleRate=(double)_sStatData.nBallInRightCycleCount/tempSum;
	}
	tempSum=_sStatData.nTeamWithBallCycleCount[0]+_sStatData.nTeamWithBallCycleCount[1];
	if(tempSum==0){
		_sStatData.dTeamWithBallCycleRate[0]=0;
		_sStatData.dTeamWithBallCycleRate[1]=0;
	}else{
		_sStatData.dTeamWithBallCycleRate[0]=_sStatData.nTeamWithBallCycleCount[0]/tempSum;
		_sStatData.dTeamWithBallCycleRate[1]=_sStatData.nTeamWithBallCycleCount[1]/tempSum;
	}

	//debug
	//outputEvents();
	//planRecognization();

	return 0;
}


int CAnalyzer::outputEvents() const
{
	ofstream outfile("event.txt");
	if(!outfile) return -1;
	outfile<<"event queu"<<endl;
	for(int i=0;i<(int)vBasicEvent.size();i++){
		outfile<<endl;
		outfile<<"-------------------------------------"<<endl;
		outfile<<"at time "<<vBasicEvent[i].time<<" :"<<endl;
		outfile<<"  player ";
		outfile<<((vBasicEvent[i].player>10)?(vBasicEvent[i].player+10):(vBasicEvent[i].player+1));
		outfile<<" was doing ";
		switch(vBasicEvent[i].type){
			case BB_SHOOT:
				outfile<<"BB_SHOOT";
				break;
			case BB_PASS:
				outfile<<"BB_PASS to ";
				outfile<<((vBasicEvent[i].obj.unum>10)?(vBasicEvent[i].obj.unum+10):(vBasicEvent[i].obj.unum+1));
				break;
			case BB_DRIBBLE:
				outfile<<"BB_DRIBBLE";
				break;
			case BB_ADJUST:
				outfile<<"BB_ADJUST";
				break;
			case BB_RECEIVE:
				outfile<<"BB_RECEIVE from ";
				outfile<<((vBasicEvent[i].obj.unum>10)?(vBasicEvent[i].obj.unum+10):(vBasicEvent[i].obj.unum+1));
				break;
			case BB_INTERCEPT:
				outfile<<"BB_INTERCEPT";
				break;
			case BB_CLEARBALL:
				outfile<<"BB_CLEARBALL";
				break;
			default:
				break;
		}
		outfile<<((vBasicEvent[i].success)?" SUCCEED":" FAIL");
		outfile<<endl<<endl;
	}

	for(int j=0;j<MAX_PLAYER * 2;j++){
		outfile<<"player "<<j<<" 's pass success rate == "<<_sStatData.dPlayerPassSuccessRate[j] <<endl;
		outfile<<"         " <<"    shot success rate == "<<_sStatData.dPlayerShootSuccessRate[j]<<endl;
		outfile<<"         " <<"    pass count		  == "<<_sStatData.nPlayerPassCount[j]<<endl;
		outfile<<"         " <<"    success pass cnt  == "<<_sStatData.nPlayerSuccessPassCount[j]<<endl;
		outfile<<"         " <<"    shot count		  == "<<_sStatData.nPlayerShootCount[j]<<endl;
		outfile<<"         " <<"    success shot cnt  == "<<_sStatData.nPlayerSuccessShootCount[j]<<endl;
		outfile<<"         " <<"    intercep count    == "<<_sStatData.nPlayerInterceptCount[j]<<endl;
		outfile<<"	       " <<"    success inte cnt  == "<<_sStatData.nPlayerSuccessInterceptCount[j]<<endl;
		outfile<<"	       " <<"    inte success rate == "<<_sStatData.dPlayInterceptSuccessRate[j]<<endl;
		outfile<<"	       " <<"    dribble count     == "<<_sStatData.nPlayerDribbleCount[j]<<endl;
		outfile<<"	       " <<"    success drib cnt  == "<<_sStatData.nPlayerSuccessDribbleCount[j]<<endl;
		outfile<<"	       " <<"    drib success rate == "<<_sStatData.dPlayerDribbleSuccessRate[j]<<endl;
	}
	for(int k=0;k<2;k++){
		outfile<<"team "<<k<<" 's pass success rate == "<<_sStatData.dTeamPassSuccessRate[k] <<endl;
		outfile<<"      "  <<"    pass count		== "<<_sStatData.nTeamPassCount[k]<<endl;
		outfile<<"       " <<"	  success pass cnt  == "<<_sStatData.nTeamSuccessPassCount[k]<<endl;
		outfile<<"      "  <<"    shot success rate == "<<_sStatData.dTeamShootSuccessRate[k]<<endl;
		outfile<<"      "  <<"    shot count		== "<<_sStatData.nTeamShootCount[k]<<endl;
		outfile<<"       " <<"	  success shot cnt  == "<<_sStatData.nTeamSuccessShootCount[k]<<endl;
		outfile<<"       " <<"    with ball cycles  == "<<_sStatData.nTeamWithBallCycleCount[k]<<endl;
		outfile<<"	     " <<"    inte count		== "<<_sStatData.nTeamInterceptCount[k]<<endl;
		outfile<<"       " <<"    success inte cnt  == "<<_sStatData.nTeamSuccessInterceptCount[k]<<endl;
		outfile<<"       " <<"    inte success rate == "<<_sStatData.dTeamInterceptSuccessRate[k]<<endl;
		outfile<<"       " <<"    drib count		== "<<_sStatData.nTeamDribbleCount[k]<<endl;
		outfile<<"       " <<"    success drib cnt  == "<<_sStatData.nTeamSuccessDribbleCount[k]<<endl;
		outfile<<"       " <<"    drib success rate == "<<_sStatData.dTeamDribbleSuccessRate[k]<<endl;
	}
	return 0;
}

int CAnalyzer::convertNetData(const showinfo_t2 &sCycleInfo)
{
	//playmode
	_sCycleInfo.pmode=(PlayMode)sCycleInfo.pmode;
	//ball
	_sCycleInfo.ball.x=(double)(long)ntohl(sCycleInfo.ball.x)/SHOWINFO_SCALE2;
	_sCycleInfo.ball.y=(double)(long)ntohl(sCycleInfo.ball.y)/SHOWINFO_SCALE2;
	_sCycleInfo.ball.deltax=(double)(long)ntohl(sCycleInfo.ball.deltax)/SHOWINFO_SCALE2;
	_sCycleInfo.ball.deltay=(double)(long)ntohl(sCycleInfo.ball.deltay)/SHOWINFO_SCALE2;
	//team
	strcpy(_sCycleInfo.team[0].name,sCycleInfo.team[0].name);
	_sCycleInfo.team[0].score=(int)(long)ntohs(sCycleInfo.team[0].score);
	strcpy(_sCycleInfo.team[1].name,sCycleInfo.team[1].name);
	_sCycleInfo.team[1].score=(int)(long)ntohs(sCycleInfo.team[1].score);
	//time
	_sCycleInfo.time=ntohs(sCycleInfo.time);
	//pos
	for(int i=0;i<MAX_PLAYER * 2;i++){
		_sCycleInfo.pos[i].body_angle=(double)(long)ntohl(sCycleInfo.pos[i].body_angle)/SHOWINFO_SCALE2;
		_sCycleInfo.pos[i].catch_count=(int)(long)ntohs(sCycleInfo.pos[i].catch_count);
		_sCycleInfo.pos[i].chg_view_count=(int)(long)ntohs(sCycleInfo.pos[i].chg_view_count);
		_sCycleInfo.pos[i].dash_count=(int)(long)ntohs(sCycleInfo.pos[i].dash_count);
		_sCycleInfo.pos[i].deltax=(double)(long)ntohl(sCycleInfo.pos[i].deltax)/SHOWINFO_SCALE2;
		_sCycleInfo.pos[i].deltay=(double)(long)ntohl(sCycleInfo.pos[i].deltay)/SHOWINFO_SCALE2;
		_sCycleInfo.pos[i].effort=(double)(long)ntohl(sCycleInfo.pos[i].effort)/SHOWINFO_SCALE2;

⌨️ 快捷键说明

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