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

📄 actionsystem.cpp

📁 浙江大学 RoboCup3D 2006 源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2004 - 2006 by ZJUBase                                  *
 *                                National Lab of Industrial Control Tech. * *                                Zhejiang University, China               * *                                                                         * *   Achievements of ZJUBase in RoboCup Soccer 3D Simulation League:       *
 *    In RoboCup championship,                                             *
 *      - June 2006 - 3rd place in RoboCup 2006, Bremen, Germany (lost     * *        the semi-final with a coin toss)                                 *
 *      - July 2005 - 3rd place in RoboCup 2005, Osaka, Japan (share the   * *        3rd place with team Caspian)                                     *
 *    In RoboCup local events,                                             *
 *      - April 2006 - 2nd place in RoboCup Iran Open 2006, Tehran, Iran   * *        (lost the final with a coin toss)                                *
 *      - December 2005 - 2nd place in AI Games 2005, Isfahan, Iran        *
 *      - July 2005 - champion in China Robot Competition 2005, Changzhou, * *        China                                                            *
 *      - October 2004 - champion in China Soccer Robot Competition 2004,  * *        Guangzhou, China                                                 *
*                                                                         * *   Team members:                                                         *
 *    Currently the team leader is,                                        * *           Hao JIANG (jianghao@iipc.zju.edu.cn; riveria@gmail.com)       *
 *    In the next season, the leader will be                               * *           Yifeng ZHANG (yfzhang@iipc.zju.edu.cn)                        *
 *    ZJUBase 3D agent is created by                                       * *           Dijun LUO (djluo@iipc.zju.edu.cn)                             *
 *    All the members who has ever contributed:                            * *           Jun JIANG                                                     *
 *           Xinfeng DU (xfdu@iipc.zju.edu.cn)                             *
 *           Yang ZHOU (yzhou@iipc.zju.edu.cn)                             *
 *           Zhipeng YANG                                                  *
 *           Xiang FAN                                                     *
 *                                                                         *
 *   Team Manager:                                                          *
 *      Ms. Rong XIONG (rxiong@iipc.zju.edu.cn)                            *
 *                                                                         *
 *   If you met any problems or you have something to discuss about        * *   ZJUBase. Please feel free to contact us through EMails given below.   * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program 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 General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include "Global.h"
#include "Situation.h"
#include "Strategy.h"
#include "Predictor.h"
#include "ActionSystem.h"

#ifdef WIN32
#define for if(0);else for
#endif

ActionSystem as;

#ifdef WIN32
string teamName = "ZJUBase";
string sayMsgSign = "esaBUJZ";
#else
extern string teamName;
extern string sayMsgSign;
#endif
extern string oppTeamName;
Situation* ActionSystem::ST=NULL;

ServerSettings* ActionSystem::SS=NULL;

void ActionSystem::AddCommand(SoccerCommand cmd)
{
	Angle panAngInc;
	Angle tiltAngInc;
	SoccerCommand cmd_panTilt;
	ST->getAngInc(panAngInc,tiltAngInc);
	cmd_panTilt=SoccerCommand(CT_PANTILT, panAngInc, tiltAngInc);///yzp0527
	global.commands[global.nCommand].push_back(cmd_panTilt);
  	global.commands[global.nCommand].push_back(cmd);
	global.nCommand ++;
}

ActionSystem::ActionSystem()
{
}

ActionSystem::~ActionSystem()
{	
}

void ActionSystem::interceptForCatchBall(CommandQueue & cmds)
{
	AgentStatus a,b;
	a.pos = global.wm.nextPos;
	a.vel = global.wm.nextVel;
	b.pos = global.wm.ballPos+global.wm.ballVel;
	b.vel = global.wm.ballVel * SS->B_decay;
	if(fabs(global.wm.ballVel.z)>0.3&&global.wm.ballPos.z>0.2)
	 	b.vel.z = (global.wm.ballVel.z+14.6795*0.2)* 0.8745-14.6795*0.2;
	
	SoccerCommand cmd1,cmd2;
	cmd1 = intercept.interceptForCatchBall(a , b);
	CommandList list;
	Vector3 a_b=a.pos-b.pos;
	cmd2=SoccerCommand(CT_CATCH);

	for(int i=0;i<20;i++){
		list.clear();
		list.push_back(cmd1);
		list.push_back(cmd2);
		cmds.push_back(list);
	}
}

void ActionSystem::interceptForStopBall(CommandQueue& cmds)
{
	AgentStatus a,b;
	a.pos = global.wm.nextPos;
	a.vel = global.wm.nextVel;
	b.pos = global.wm.ballPos+global.wm.ballVel;
	b.vel = global.wm.ballVel * SS->B_decay;

	if(fabs(global.wm.ballVel.z)>0.3&&global.wm.ballPos.z>0.2)
	 	b.vel.z = (global.wm.ballVel.z+14.6795*0.2)* 0.8745-14.6795*0.2;

	SoccerCommand cmd1,cmd2;
	cmd1 = intercept.interceptForStopBall(a , b);
	CommandList list;
	double power;
	Angle theta;

	Vector3 curballposvalue=ST->EvaluatePassPoint(b.pos);

	// if there is an opponent near me, then send "kick" 20 times
	Vector3 curBall = global.wm.ballPos;
	Vector3 nextBall = global.wm.ballPos + global.wm.ballVel;
	Vector3 nextMe = global.wm.nextPos;
	Vector3 fastestOpp = global.wm.oppPos[ST->oppByDist2Ball[0]];
	Vector3 g1(-X(100),SS->mGoalWidth/2.);
	Vector3 g2(-X(100),-SS->mGoalWidth/2.);
	Angle ang1=(b.pos-g1).ang()-10;
	Angle ang2=(b.pos-g2).ang()+10;
	Angle kick_ang=(nextMe-nextBall).ang();

	if((	// if the kick angle is to the offense direction
		fabs(ST->getKickAngle()) < 90 && 
		// if the fastest opponent is very near from the ball
		(fastestOpp - curBall).mod() < 5.0 &&curballposvalue.x<20&&
		// if my position is very near from the ball
		(nextMe - curBall).mod() < 1.2 &&
		// if the oppenent is not blocked by me from the ball
		fabs(Normalize((nextMe - curBall).ang() - (fastestOpp - curBall).ang())) > 30) ||
		 (global.wm.myNumber>=1&&global.wm.myNumber<=5&& (fastestOpp-curBall).mod()<5.0 && (nextMe-nextBall).mod()<2.0)&&(kick_ang<ang1||kick_ang>ang2)){

		if(ST->getPassVel(power, theta)){
			cmd2 = SoccerCommand(CT_KICK,theta,power);
			for(int i=0;i<20;i++){
				list.clear();
				list.push_back(cmd1);
				list.push_back(cmd2);
				cmds.push_back(list);
			}

		} else if(global.wm.ballPos.x<-10){

			if(global.wm.ballPos.getDistToOppGoal() < 8)
				theta = 5;
			else
				theta = 30;

			power = 100;
			cmd2 = SoccerCommand(CT_KICK,theta,power);
			for(int i=0;i<20;i++){
				list.clear();
				list.push_back(cmd1);
				list.push_back(cmd2);
				cmds.push_back(list);
			}

		} else {
			bool bFlag = false;
			Angle ang_target = (Vector3(X(100),0,0)-global.wm.ballPos).ang();
			for(int i=0;i<11;i++){
				Angle ang = (global.wm.oppPos[i]-global.wm.ballPos).ang();
				if((global.wm.oppPos[i] - global.wm.ballPos).mod() < 1
					&&fabs(Normalize(ang_target-ang))<45){
					bFlag = true;
					break;
				}
			}

			if(bFlag){
				if(global.wm.ballPos.getDistToOppGoal() < 8) {
					theta = 30;
				} else {
					theta = 45;
				}
				power = 100;
				cmd2 = SoccerCommand(CT_KICK,theta,power);
				for(int i=0;i<20;i++){
					list.clear();
					list.push_back(cmd1);
					list.push_back(cmd2);
					cmds.push_back(list);
				}

			} else{
				list.push_back(cmd1);
				cmds.push_back(list);
			}
		}
	} else {
		list.push_back(cmd1);
		cmds.push_back(list);
	}

}


void  ActionSystem::interceptFastest(CommandQueue& cmds,Vector3 target)
{
	AgentStatus a,b;
	a.pos = global.wm.nextPos;
	a.vel = global.wm.nextVel;
	b.pos = global.wm.ballPos+global.wm.ballVel;
	b.vel = global.wm.ballVel * SS->B_decay;
	if(fabs(global.wm.ballVel.z)>0.3&&global.wm.ballPos.z>0.2)
	 	b.vel.z = (global.wm.ballVel.z+14.6795*0.2)* 0.8745-14.6795*0.2;

	SoccerCommand cmd1,cmd2;
	cmd1 = intercept.interceptFastest(target,  a,  b);
	CommandList list;
	double power;
	Angle theta;
	Vector3 curballposvalue=ST->EvaluatePassPoint(b.pos);

	// if there is an opponent near me, then send "kick" 20 times
	Vector3 curBall = global.wm.ballPos;
	Vector3 nextBall = global.wm.ballPos + global.wm.ballVel;
	Vector3 nextMe = global.wm.nextPos;
	Vector3 fastestOpp = global.wm.oppPos[ST->oppByDist2Ball[0]];

	if((	// if the kick angle is to the offense direction
		fabs(ST->getKickAngle()) < 90 && 
		// if the fastest opponent is very near from the ball
		(fastestOpp - curBall).mod() < 5.0 &&curballposvalue.x<20&&
		// if my position is very near from the ball
		(nextMe - curBall).mod() < 1.2 &&
		// if the oppenent is not blocked by me from the ball
		fabs(Normalize((nextMe - curBall).ang() - (fastestOpp - curBall).ang())) > 90) ||
		//if i'm the goalia
          (global.wm.myNumber==1 && (fastestOpp-curBall).mod()<10.0 && (nextMe-nextBall).mod()<2.0)){

		if(ST->getPassVel(power, theta)){
			cmd2 = SoccerCommand(CT_KICK,theta,power);
			for(int i=0;i<20;i++){
				list.clear();
				list.push_back(cmd1);
				list.push_back(cmd2);
				cmds.push_back(list);
			}

		}else if(global.wm.ballPos.x<-10){

			if(global.wm.ballPos.getDistToOppGoal() < 8)
				theta = 30;
			else
				theta = 45;
			power = 100;
			if(global.wm.myNumber>6){
				Vector3 opp2me=global.wm.oppPos[0]-global.wm.nextPos;
				Vector3 goal2me=Vector3(X(100),0,0)-global.wm.nextPos;
				Vector3 ball2me=global.wm.ballPos+global.wm.ballVel-global.wm.nextPos;
				double ang_goal2me=Normalize(goal2me.ang());
				double ang_ball2me=Normalize(ball2me.ang());
			
				if(global.wm.myPos.x>X(70)||fabs(ang_goal2me-ang_ball2me)>45||global.wm.myNumber>9){
					power=5;theta=0;
				}
			}

			cmd2 = SoccerCommand(CT_KICK,theta,power);
			for(int i=0;i<20;i++){
				list.clear();
				list.push_back(cmd1);
				list.push_back(cmd2);
				cmds.push_back(list);
			}

		} else {
			bool bFlag = false;
			Angle ang_target = (Vector3(X(100),0,0)-global.wm.ballPos).ang();
			for(int i=0;i<11;i++){
				Angle ang = (global.wm.oppPos[i]-global.wm.ballPos).ang();
				if((global.wm.oppPos[i] - global.wm.ballPos).mod() < 1
					&&fabs(Normalize(ang_target-ang))<45){
					bFlag = true;
					break;
				}
			}

			if(bFlag){
				if(global.wm.ballPos.getDistToOppGoal() < 8)
					theta = 5;
				else
					theta = 30;
				power = 100;
				cmd2 = SoccerCommand(CT_KICK,theta,power);
				for(int i=0;i<20;i++){
					list.clear();
					list.push_back(cmd1);
					list.push_back(cmd2);
					cmds.push_back(list);
				}

⌨️ 快捷键说明

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