Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

gamestateperceptor.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: gamestateperceptor.cpp,v 1.5 2004/06/09 09:22:27 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "gamestateperceptor.h"
00023 #include <zeitgeist/logserver/logserver.h>
00024 #include <soccer/soccerbase/soccerbase.h>
00025 #include <soccer/agentstate/agentstate.h>
00026 #include <soccer/gamestateaspect/gamestateaspect.h>
00027 
00028 using namespace zeitgeist;
00029 using namespace oxygen;
00030 using namespace boost;
00031 using namespace std;
00032 
00033 GameStatePerceptor::GameStatePerceptor() : oxygen::Perceptor()
00034 {
00035     mFirstPercept = true;
00036 }
00037 
00038 GameStatePerceptor::~GameStatePerceptor()
00039 {
00040 }
00041 
00042 void
00043 GameStatePerceptor::InsertSoccerParam(Predicate& predicate, const std::string& name)
00044 {
00045     float value;
00046     if (! SoccerBase::GetSoccerVar(*this,name,value))
00047     {
00048         return;
00049     }
00050 
00051     ParameterList& element = predicate.parameter.AddList();
00052     element.AddValue(name);
00053     element.AddValue(value);
00054 }
00055 
00056 void
00057 GameStatePerceptor::InsertInitialPercept(Predicate& predicate)
00058 {
00059     // uniform number
00060     ParameterList& unumElement = predicate.parameter.AddList();
00061     unumElement.AddValue(string("unum"));
00062     unumElement.AddValue(mAgentState->GetUniformNumber());
00063 
00064     // team index
00065     std::string team;
00066     switch (mAgentState->GetTeamIndex())
00067     {
00068     case TI_NONE :
00069         team = "none";
00070         break;
00071     case TI_LEFT :
00072         team = "left";
00073         break;
00074     case TI_RIGHT :
00075         team = "right";
00076         break;
00077     }
00078 
00079     ParameterList& teamElement = predicate.parameter.AddList();
00080     teamElement.AddValue(string("team"));
00081     teamElement.AddValue(team);
00082 
00083     // soccer variables
00084     // field geometry parameter
00085     InsertSoccerParam(predicate,"FieldLength");
00086     InsertSoccerParam(predicate,"FieldWidth");
00087     InsertSoccerParam(predicate,"FieldHeight");
00088     InsertSoccerParam(predicate,"GoalWidth");
00089     InsertSoccerParam(predicate,"GoalDepth");
00090     InsertSoccerParam(predicate,"GoalHeight");
00091     InsertSoccerParam(predicate,"BorderSize");
00092 
00093     // agent parameter
00094     InsertSoccerParam(predicate,"AgentMass");
00095     InsertSoccerParam(predicate,"AgentRadius");
00096     InsertSoccerParam(predicate,"AgentMaxSpeed");
00097 
00098     // ball parameter
00099     InsertSoccerParam(predicate,"BallRadius");
00100     InsertSoccerParam(predicate,"BallMass");
00101 }
00102 
00103 bool
00104 GameStatePerceptor::Percept(boost::shared_ptr<PredicateList> predList)
00105 {
00106     if (
00107         (mGameState.get() == 0) ||
00108         (mAgentState.get() == 0)
00109         )
00110     {
00111         return false;
00112     }
00113 
00114     Predicate& predicate = predList->AddPredicate();
00115     predicate.name = "GameState";
00116     predicate.parameter.Clear();
00117 
00118     // with the first GameState percept after the player is assigned
00119     // to a team it receives info about it's team and unum assignment
00120     // along with outher soccer parameters
00121     if (
00122         (mFirstPercept) &&
00123         (mAgentState->GetTeamIndex() != TI_NONE)
00124         )
00125     {
00126         mFirstPercept = false;
00127         InsertInitialPercept(predicate);
00128     }
00129 
00130     // time
00131     ParameterList& timeElement = predicate.parameter.AddList();
00132     timeElement.AddValue(string("time"));
00133     timeElement.AddValue(mGameState->GetTime());
00134 
00135     // playmode
00136     ParameterList& pmElement = predicate.parameter.AddList();
00137     pmElement.AddValue(string("playmode"));
00138     pmElement.AddValue(SoccerBase::PlayMode2Str(mGameState->GetPlayMode()));
00139 
00140     return true;
00141 }
00142 
00143 void
00144 GameStatePerceptor::OnLink()
00145 {
00146     SoccerBase::GetGameState(*this,mGameState);
00147     SoccerBase::GetAgentState(*this,mAgentState);
00148 }
00149 
00150 void
00151 GameStatePerceptor::OnUnlink()
00152 {
00153     mGameState.reset();
00154     mAgentState.reset();
00155 }

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4