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

📄 kick.h

📁 2002年
💻 H
字号:
#ifndef __KICK_H__
#define __KICK_H__

#include "types.h"
#include "astar.h"
#include "command.h"
#include "serverparam.h"
#include "clientparam.h"


const int KICKDIS = 5;
const int KICKAGL = 24;

const float CP_OA_stepcost = -0.09f;
const int CP_OA_maxdepth = 5;
const int CP_OA_maxsteps = 10;

const float CP_OA_root_hvalue = 0;

struct kpos{
	Vector pos;
	int idx_dis;
	int idx_agl;
	
	bool enabled;
	float qvalue[KICKDIS*KICKAGL];
	kpos* pts[KICKDIS*KICKAGL+1];
};

class kstate{
private:	
	inline int GetIdx() const {
		return  pos - p_pos->pts[0] ;
	} //pos = p_pos->pts[idx]
public:
	kpos *p_pos, *pos;

	kstate(kpos* _pos, kpos* _p_pos = NULL) 
		: pos(_pos), p_pos(_p_pos), explored_nodes(0) {}
	inline bool IsRoot() const {
		return bool(p_pos == NULL);
	}
	int depth;
	int explored_nodes;	//explored nodes

	inline kpos* go_next(){
		return pos->pts[explored_nodes++];
	}
	
	inline float cost() const{
		return depth * CP_OA_stepcost;
	}
	inline float hvalue() const{
		if(p_pos == NULL) return CP_OA_root_hvalue;
		else return p_pos->qvalue[GetIdx()];
	}
	
	inline float GetValue() const{return hvalue() + cost();}
	
	inline bool operator == (const kstate& t) const{
		return bool(p_pos == t.p_pos && pos == t.pos);
	}
	inline bool operator < (const kstate& t) const{
		return GetValue() > t.GetValue(); 
	}		
};

class MyOA : public Astar<kstate>{
private:
	Vector s_pos,s_vel,p_vel[CP_OA_maxdepth];
	float bdfacing;
	kpos oapos[KICKDIS][KICKAGL];
	Vector Tvel;
	Vector dvel;

	int maxdepth;
	float stepcost;

	void GetNode_PosVel(const Node& node, Vector& pos, Vector& vel) const;
	void Extend(Node& sel_s);
	void ExtendSel();
public:	
	MyOA(){maxdepth = CP_OA_maxdepth; stepcost = CP_OA_stepcost; maxscounts = CP_OA_maxsteps;}

	bool IsTarget();

	inline int getdisidx(float balldis);
	inline int getaglidx(float ballagl);
	inline kpos* getkickpos(int disidx,int aglidx){return &(oapos[disidx][aglidx]);}
	inline void Disable(int disidx, int aglidx){oapos[disidx][aglidx].enabled = false;}
	inline void Enable(int disidx, int aglidx){oapos[disidx][aglidx].enabled = true;}
	void Enableall();
	Vector Getfirstkick();
	Vector Getnextpos();
	int Getneedkicks();
	inline int Getsearchcounts(){return scounts;}
	inline Vector GetTvel(){return Tvel;}
	void Initvpos(char* filename = NULL);	
	//float fEvaluate(kstate s);	
	void SetInitState(Vector pos, Vector vel, Vector pvel, float bodyfacing);
	inline void SetDesirevel(Vector desirevel){dvel = desirevel;}
	inline void SetMaxdepth(int depth){maxdepth = depth>CP_OA_maxdepth ? CP_OA_maxdepth:depth;}
	inline void Setstepcost(float cost){stepcost = cost;}
	inline void Setmaxsteps(int maxsteps){maxscounts = maxsteps;}

	bool Canreachpos(Vector& bpos, Vector& bvel, float bdfacing, Vector& next_bpos, float* effort=NULL);
	bool Canreachvel(Vector& bpos, Vector& bvel, float bdfacing, Vector& next_bvel, float* effort=NULL);

};


class Kick{
private:
	/*	wise kick */
	float speedinc[19];
	AngleDeg maxinc_angle[19];
	float getspeedinc(AngleDeg startangle, AngleDeg turnangle);
	float getmaxincangle(AngleDeg startangle);
/*	oakick	*/
	inline void Enablepos(int disidx, int aglidx);
	inline void Disablepos(int disidx, int aglidx);
	void Oa_limitpos(float rel_angle);

	Time oainf_time;
	bool oainf_allenabled;
	float oainf_Maxy, oainf_Miny, oainf_Minx, oainf_Maxx;
	bool line_limit;
	int pos_limit;
	Vector oainf_pos[3];
	float oainf_radius[3];
public:
	Kick();
/*	oa kick	*/
	MyOA KickOAlast;
	MyOA KickOA2_5;
	MyOA KickOA2_0;
	MyOA KickOA1_5;

	void SetOainf();
	void Enableall();

	KT_Res oakick(float kickspeed, AngleDeg kickangle, KK_Mode kk_mode = KK_slow);
	KT_Res oakick(float kickspeed, AngleDeg kickangle, Command& command, KK_Mode kk_mode = KK_slow);

/*	smartkick	*/
	float smartkick(float kickspeed, AngleDeg kickangle, Command& command, KK_Mode mode = KK_slow);
	float smartkick(float kickspeed, AngleDeg kickangle, KK_Mode mode = KK_slow); // execute at once

/*	turn_ball	*/
	KT_Res turn_ball(TurnDir dir, AngleDeg turn_angle, float turnball_radius = ClientParam::turnball_radius, KK_Mode kk_mode = KK_slow);
	KT_Res turn_ball(TurnDir dir, AngleDeg turn_angle, Command& command, float turnball_radius = ClientParam::turnball_radius, KK_Mode kk_mode = KK_slow);
	KT_Res turn_ball(AngleDeg turn_angle, float turnball_radius = ClientParam::turnball_radius, KK_Mode kk_mode = KK_slow);
	KT_Res turn_ball(AngleDeg turn_angle, Command& command, float turnball_radius = ClientParam::turnball_radius, KK_Mode kk_mode = KK_slow);

/*	stop ball	*/
	bool stopball();
	bool stopball(Command& command);
/*	wisekick	*/
	KT_Res wisekick(float kickspeed, AngleDeg kickangle, KK_Mode kk_mode = KK_slow);
	KT_Res wisekick(float kickspeed, AngleDeg kickangle, Command& command, KK_Mode kk_mode = KK_slow);

	void CorrectForMyVel(float& kickspeed, float& kickangle);
	bool CanKickOut(Vector ballrelpos, float speed, float angle);	
};

#endif //__KICK_H__

⌨️ 快捷键说明

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