📄 worldmodel.h
字号:
/*
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 WorldModel.h
<pre>
<b>File:</b> WorldModel.h
<b>Project:</b> Robocup Soccer Simulation Team: UvA Trilearn
<b>Authors:</b> Jelle Kok
<b>Created:</b> 12/02/2001
<b>Last Revision:</b> $ID$
<b>Contents:</b> class declarations of WorldModel. This class contains
methods that give information about the current and future
state of the world (soccer field).
<hr size=2>
<h2><b>Changes</b></h2>
<b>Date</b> <b>Author</b> <b>Comment</b>
12/02/2001 Jelle Kok Initial version created
</pre>
*/
#ifndef _WORLD_MODEL_
#define _WORLD_MODEL_
#include "Objects.h" // needed for PlayerObject
#include "PlayerSettings.h" // needed for getPlayerDistTolerance
#include "Logger.h" // needed for Log
#include "Formations.h" // needed for getStrategicPosition (prediction)
#include <list>
#ifdef WIN32
#include <windows.h> // needed for mutex
#else
#include <pthread.h> // needed for pthread_mutex
#include <sys/time.h> // needed for gettimeofday
#endif
extern Logger Log; // defined in Logger.C
extern Logger LogDraw; // defined in Logger.C
#ifdef WIN32
/*! This function shall return the integral value (represented as a double)
nearest x in the direction of the current rounding mode. The current
rounding mode is implementation-defined.
If the current rounding mode rounds toward negative infinity, then rint()
shall be equivalent to floor() . If the current rounding mode rounds
toward positive infinity, then rint() shall be equivalent to ceil().
url: http://www.opengroup.org/onlinepubs/007904975/functions/rint.html */
inline double rint(double x)
{
return floor(x+0.5);
}
/*! The drand48() function shall return non-negative,
double-precision, floating-point values, uniformly distributed over the
interval [0.0,1.0).
url: http://www.opengroup.org/onlinepubs/007904975/functions/drand48.html*/
inline double drand48()
{
return ((double)(rand() % 100)) / 100;
}
#endif
/*****************************************************************************/
/********************** CLASS WORLDMODEL *************************************/
/*****************************************************************************/
/*! The Class WorlModel contains all the RoboCup information that is available
on the field. It contains information about the players, ball, flags and
lines. Furthermore it contains methods to extract useful information.
The (large amount of) attributes can be separated into different groups:
- Environmental information: specific information about the soccer server
- Match information: general information about the current state of a match
- Object information: all the objects on the soccer field
- Action information: actions that the agent has performed
The methods can also be divided into different groups:
- Retrieval methods: directly retrieving information of objects
- Update methods: update world based on new sensory information
- Prediction methods: predict future states based on past perceptions
- High-Level methods: deriving high-level conclusions from basic worldstate
*/
class WorldModel
{
private:
/***************************************************************************/
/*************************** ATTRIBUTES ************************************/
/***************************************************************************/
////////////////////////// ENVIRONMENTAL INFORMATION ////////////////////////
ServerSettings *SS; /*!< Reference to all server params*/
PlayerSettings *PS; /*!< Reference to all client params*/
HeteroPlayerSettings pt[MAX_HETERO_PLAYERS]; /*!< info hetero player types */
Formations *formations; /*!< Reference to formation used */
////////////////////////// CURRENT MATCH INFORMATION ////////////////////////
// time information
Time timeLastSeeMessage; /*!< server time of last see msg */
Time timeLastRecvSeeMessage; /*!< server time received see msg */
Time timeLastSenseMessage; /*!< server time of last sense msg */
Time timeLastRecvSenseMessage;/*!< server time received sense msg */
Time timeLastHearMessage; /*!< server time of last hear msg */
bool bNewInfo; /*!< indicates new info from server */
Time timeLastCatch; /*!< time of last catch by goalie */
Time timeLastRefMessage; /*!< time of last referee message */
// player information
char strTeamName[MAX_TEAM_NAME_LENGTH]; /*!< Team name */
int iPlayerNumber; /*!< player number in soccerserver */
SideT sideSide; /*!< side where the agent started */
// match information
PlayModeT playMode; /*!< current play mode in the game */
int iGoalDiff; /*!< goal difference */
////////////////////////// OBJECTS //////////////////////////////////////////
// dynamic objects
BallObject Ball; /*!< information of the ball */
AgentObject agentObject; /*!< information of the agent itself*/
PlayerObject Teammates[MAX_TEAMMATES];/*!< information of all teammates */
PlayerObject Opponents[MAX_OPPONENTS];/*!< information of all opponents */
PlayerObject UnknownPlayers[MAX_TEAMMATES+MAX_OPPONENTS];
/*!< info unknown players are stored
here til mapped to known player */
int iNrUnknownPlayers; /*!< number of unknown players */
// fixed objects
FixedObject Flags[MAX_FLAGS]; /*!< all flag information */
FixedObject Lines[MAX_LINES]; /*!< all line information */
////////////////////////// LOCALIZATION INFORMATION /////////////////////////
static const int iNrParticlesAgent = 100; /*!<nr of particles used to store
agent position */
static const int iNrParticlesBall = 100; /*! nr of particles used to store
ball position and velocity */
VecPosition particlesPosAgent[iNrParticlesAgent]; /*!< particles to store
agent position */
VecPosition particlesPosBall[iNrParticlesBall]; /*! particles to store
ball position */
VecPosition particlesVelBall[iNrParticlesBall]; /*! particles to store
ball velocity */
double dTotalVarVel;
double dTotalVarPos;
////////////////////////// PREVIOUS ACTION INFORMATION //////////////////////
// arrays needed to keep track of actually performed actions.
SoccerCommand queuedCommands[CMD_MAX_COMMANDS]; /*!<all performed commands,
set by ActHandler */
bool performedCommands[CMD_MAX_COMMANDS];/*!< commands performed in
last cycle, index is
CommandT */
int iCommandCounters[CMD_MAX_COMMANDS]; /*!< counters for all
performed commands */
////////////////////////// VARIOUS //////////////////////////////////////////
// attributes only applicable to the coach
Time timeCheckBall; /*!< time bsCheckBall applies to */
BallStatusT bsCheckBall; /*!< state of the ball */
// synchronization
#ifdef WIN32
CRITICAL_SECTION mutex_newInfo; /*!< mutex to protect bNewInfo */
HANDLE event_newInfo; /*!< event for bNewInfo */
#else
pthread_mutex_t mutex_newInfo; /*!< mutex to protect bNewInfo */
pthread_cond_t cond_newInfo; /*!< cond variable for bNewInfo */
#endif
bool m_bRecvThink; /*!< think received in sync. mode */
// communication
char m_strPlayerMsg[MAX_MSG];/*!< message communicated by player */
int m_iCycleInMsg; /*!< cycle contained in message */
Time m_timePlayerMsg; /*!< time corresponding to player msg*/
int m_iMessageSender; /*!< player who send message */
public:
int getMessageSender() { return m_iMessageSender; }
private:
char m_strCommunicate[MAX_SAY_MSG];/*!< string for communicating */
// attention to
ObjectT m_objFocus; /*!< object to which is focused. */
// offside line
double m_dCommOffsideX; /*!< communicated offside line */
Time m_timeCommOffsideX; /*!< time Communicated offside line */
// feature information
Feature m_features[MAX_FEATURES];/*!< features applied to cur. cycle.*/
// other
bool m_bPerformedKick; /*!<Indicates whether ball was kicked*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -