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

📄 analyzer.h

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 H
字号:
//在线教练分析器
#ifndef _ANALYZER_H_
#define _ANALYZER_H_
using namespace std;
#include "defines.h"
#include <math.h>
#include <vector>
#include <list>
#include <set>
#include <fstream>
#include "SoccerDoctor.h"

#define SHOOTPROBABILITYTHRESHOLD 0.15
#define SHOOTDISTANCETHRESHOLD 30
#define MAXBALLSPEED 2.7
#define FIELDLENGTH 105
#define FIELDWIDTH 68
#define GOALWIDTH 14.6
#define LEFTFIELDTHRESHOLD -17.5
#define RIGHTFIELDTHRESHOLD 17.5
#define REGIONWIDTH 200
#define REGIONHEIGHT 100
#define MAXTABLESIZE 100
#define CRITICALVALUE 1

enum BasicBehaviorType{
	BB_NONE,
	BB_SHOOT,
	BB_PASS,
	BB_DRIBBLE,
	BB_CLEARBALL,
	BB_ADJUST,
	BB_RECEIVE,
	BB_INTERCEPT,
	BB_POSITION
};

struct PointT{
	PointT();
	PointT(double _x,double _y);
	double x;
	double y;
};

struct ObjectT{
	int unum;
	PointT pt;
};

struct BasicBehaviorEvent{
	int time;
	int endTime;
	int team;
	int player;
	BasicBehaviorType type;
	PointT pt;
	ObjectT obj;
	bool success;
};


struct InnerState{
	//当前周期
	PlayMode playMode;
	bool ballKickableForPlayer;
	int playerWithBall;
	int teamWithBall;
	int scoreLeft;
	int scoreRight;
	//上一周期
	PlayMode lastCyclePlayMode;
	bool lastCycleBallKickableForPlayer;
	int lastCyclePlayerWithBall;
	int lastCycleTeamWithBall;
	int lastCycleScoreLeft;
	int lastCycleScoreRight;
	//上一次
	int prePlayerWithBall;
	int preTeamWithBall;
	//不分的
	bool teamWithBallChange;
	bool playerWithBallChange;
	bool parameterNeedFillBack;
	bool statDataInvoked;
	bool logLoaded;
	int  lastCycle;
};

struct StatDataStructure{
	//个人
	int nPlayerShootCount[MAX_PLAYER * 2];
	int nPlayerSuccessShootCount[MAX_PLAYER * 2];
	double dPlayerShootSuccessRate[MAX_PLAYER * 2];
	int nPlayerPassCount[MAX_PLAYER * 2];
	int nPlayerSuccessPassCount[MAX_PLAYER * 2];
	double dPlayerPassSuccessRate[MAX_PLAYER * 2];
	int nPlayerWithBallCycleCount[MAX_PLAYER * 2];
	double dPlayerWithBallCycleRate[MAX_PLAYER * 2];
	int	nPlayerInterceptCount[MAX_PLAYER * 2];
	int nPlayerSuccessInterceptCount[MAX_PLAYER * 2];
	double dPlayInterceptSuccessRate[MAX_PLAYER * 2];
	int nPlayerDribbleCount[MAX_PLAYER * 2];
	int nPlayerSuccessDribbleCount[MAX_PLAYER * 2];
	double dPlayerDribbleSuccessRate[MAX_PLAYER * 2];
	PointT pPlayerExpectedPosition[MAX_PLAYER * 2];
	//团队
	int nTeamShootCount[2];
	int nTeamSuccessShootCount[2];
	double dTeamShootSuccessRate[2];
	int nTeamPassCount[2];
	int nTeamSuccessPassCount[2];
	double dTeamPassSuccessRate[2];
	int nTeamInterceptCount[2];
	int nTeamSuccessInterceptCount[2];
	double dTeamInterceptSuccessRate[2];
	int nTeamDribbleCount[2];
	int nTeamSuccessDribbleCount[2];
	double dTeamDribbleSuccessRate[2];
	int nTeamWithBallCycleCount[2];
	double dTeamWithBallCycleRate[2];
	int nTeamLeftFieldControlBallCycleCount[2];
	double dTeamLeftFieldControlBallCycleRate[2];
	int nTeamMiddleFieldControlBallCycleCount[2];
	double dTeamMiddleFieldControlBallCycleRate[2];
	int nTeamRightFieldControlBallCycleCount[2];
	double dTeamRightFieldControlBallCycleRate[2];
	int nBallInLeftCycleCount;
	double dBallInLeftCycleRate;
	int nballInMiddleCycleCount;
	double dBallInMiddleCycleRate;
	int nBallInRightCycleCount;
	double dBallInRightCycleRate;
	int nTeamOffsideCount[2];
	int nTeamBackPassCount[2];
	int nTeamKickFaultCount[2];
	int nTeamKickInCount[2];
	int nTeamCornerKickCount[2];
	int nTeamGoalKickCount[2];
	int nTeamFreeKickCount[2];
};

 
struct TeamT{
	char	name[16] ;
	int 	score ;
};

struct BallT{
  double x;
  double y;
  double deltax;
  double deltay;
};

struct PlayerT{
  int type;
  double x;
  double y;
  double deltax;
  double deltay;
  double body_angle;
  double head_angle;
  double view_width;
  double view_quality;
  int stamina;
  double effort;
  double recovery;
  int kick_count;
  int dash_count;
  int turn_count;
  int say_count;
  int tneck_count;
  int catch_count;
  int move_count;
  int chg_view_count;
} ;

struct CycleInfoT{
  PlayMode		pmode ;
  TeamT			team[2] ;
  BallT			ball;
  PlayerT		pos[MAX_PLAYER * 2] ;
  u_long		time ;
};  

struct PointFrameT{
	int	time;
	PointT ball;
	PointT pFrame[MAX_PLAYER * 2];
};

//************************************************
//		计划识别的MAPRN节点结构
//************************************************
//基本事件
//struct MAPRNBE{
//	BasicBehaviorType type;
//	int	player;
//	int sourceRegion;
//	int goalRegion;
//};

struct MAPRNNode;

//并发和后继事件的指针
struct MAPRNPTR{
	int pEvent;
	int counts;
	double p;
};

//事件
struct MAPREVENT{
	BasicBehaviorType type;
	int player;
	int sourceRegion;
	int goalPlayer;
	int goalRegion;
};

//节点
struct MAPRNNode{
	MAPREVENT event;
	int counts;
	vector<MAPRNPTR> concurrent;
	vector<MAPRNPTR> follow;
};
//************************************************

//************************************************
//		计划识别的Trie结构
//************************************************
//节点
struct TrieNode{
	MAPREVENT leading_action;
	list<MAPREVENT> associate_action;
	TrieNode *parents;
	list<TrieNode*> children;
	int count;
	double chi2;
};

//end-length table structure
struct EndLengthTable{
	//vector<vector<int> > table;
	int table[MAXTABLESIZE*10][MAXTABLESIZE];
	vector<MAPREVENT> events;
};
//************************************************


//************************************************
//		分析器定义
//************************************************
class CMainFrame;
class CAnalyzer
{
public:
	CAnalyzer();
	~CAnalyzer(void);
	void init(CMainFrame* pMainFrame);

	//调用接口
	int analyzeOneCycleInfo(const showinfo_t2 &sCycleInfo);
	int statData();
	int outputEvents() const;

	//数据复位接口
	int resetStatData(bool restrict=true);
	int resetInnerState();

	//获得事件表指针的接口
	const vector<BasicBehaviorEvent>& getBasicEventPointer() const;

	//获得位置表指针的接口
	const vector<PointFrameT>& getPlayerPositionPointer() const;

	//获得统计数据的接口
	//个人
	int getPlayerShootCount(int side,int unum) const;
	int getPlayerSuccessShootCount(int side,int unum) const;
	double getPlayerShootSuccessRate(int side,int unum) const;
	int getPlayerPassCount(int side,int unum) const;
	int getPlayerSuccessPassCount(int side,int unum) const;
	double getPlayerPassSuccessRate(int side,int unum) const;
	int getPlayerWithBallCycleCount(int side,int unum) const;
	double getPlayerWithBallCycleRate(int side,int unum) const;
	int	getPlayerInterceptCount(int side,int unum) const;
	int getPlayerSuccessInterceptCount(int side,int unum) const;
	double getPlayInterceptSuccessRate(int side,int unum) const;
	int getPlayerDribbleCount(int side,int unum) const;
	int getPlayerSuccessDribbleCount(int side,int unum) const;
	double getPlayerDribbleSuccessRate(int side,int unum) const;
	PointT getPlayerExpectedPosition(int side,int unum) const;
	struct BasicBehaviorEvent getPlayerBehavior(int cycle,int side,int unum) const;
	//团队
	int getTeamShootCount(int side) const;
	int getTeamSuccessShootCount(int side) const;
	double getTeamShootSuccessRate(int side) const;
	int getTeamPassCount(int side) const;
	int getTeamSuccessPassCount(int side) const;
	double getTeamPassSuccessRate(int side) const;
	int getTeamInterceptCount(int side) const;
	int getTeamSuccessInterceptCount(int side) const;
	double getTeamInterceptSuccessRate(int side) const;
	int getTeamDribbleCount(int side) const;
	int getTeamSuccessDribbleCount(int side) const;
	double getTeamDribbleSuccessRate(int side) const;
	int getTeamWithBallCycleCount(int side) const;
	double getTeamWithBallCycleRate(int side) const;
	int getTeamLeftFieldControlBallCycleCount(int side) const;
	double getTeamLeftFieldControlBallCycleRate(int side) const;
	int getTeamMiddleFieldControlBallCycleCount(int side) const;
	double getTeamMiddleFieldControlBallCycleRate(int side) const;
	int getTeamRightFieldControlBallCycleCount(int side) const;
	double getTeamRightFieldControlBallCycleRate(int side) const;
	double getLeftControlRate() const;
	double getMiddleControlRate() const;
	double getRightControlRate() const;
	int getTeamOffsideCount(int side) const;
	int getTeamBackPassCount(int side) const;
	int getTeamKickFaultCount(int side) const;
	int getTeamKickInCount(int side) const;
	int getTeamCornerKickCount(int side) const;
	int getTeamGoalKickCount(int side) const;
	int getTeamFreeKickCount(int side) const;


private:
	//网络格式转换
	int convertNetData(const showinfo_t2 &sCycleInfo);

	//记录球员位置
	int recordPlayerPosition();

	//预测工具
	int getFastestPlayerToBall(bool teammate=false, int unum=-1);
	double caclPlayerDashDist(int cycle);
	double caclShootProbability(int side);
	bool areTeammate(int player1,int player2);
	int player2Unum(int player);
	string behavior2str(int behavior);

	//控球判断
	int getPlayerWithBall();
	int getTeamWithBall();

	//基本行为分析
	struct BasiceBehavior getPlayerBehavior();

	//回填参数
	int fillBackParameter();

private:
	//************************************************
	//计划识别函数
	//************************************************
	//生成MAPR事件队列
	int planRecognization();
	int point2Region(PointT pt);
	//生成基本事件队列
	int createBasicEvent();
	//生成计划识别网络
	int createMAPRN();
	//计划抽取
	int refinePlan();
	//在MAPRN中寻找给定事件
	int findEventInMAPRN(MAPREVENT event);
	//输出基本行为事件队列
	int outputVEvent();
	//输出MAPRN
	int outputMAPRN();
	//初始化Trie
	int initTrie();
	//构建Trie
	int createTrie();
	//寻找孩子
	TrieNode* findChild(TrieNode* pParents,MAPREVENT leading_act);
	//添加一个孩子
	TrieNode* addChild(TrieNode* pParents,MAPREVENT leading_act);
	//更新END-LENGTH表
	int updateEndLengthTable(int depth,MAPREVENT leading_act);
	//获得END-LENGTH表表项
	int getEndLengthTableItem(MAPREVENT leading_act, int depth);
	//对Trie剪枝
	int pruningTrie(TrieNode* pNode,int depth);
	//释放Trie
	int releaseTrie(TrieNode* pNode);
	//输出Trie
	int outputTrie(TrieNode* pNode);
	//优化行为序列
	int refineVEvent();

private:
	//周期信息记录
	CycleInfoT _sCycleInfo;
	//分析器内部状态
	InnerState _sInnerState;
	//统计数据
	StatDataStructure _sStatData;

	//指向主窗口的指针
	CMainFrame* _pMainFrame;

	//指向球员参数的指针
	const player_params_t *_pPlayerParam;
	//指向Server参数的指针
	const server_params_t *_pServerParam;

	//记录基本行为事件的表
	vector<BasicBehaviorEvent> vBasicEvent;

	//记录球员的位置的表
	vector<PointFrameT> vPlayerPosition;

	//************************************************
	//计划识别
	//************************************************
	//基本事件集合
	vector<vector<MAPREVENT> > vEvent;
	//事件集合
	vector<MAPRNNode> vMAPRN;
	//Trie
	TrieNode *pTrieRoot;
	//行为长度表
	EndLengthTable sEndLengthTable;
	//参数
	double region_width;
	double region_height;
	double chi2_threshold;
};
#endif

⌨️ 快捷键说明

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