playerteams.cpp
来自「根据 trilearn_base_sources-3.3 (一般称做UVA底层)」· C++ 代码 · 共 423 行 · 第 1/2 页
CPP
423 行
/*Copyright (c) 2000-2003, Jelle Kok, University of AmsterdamAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the University of Amsterdam nor the names of itscontributors may be used to endorse or promote products derived from thissoftware without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//*! \file PlayerTeams.cpp<pre><b>File:</b> PlayerTest.cpp<b>Project:</b> Robocup Soccer Simulation Team: UvA Trilearn<b>Authors:</b> Jelle Kok<b>Created:</b> 10/12/2000<b>Last Revision:</b> $ID$<b>Contents:</b> This file contains the class definitions for the Player that are used to test the teams' high level strategy.<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>10/12/2000 Jelle Kok Initial version created</pre>*/#include "Player.h"/*!This method is the first complete simple team and defines the actions taken by all the players on the field (excluding the goalie). It is based on the high-level actions taken by the simple team FC Portugal that it released in 2000. The players do the following: - if ball is kickable kick ball to goal (random corner of goal) - else if i am fastest player to ball intercept the ball - else move to strategic position based on your home position and pos ball */SoccerCommand Player::deMeer5( ){ static FormationT ftChange=FT_BlueSky_442A; //记录要更改的阵形,默认使用FT_BlueSky_442A阵形 SoccerCommand soc(CMD_ILLEGAL);//初始化一个无效指令 VecPosition posAgent = WM->getAgentGlobalPosition();//取得当前球员的位置 VecPosition posBall = WM->getBallPos();//取得球的位置 int iTmp;//临时变量 if( !WM->isBeforeKickOff( ) ) { //队形不正确首先调整队形 if(formations->getFormation()!=ftChange) formations->setFormation( ftChange ); //需要根据不同的比赛状态来采取同的行动方针 if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() ) { ACT->putCommandInQueue( soc = searchBall() ); // if ball pos unknown ACT->putCommandInQueue( alignNeckWithBody( ) ); // search for it } else if( WM->isBallKickable()) // if kickable { //soc = shot(); soc=dribbleWith(0.0); ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); Log.log( 100, "kick ball" ); } else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp ) == WM->getAgentObjectType() && !WM->isDeadBallThem() ) { // if fastest to ball Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp ); soc = intercept( false,true ); // intercept the ball if( soc.commandType == CMD_DASH && // if stamina low WM->getAgentStamina().getStamina() < SS->getRecoverDecThr()*SS->getStaminaMax()+200 ) { soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // if stamina high { ACT->putCommandInQueue( soc ); // dash as intended ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } else if( posAgent.getDistanceTo(WM->getStrategicPosition()) > 1.5 + fabs(posAgent.getX()-posBall.getX())/10.0) // if not near strategic pos { if( WM->getAgentStamina().getStamina() > // if stamina high SS->getRecoverDecThr()*SS->getStaminaMax()+800 ) { soc = moveToPos(WM->getStrategicPosition(), PS->getPlayerWhenToTurnAngle()); ACT->putCommandInQueue( soc ); // move to strategic pos ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // else watch ball { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // nothing to do ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) ); } else { //阵形不是默认开球阵形的话,更改阵形 if( formations->getFormation() != FT_BlueSky_INIT ) { formations->setFormation( FT_BlueSky_INIT ); } if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 11 ) // 11号球员发球 { if( WM->isBallKickable() )//可以踢球了 { VecPosition posDes(-9.0,6.0);//传球的目标是后方队员 soc = BasicPlayer::directPass( posDes,PASS_NORMAL ); //传球给后方队友 Log.log( 100, "take kick off" ); } else//否则的话11号球员首先要去拿到球 { soc = intercept( false ); Log.log( 100, "move to ball to take kick-off" ); } ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); return soc; } //距离本位点过远的情况下,将球员直接移动到本位点 if( posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 ) { ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() )); } //如果身体不是正对足球的话,调整为向球看 else if(WM->getAgentGlobalBodyAngle()!=0) { ACT->putCommandInQueue( soc=turnBodyToPoint( WM->getGlobalPosition(OBJECT_BALL), 0 ) ); } //让球员不停的旋转查看四周状况 ACT->putCommandInQueue(lookAround( 45.0,soc )); } return soc;}/*!This method is a simple goalie based on the goalie of the simple Team of FC Portugal. It defines a rectangle in its penalty area and moves to the position on this rectangle where the ball intersects if you make a line between the ball position and the center of the goal. If the ball can be intercepted in the own penalty area the ball is intercepted and catched.*//* 守门员高级决策 */SoccerCommand Player::deMeer5_goalie( ){ int i; SoccerCommand soc; //初始化命令为无效的 VecPosition posBall = WM->getBallPos(); //当前球的位置 VecPosition posAgent = WM->getAgentGlobalPosition(); //取得球员当前的位置 AngDeg angBody = WM->getAgentGlobalBodyAngle(); //身体的角度 double dist = posAgent.getDistanceTo( posBall ); //和球的距离 int cycle = WM->getCurrentCycle(); //当前的周期数 double distUs; //距离足球最近的我方球员和球的距离 double distThem; //距离足球最近的对方球员和球的距离 VecPosition posUs; //距离足球最近的我方球员的位置 VecPosition posThem; //距离足球最近的对方球员的位置 ControlT who_control; //球的控制权在谁的手上static ControlT last_control; //记录最后一次球的控制权在谁的手上 // define the top and bottom position of a rectangle in which keeper moves // 定义守门员移动区域的最右上角点和最左下角点(守门员方向的左前方点和右前方点) static const VecPosition posLeftTop( -PITCH_L_HALF + PENALTY_AREA_L_HALF, -PENALTY_AREA_W_HALF/2.0 ); static const VecPosition posRightTop( -PITCH_L_HALF + PENALTY_AREA_L_HALF, +PENALTY_AREA_W_HALF/2.0 ); // define the borders of this rectangle using the two points. // 取得几条有关这两个点的直线... static Line lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop); static Line lineBack = Line::makeLineFromTwoPoints( VecPosition( -51.5, posLeftTop.getY() ),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?