From: Oliver O. <fr...@us...> - 2007-03-07 10:39:38
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/gamestateperceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/gamestateperceptor Added Files: Tag: projectx gamestateperceptor.cpp gamestateperceptor.h gamestateperceptor_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: gamestateperceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor.cpp,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gamestateperceptor.h" #include <zeitgeist/logserver/logserver.h> #include <soccer/soccerbase/soccerbase.h> #include <soccer/agentstate/agentstate.h> #include <soccer/gamestateaspect/gamestateaspect.h> using namespace zeitgeist; using namespace oxygen; using namespace boost; using namespace std; GameStatePerceptor::GameStatePerceptor() : oxygen::Perceptor() { mFirstPercept = true; } GameStatePerceptor::~GameStatePerceptor() { } void GameStatePerceptor::InsertSoccerParam(Predicate& predicate, const std::string& name) { float value; if (! SoccerBase::GetSoccerVar(*this,name,value)) { return; } ParameterList& element = predicate.parameter.AddList(); element.AddValue(name); element.AddValue(value); } void GameStatePerceptor::InsertInitialPercept(Predicate& predicate) { // uniform number ParameterList& unumElement = predicate.parameter.AddList(); unumElement.AddValue(string("unum")); unumElement.AddValue(mAgentState->GetUniformNumber()); // team index std::string team; switch (mAgentState->GetTeamIndex()) { case TI_NONE : team = "none"; break; case TI_LEFT : team = "left"; break; case TI_RIGHT : team = "right"; break; } ParameterList& teamElement = predicate.parameter.AddList(); teamElement.AddValue(string("team")); teamElement.AddValue(team); // soccer variables // field geometry parameter InsertSoccerParam(predicate,"FieldLength"); InsertSoccerParam(predicate,"FieldWidth"); InsertSoccerParam(predicate,"FieldHeight"); InsertSoccerParam(predicate,"GoalWidth"); InsertSoccerParam(predicate,"GoalDepth"); InsertSoccerParam(predicate,"GoalHeight"); InsertSoccerParam(predicate,"BorderSize"); // agent parameter InsertSoccerParam(predicate,"AgentMass"); InsertSoccerParam(predicate,"AgentRadius"); InsertSoccerParam(predicate,"AgentMaxSpeed"); // ball parameter InsertSoccerParam(predicate,"BallRadius"); InsertSoccerParam(predicate,"BallMass"); } bool GameStatePerceptor::Percept(boost::shared_ptr<PredicateList> predList) { if ( (mGameState.get() == 0) || (mAgentState.get() == 0) ) { return false; } Predicate& predicate = predList->AddPredicate(); predicate.name = "GameState"; predicate.parameter.Clear(); // with the first GameState percept after the player is assigned // to a team it receives info about it's team and unum assignment // along with outher soccer parameters if ( (mFirstPercept) && (mAgentState->GetTeamIndex() != TI_NONE) ) { mFirstPercept = false; InsertInitialPercept(predicate); } // time ParameterList& timeElement = predicate.parameter.AddList(); timeElement.AddValue(string("time")); timeElement.AddValue(mGameState->GetTime()); // playmode ParameterList& pmElement = predicate.parameter.AddList(); pmElement.AddValue(string("playmode")); pmElement.AddValue(SoccerBase::PlayMode2Str(mGameState->GetPlayMode())); return true; } void GameStatePerceptor::OnLink() { SoccerBase::GetGameState(*this,mGameState); SoccerBase::GetAgentState(*this,mAgentState); } void GameStatePerceptor::OnUnlink() { mGameState.reset(); mAgentState.reset(); } --- NEW FILE: gamestateperceptor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor_c.cpp,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gamestateperceptor.h" using namespace boost; using namespace oxygen; void CLASS(GameStatePerceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/Perceptor); } --- NEW FILE: gamestateperceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: gamestateperceptor.h,v 1.1.2.1 2007/03/07 10:39:34 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef GAMESTATEPERCEPTOR_H #define GAMESTATEPERCEPTOR_H #include <oxygen/agentaspect/perceptor.h> #include <soccer/soccertypes.h> class GameStateAspect; class AgentState; namespace oxygen { class Predicate; } class GameStatePerceptor : public oxygen::Perceptor { public: GameStatePerceptor(); virtual ~GameStatePerceptor(); //! \return true, if valid data is available and false otherwise. virtual bool Percept(boost::shared_ptr<oxygen::PredicateList> predList); protected: /** sets up the reference to the GameStateAspect */ virtual void OnLink(); /** resets the reference to the GameStateAspect */ virtual void OnUnlink(); /** inserts predicate parameters the agent receives once after a successful init command into the predicate. These are it's uniform number and team as well as a subset of the soccer variables */ void InsertInitialPercept(oxygen::Predicate& predicate); /** inserts a soccer variable and its current value into the predicate */ void InsertSoccerParam(oxygen::Predicate& predicate, const std::string& name); protected: //! a reference to the game state boost::shared_ptr<GameStateAspect> mGameState; //! a reference to the agentstate boost::shared_ptr<AgentState> mAgentState; /** true until Percept() is called the first time after the agent is assigned to a team with a successful init command */ bool mFirstPercept; }; DECLARE_CLASS(GameStatePerceptor); #endif // GAMESTATEPERCEPTOR_H |