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

📄 strategy.h

📁 robocup源代码2001年清华机器人源代码
💻 H
字号:
/*
    Copyright (C) 2001  Tsinghuaeolus

    Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

	If you make any changes or have any comments we would appreciate a 
	message to yjy01@mails.tsinghua.edu.cn.
*/

#ifndef _Strategy
#define _Strategy


#include "Geometry.h"
#include "Command.h"
#include "bpn.h"

class Player;

class The3rdCurve{
private:
	float a, b, c, d;
	float inf, sup;
public:
	The3rdCurve(float a = 0.0f, float b = 0.0f, float c = 0.0f, float d = 0.0f, float inf = 0.0f, float sup = 1.0f);
	bool Interpolation(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3);
	float GetOutput(float x, bool limited = true);
	void SetABCD(float a, float b, float c, float d);
	void  SetInfSup(float inf, float sup);
};

#define MAXBALLCONTROLLERS 5
#define CP_max_hearmodes 5
class Situation{
private:
	int num_hearmodes;
	PlayMode heardmode[CP_max_hearmodes];
	bool mode_changed;

	void ForgetAll();
public:
	Situation();

	Time CurrentTime;
	Time LastInterruptTime;
	Time LastCycle();
	
	Time Sense_Interval;// how long has it been since the last sense infomation came
	Time UpdateInterval;// how long has it been since the last update
	int InterruptsThisCycle;

	bool ClockStopped;
	Time ClockStoppedTime;

	PlayMode playmode;
	KickOff_Mode kickoff_mode;
	bool IsGoalieKick;

	int MyScore;
	int TheirScore;
	char MySide;
	char TheirSide;
/****************************************************************/
	void HearMode(PlayMode playemode);
	void SetPlayMode(PlayMode playmode);
	void OnChangeMode(PlayMode playmode);
	void UpdateScore(char Side);
	void SetKickOffMode(KickOff_Mode);
	void UpdateTime(Time time);
	void UpdateMode();

/***********   Control of the ball *******************/
	UNum My_Ballcontrollers[MAXBALLCONTROLLERS];
	UNum Their_Ballcontrollers[MAXBALLCONTROLLERS];
	int num_my_ballcontrollers;
	int num_their_ballcontrollers;
	int num_ballcontrollers;
	float conf_of_control;
	UNum  ballcontroller;
	UNum  most_promising_controller;
	Vector next_interception_point;
	float min_IT_cycles;
	float Team_Control;
	bool Ballwithincontrol(char side, UNum No);
	bool BallFree;
	bool IsControllerOrFutureController(char side, UNum No);
	bool IsControllerOrFutureController(UNum No);
	Vector NextControlBallPos();
/********	Ball Change Course	*************/
/*******  judge situation *****************/
	bool IsAttack;
	void JudgeSituation();
	SP_State PlaceKickState;	
	GameState JudgeGameState();
	GameState gamestate;
	void LogGameState();
	Time SightTime;
	Time ModeChangedTime;
	bool IsPlaceKick(){return bool(PlaceKickState != SPST_AfterExec);}
	bool IsSetPlayState(SP_State state){return bool(PlaceKickState == state);}
	void ChangeSetPlay(SP_State state){PlaceKickState = state;}
};

class Role{
public:
	Role(float attackness = -1.0f, float leftness = -1.0f, float aggressiveness = -1.0f, float creative = -1.0f);
	void SetRole(float attackness, float leftness, float aggressiveness, float creative);
	UNum No;
	Vector strategical_pos;
	bool RoleMatched(Role& role);
	bool IsRoleKnown(){ return attackness >= 0 && leftness >= 0 && aggressiveness >= 0 && creativeness >= 0;}
	bool IsMid(){return leftness <= 0.6f && leftness >= 0.4f;}
	bool IsForward(){ return attackness >= 0.8f;}
	bool IsBack(){ return attackness <= 0.5f;}
	bool IsMidFielder(){ return !IsForward() && !IsBack();}

	float attackness;
	float leftness;
	float aggressiveness;
	float creativeness;	
};

class Set_Play{
protected:
	int total_roles;
	Role roles[SP_team_size];
	UNum Executor;
public:
	Time Counter;	
	Set_Play(){total_roles = 0;}
	void AddRole(float attackness, float leftness, const Vector& pos);
	void AddRole(UNum No, const Vector& pos);
	bool IsRole(UNum No);
	bool IsExecutor(UNum No);
	Vector GetSetPlayPos(UNum No);
	Vector GetMySetPlayPos();
	bool RecentSeen();
		
};

class BeforeKickOff : public Set_Play{
private:
	Time fill_pos_move_time;
	Time fill_pos_turn_time;
public:
	void set_roles();
	void going();
};

class PlaceKick :public Set_Play{
protected:	
	int total_roles;
	Vector BallPos;
	float PlayerZoneLength[SP_team_size+1];
	float HeadingToBall[SP_team_size+1];
	Vector Trackmark[SP_team_size+1];
	void CheckHeadingAndStamina();
	bool canshoot,canpass;
	AngleDeg GetFaceAngle();
public:
	SP_State curState;
	void going();
	UNum JudgeExecutor();
	bool CanExecute();
	bool ShouldAssist();
	bool ExecutorGo();
	void AssistGo();
	void Execute();
    
};

class GoaliePlaceKick : public Set_Play{
private :
public :
	int movecount;
	Time movetime;
	GoaliePlaceKick();
	float CalcPass(Vector pos);
	float CalcAngle(Vector ATpos,Vector DFpos); 
	float CalcPoint(Vector pos);
	float GetControl(int mynum,int oppnum);
	void going();
	bool ShouldMove();
	bool CanKickOut();
	bool KickOut();
	AngleDeg MyFaceAngle(Vector pos);
	Vector MovePoint[CP_NumGoalieMovePoint];
	int deadtime;
	float passpriority;
	AngleDeg visualrequestangle;
};


class Formation{
private:
//for BP use
	double input[4];
	double output[2];
public:
	Formation();
	
	Vector GetOffensivePoint(float attackness, float leftness, Vector ballpos);
	Vector GetDefensivePoint(const Role& role, Vector ballpos);
	Vector GetDefensivePoint(float attackness, float leftness, Vector ballpos);
	Vector GetFormationPoint(const Player& player);
	Vector GetFormationPoint();
	BPN FMOffenseNet;
	BPN FMDefenseNet;
/*******  Set Play  ******************/
	BeforeKickOff beforekickoff;
	GoaliePlaceKick goalieplacekick;
	PlaceKick placekick;
/*************************************/
	float CalcRelativeDegree();
};

class Field{
private:
	double sensitivity_input[2];
	double sensitivity_output;
public:
	Field();

	void Initialize();

	BPN DF_SensitivityNet;
	BPN OffSensitivityNet;
	Rect field;
	Rect l_field;
	Rect r_field;

	Rect backfield;
	Rect forwardfield;
	Rect midfield;

	Rect l_backfield;
	Rect m_backfield;
	Rect r_backfield;

	Rect l_midfield;
	Rect m_midfield;
	Rect r_midfield;

	Rect l_forwardfield;
	Rect m_forwardfield;
	Rect r_forwardfield;

	Rect my_penaltyarea;
	Rect their_penaltyarea;
	Rect my_goaltenderbox;
	Rect their_goaltenderbox;
	Rect my_goaldefendbox; 

	Rect shootablearea;
	Rect expanded_field;//greater than field
	Rect shrinked_field; //smaller than field

	Vector mygoal;
	Vector l_mygoalpost;
	Vector r_mygoalpost;
	Vector theirgoal;
	Vector l_theirgoalpost;
	Vector r_theirgoalpost;

	Line SideLines[4];

	float GetDefensiveSensitivity(Vector pos);
	float GetOffensiveSensitivity(Vector pos);

	bool WithInField(Vector pos);
	bool WithInExpandedField(Vector pos);
	bool WithInLeftField(Vector pos);
	bool WithInRightField(Vector pos);
	bool WithInShootableArea(Vector pos);
	/** Stat players in some field**/
	int NumOpponentsInCone(AngleDeg direction, float distance, AngleDeg angle_range);
	int NumOpponentsInCone(Vector pos, AngleDeg direction, float distance, AngleDeg angle_range);
	int NumTeammatesInCone(AngleDeg direction, float distance, AngleDeg angle_range);
	int NumTeammatesInCone(Vector pos, AngleDeg direction, float distance, AngleDeg angle_range);
	int NumNoneGoalieTeammatesInCone(Vector end1, Vector end2, AngleDeg angle_range);
	int NumNoneGoalieTeammatesInCone(Vector pos, AngleDeg direction, float distance, AngleDeg angle_range);
	int NumOpponentsWithin(float distance);
	int NumOpponentsWithin(float distance, Vector pos);
	int NumOpponentsWithin(float Dist, AngleDeg angle, float ofDist, AngleDeg ofangle);
	int NumTeammatesWithin(float distance);
	int NumTeammatesWithin(float distance, Vector pos);
	int NumTeammatesWithin(float Dist, AngleDeg angle, float ofDist, AngleDeg ofangle);

	bool IsInvalidZone(Vector Pos);
	
	float GetOffsideLine();
	UNum GuessOffside();
	bool IsOffside();
	bool Maybeoffside();

	float CalcThreat(UNum No);

	float FitPosDegree(Vector CurrentPos, Vector TargetPos,float radius = 2.5);
	float FitPosDegree(UNum No, Vector TargetPos, float radius = 2.5);

	bool IsBlocked(UNum No);
	bool IsBlocked(char side, UNum No);

	UNum theirgoalie;
	UNum mygoalie;
	inline bool IsValidmygoalie(){return bool(0 < mygoalie && mygoalie<=SP_team_size);}
	inline bool IsValidtheirgoalie(){return bool(0 < theirgoalie && theirgoalie<=SP_team_size);}

	
	TimedDataArray<float, 5> offsideline;
	TimedDataArray<UNum, 5> Behindestopp;
	TimedDataArray<UNum, 5> Susoffsideopp;
};
#endif

⌨️ 快捷键说明

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