📄 formations.cpp
字号:
/*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 Formations.cpp<pre><b>File:</b> Formations.cpp<b>Project:</b> Robocup Soccer Simulation Team: UvA Trilearn<b>Authors:</b> Jelle Kok<b>Created:</b> 05/02/2001<b>Last Revision:</b> $ID$<b>Contents:</b> Definitions for the different methods in the classes that are associated with Formations. .<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>05/02/2001 Jelle Kok Initial version created</pre>*/#include "Formations.h"#include "Parse.h" // Parse#include <fstream> // ifstream#include <stdio.h> // printf#include <math.h> // fabs/*****************************************************************************//********************** CLASS PLAYERTYPEINFO *********************************//*****************************************************************************//*! This method is the default constructor and sets all the values of this class to "illegal" values. This method is needed when an array of this class is initialized, since then the default constructor (without arguments) is called. Afterwards the actual values should be set using the method setValues. */PlayerTypeInfo::PlayerTypeInfo(){ setValues( PT_ILLEGAL, UnknownDoubleValue,UnknownDoubleValue, UnknownDoubleValue,UnknownDoubleValue, false );}/*! This Constructor receives the values for all the member variables as arguments and initializes the member variables using the method setValues. \param pt PlayerType corresponding to the player type of this class \param dAttrX x attraction to the ball \param dAttrY y attraction to the ball \param dMinX minimal x coordinate for this player type \param dMaxX maximal x coordinate for this player type \param bBehindBall boolean indicating whether this player type should always stay behind the ball. */PlayerTypeInfo::PlayerTypeInfo( PlayerT pt, double dAttrX, double dAttrY, double dMinX, double dMaxX, bool bBehindBall ){ setValues( pt, dAttrX, dAttrY, dMinX, dMaxX, bBehindBall );}/*! This method receives the values for all the member variables as arguments and sets these member variables. \param pt PlayerType corresponding to the player type of this class \param ax x attraction to the ball \param ay y attraction to the ball \param minx minimal x coordinate for this player type \param maxx maximal x coordinate for this player type \param bb boolean indicating whether this player type should always stay behind the ball. \return bool indicating whether update was successful. */bool PlayerTypeInfo::setValues( PlayerT pt, double ax, double ay, double minx, double maxx, bool bb ){ playerType = pt; dAttrX = ax; dAttrY = ay; dMinX = minx; dMaxX = maxx; bBehindBall = bb; return true;}/*! This method print the different member values separated by comma's to the specified output stream. \param os output stream to which member values are printed */void PlayerTypeInfo::show( ostream &os ){ os << "(" << (int)playerType << ", " << dAttrX << ", " << dAttrY << ", " << dMinX << ", " << dMaxX << ", " << bBehindBall << ")" << endl;}/*! This method sets the player type associated with this class. \param type new player type \return bool indicating whether update was succesfull */bool PlayerTypeInfo::setPlayerType( PlayerT type ){ playerType = type; return true;}/*! This method returns the player type associated with this class. \return player type of this class */PlayerT PlayerTypeInfo::getPlayerType( ) const{ return playerType;}/*! This method sets the x attraction to the ball for this player type. The x attraction to the ball is a double in the range (0,1). This value is used to determine the x coordinate of the strategic position for this player type. The x attraction of the ball is multiplied with the x coordinate of the ball and added to the home position of the agent to determine the x coordinate of the strategic position. \param dAttractionX new x attraction for this player type \return bool indicating whether update was succesfull */bool PlayerTypeInfo::setAttrX( double dAttractionX ){ dAttrX = dAttractionX; return true;}/*! This method returns the x attraction to the ball for this player type. The x attraction to the ball is a double in the range (0,1). This value is used to determine the x coordinate of the strategic position for this player type. The x attraction of the ball is multiplied with the x coordinate of the ball and added to the home position of the agent to determine the x coordinate of the strategic position. \return x attraction for this player type */double PlayerTypeInfo::getAttrX( ) const{ return dAttrX;}/*! This method sets the y attraction to the ball for this player type. The y attraction to the ball is a double in the range (0,1). This value is used to determine the y coordinate of the strategic position for this player type. The y attraction of the ball is multiplied with the y coordinate of the ball and added to the home position of the agent to determine the y coordinate of the strategic position. \param dAttractionY new y attraction for this player type \return bool indicating whether update was succesfull */bool PlayerTypeInfo::setAttrY( double dAttractionY ){ dAttrY = dAttractionY; return true;}/*! This method returns the y attraction to the ball for this player type. The y attraction to the ball is a double in the range (0,1). This value is used to determine the y coordinate of the strategic position for this player type. The y attraction of the ball is multiplied with the y coordinate of the ball and added to the home position of the agent to determine the y coordinate of the strategic position. \return y attraction for this player type */double PlayerTypeInfo::getAttrY( ) const{ return dAttrY;}/*! This method sets the minimal x coordinate for this player type. When the calculated x coordinate for the strategic position is lower than this value, the x coordinate is set to this minimal x coordinate. \param dMinimalX new minimal x coordinate for this player type \return bool indicating whether update was succesfull. */bool PlayerTypeInfo::setMinX( double dMinimalX ){ dMinX = dMinimalX; return true;}/*! This method returns the minimal x coordinate for this player type. When the calculated x coordinate for the strategic position is lower than this value, the x coordinate is set to this minimal x coordinate. \return minimal x coordinate for this player type */double PlayerTypeInfo::getMinX( ) const{ return dMinX;}/*! This method sets the maximal x coordinate for this player type. When the calculated x coordinate for the strategic position is larger than this value, the x coordinate is set to this maximal x coordinate. \param dMaximalX new maximal x coordinate for this player type \return bool indicating whether update was succesfull. */bool PlayerTypeInfo::setMaxX( double dMaximalX ){ dMaxX = dMaximalX; return true;}/*! This method returns the maximal x coordinate for this player type. When the calculated x coordinate for the strategic position is larger than this value, the x coordinate is set to this maximal x coordinate. \return maximal x coordinate for this player type */double PlayerTypeInfo::getMaxX( ) const{ return dMaxX;}/*!This method sets the value that indicates whether this player type should stay behind the ball or not. When set to true and the strategic position for this player type is calculated to be in front of the ball. The x coordinate of the strategic position is set to the x coordinate of the ball. \param b boolean indicating whether this playertype should stay behind the ball \return bool indicating whether update was succesfull. */bool PlayerTypeInfo::setBehindBall( bool b ){ bBehindBall = b; return true;}/*! This method returns the value that indicates whether this player type should stay behind the ball or not. When set to true and the strategic position for this player type is calculated to be in front of the ball. The x coordinate of the strategic position is set to the x coordinate of the ball. \return bool indicating whether to stay behind the ball or not */bool PlayerTypeInfo::getBehindBall( ) const{ return bBehindBall;}/*****************************************************************************//********************** CLASS FORMATIONTYPEINFO*******************************//*****************************************************************************//*! This is the default constructor and does nothing. */FormationTypeInfo::FormationTypeInfo( ){}/*!This method sets the current formation type for this class. \param type new formation type for this class. \return bool indicating whether update was successful. */bool FormationTypeInfo::setFormationType( FormationT type ){ formationType = type; return true;}/*! This method return the current formation type for this class. \return formation type for this class. */FormationT FormationTypeInfo::getFormationType( ) const{ return formationType;}/*! This method prints all the information about this formation to the specified output stream. The format is the following: - x coordinate of the home position for all the roles - y coordinate of the home position for all the roles - the player types for all the roles - the x attraction for all the player types - the y attraction for all the player types - indication whether to stay behind the ball for all the player types - minimal x coordinate for all the player types - maximal x coordinate for all the player types \param os output stream for output. */void FormationTypeInfo::show( ostream &os ){ char str[128]; for( int i = 0; i < MAX_TEAMMATES; i++ ) { sprintf(str, "%3.2f ", posHome[i].getX() ); os << str; } os << endl; for( int i = 0; i < MAX_TEAMMATES; i++ ) { sprintf( str, "%3.2f ", posHome[i].getY() ); os << str; } os << endl; for( int i = 0; i < MAX_TEAMMATES; i++ ) { sprintf( str, "%5d ", (int)playerType[i] ); os << str; } os << endl; for( int i = 0; i < MAX_PLAYER_TYPES; i++ ) { sprintf( str, "%3.2f ", playerTypeInfo[i].getAttrX() ); os << str; } os << endl; for( int i = 0; i < MAX_PLAYER_TYPES; i++ ) { sprintf( str, "%3.2f ", playerTypeInfo[i].getAttrY() ); os << str; } os << endl; for( int i = 0; i < MAX_PLAYER_TYPES; i++ ) { sprintf( str, "%5d ", playerTypeInfo[i].getBehindBall() ); os << str; } os << endl; for( int i = 0; i < MAX_PLAYER_TYPES; i++ ) { sprintf( str, "%3.2f ", playerTypeInfo[i].getMinX() ); os << str; } os << endl; for( int i = 0; i < MAX_PLAYER_TYPES; i++ ) { sprintf( str, "%3.2f ", playerTypeInfo[i].getMaxX() ); os << str; } os << endl;}/*! This method sets the home position of the role indicated by the number 'atIndex' in this formation. The home position is the position from which the strategic position is calculated and could be interpreted as the position a player is located when the ball is at the position (0,0). \param pos new home position for the player with role number 'atIndex' \param atIndex index of the player with role for which the home position should be set. \return bool indicating whether update was succesfull. */bool FormationTypeInfo::setPosHome( VecPosition pos, int atIndex ){ posHome[ atIndex ] = pos; return true;}/*! This method sets the x coordinate of the home position for the player
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -