📄 playerteams.cpp
字号:
/*
Copyright (c) 2000-2003, Jelle Kok, University of Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list 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 documentation
and/or other materials provided with the distribution.
3. Neither the name of the University of Amsterdam nor the names of its
contributors may be used to endorse or promote products derived from this
software 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, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF 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"
#include "Global.h"
#include "CommunicationSystem.h"
#include "SenseHandler.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 */
extern CViewAngle g_viewAngle;
SoccerCommand Player::deMeer5( )
{
// 首先,把改变视觉模式命令放入队列中
// 这两行不需要修改
//
SoccerCommand cmdChangeView = g_viewAngle.getCommandChangeViewType();
ACT->putCommandInQueue(cmdChangeView);
//-------------------------------------------------------------------------
SoccerCommand soc(CMD_ILLEGAL);
SoccerCommand cmdTurnNeck(CMD_ILLEGAL); // lm 06.10.11
VecPosition posAgent = WM->getAgentGlobalPosition();
VecPosition posBall = WM->getBallPos();
int iTmp;
// before kick off : 开球前
if( WM->isBeforeKickOff( ) )
{
if( WM->isKickOffUs( ) &&
WM->getAgentObjectType() == OBJECT_TEAMMATE_9 )
{
// 如果球在脚下(kickable) 。。。
if( WM->isBallKickable() )
{
VecPosition posGoal( PITCH_LENGTH/2.0,
(-1 + 2*(WM->getCurrentCycle()%2)) *
0.4 * SS->getGoalWidth() );
soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
Log.log( 100, "take kick off" );
}
// 球太远了,踢不到。。。
else
{
// 跑到球那里
soc = intercept( false );
Log.log( 100, "move to ball to take kick-off" );
}
ACT->putCommandInQueue( soc );
return soc;
}
// 我不是开球人,那么我要站到我的初始阵型位置
if(posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )
{
ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() ));
}
// 如果我已经离我的初始阵型位置很近,那么我就把身体转向足球
else // else turn to center
{
ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) );
}
}
// 已经开球了
else
{
soc.commandType = CMD_ILLEGAL;
//say pass advice, can ball controller pass to me?
// 如果我计算出控球者可以传球给我,而且我的位置比他的好
// 我就说传球建议,让他把球传给我
sayPassAdvice();
// 如果球很久没看到了,转身去找球
if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
{
ACT->putCommandInQueue( soc = searchBall() ); // if ball pos unknown
return soc;
}
// 如果球在脚下,可踢到
// WM->getConfidence 一句不用管,就当它没用好了,但注意不要删掉
else if( WM->isBallKickable() && WM->getConfidence(OBJECT_BALL) > 0.995 ) // if kickable
{
//first of all, can I shoot?
//一个最简单的射门---如果离对方球门距离小于20.0,向对方球门一角踢
VecPosition posGoal(PITCH_LENGTH/2.0,0.0);
if ( (posAgent-posGoal).getMagnitude() < 20.0 ) {
VecPosition posShoot( PITCH_LENGTH/2.0,
(-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
soc = kickTo( posShoot, SS->getBallSpeedMax() ); // kick maximal
ACT->putCommandInQueue(soc);
return soc;
/*
double oppGoalieY = WM->getGlobalPosition(
WM->getOppGoalieType() ).getY();
int sign = (oppGoalieY > 0) ? -1 : 1;
VecPosition posShoot(PITCH_LENGTH/2.0,
sign * 0.45 * SS->getGoalWidth());
soc = kickTo( posShoot, SS->getBallSpeedMax() ); // kick maximal
ACT->putCommandInQueue(soc);
return soc;
*/
}
//-----------------------------------------------------------
//can I pass?
//如果听到队友要求我传球给他,我就把球踢给他
if (coms.hearPassAdvTime==WM->getCurrentTime()){
soc = kickTo(coms.velPassAdv);
cout<<g_cyc<<" do PassAdv: "<<coms.velPassAdv<<endl;
ACT->putCommandInQueue( soc );
return soc;
}
// 以下判断是否可以带球,以及带球方向
//can I dribble?
//we have many methods to check whether we can dribble:
// 1. no opponents in the cone of the expected dribble angle
// 2. no opponents in the circle of the expected dribble angle
double angDribble = WM->getRelAngleOpponentGoal();
//can I dribble to opp goal? using cone.
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS, Circle(g_ballPos, 2.5)) == 0 &&
WM->getNrInSetInCone(OBJECT_SET_OPPONENTS, PS->getConeWidth(),
g_agentPos, VecPosition(8, angDribble,POLAR) ) == 0){
soc = dribble(angDribble, DRIBBLE_FAST);
ACT->putCommandInQueue( soc );
return soc;
}
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS, Circle(g_ballPos, 2.5)) == 0 &&
WM->getNrInSetInCone(OBJECT_SET_OPPONENTS, PS->getConeWidth(),
g_agentPos, VecPosition(6, angDribble,POLAR) ) == 0){
soc = dribble(angDribble, DRIBBLE_SLOW);
ACT->putCommandInQueue( soc );
return soc;
}
angDribble = 0;
//can I dribble forward? using cone.
if (g_agentPos.getX()<41 &&
WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS, Circle(g_ballPos, 2.5)) == 0 &&
WM->getNrInSetInCone(OBJECT_SET_OPPONENTS, PS->getConeWidth(),
g_agentPos, VecPosition(8, angDribble,POLAR) ) == 0){
soc = dribble(angDribble, DRIBBLE_FAST);
ACT->putCommandInQueue( soc );
return soc;
}
if (g_agentPos.getX()<45 &&
WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS, Circle(g_ballPos, 2.5)) == 0 &&
WM->getNrInSetInCone(OBJECT_SET_OPPONENTS, PS->getConeWidth(),
g_agentPos, VecPosition(6, angDribble,POLAR) ) == 0){
soc = dribble(angDribble, DRIBBLE_SLOW);
ACT->putCommandInQueue( soc );
return soc;
}
angDribble = WM->getRelAngleOpponentGoal();
//can I dribble to opp goal? using circle.
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS,
Circle(g_ballPos+VecPosition(6, angDribble, POLAR), 6.5)) == 0){
soc = dribble(angDribble, DRIBBLE_FAST);
ACT->putCommandInQueue( soc );
return soc;
}
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS,
Circle(g_ballPos+VecPosition(6, angDribble, POLAR), 6.5)) == 0){
soc = dribble(angDribble, DRIBBLE_SLOW);
ACT->putCommandInQueue( soc );
return soc;
}
angDribble = 0;
//can I dribble forward? using circle.
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS,
Circle(g_ballPos+VecPosition(4, angDribble, POLAR), 4.5)) == 0){
soc = dribble(angDribble, DRIBBLE_FAST);
ACT->putCommandInQueue( soc );
return soc;
}
if (WM->getNrInSetInCircle(OBJECT_SET_OPPONENTS,
Circle(g_ballPos+VecPosition(4, angDribble, POLAR), 4.5)) == 0){
soc = dribble(angDribble, DRIBBLE_SLOW);
ACT->putCommandInQueue( soc );
return soc;
}
VecPosition posShoot( PITCH_LENGTH/2.0,
(-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
soc = kickTo( posShoot, SS->getBallSpeedMax() ); // kick maximal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -