From: <he...@us...> - 2013-06-08 21:23:57
|
Revision: 355 http://sourceforge.net/p/simspark/svn/355 Author: hedayat Date: 2013-06-08 21:23:54 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Check the number of hetero players each team can use. Modified Paths: -------------- trunk/rcssserver3d/ChangeLog trunk/rcssserver3d/plugin/soccer/agentstate/agentstate.cpp trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.cpp trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.h trunk/rcssserver3d/rcssserver3d/naosoccersim.rb Modified: trunk/rcssserver3d/ChangeLog =================================================================== --- trunk/rcssserver3d/ChangeLog 2013-06-05 20:03:19 UTC (rev 354) +++ trunk/rcssserver3d/ChangeLog 2013-06-08 21:23:54 UTC (rev 355) @@ -1,3 +1,14 @@ +2013-06-09 Hedayat Vatankhah <hed...@gm...> + + * plugin/soccer/gamestateaspect/gamestateaspect.h: + * plugin/soccer/gamestateaspect/gamestateaspect.cpp: + * plugin/soccer/agentstate/agentstate.cpp (AgentState::OnUnlink): + * rcssserver3d/naosoccersim.rb: + - control the number of heterogeneous players each team can use. It limits + both the total number of heterogeneous players of each team + (MaxTotalHeteroCount variable in naosoccersim.rb), and the number of + heterogeneous players of each type (MaxHeteroTypeCount variable) + 2013-06-06 Hedayat Vatankhah <hed...@gm...> * plugin/soccer/restrictedvisionperceptor/restrictedvisionperceptor.h: @@ -4,7 +15,7 @@ * plugin/soccer/restrictedvisionperceptor/restrictedvisionperceptor.cpp: * plugin/soccer/restrictedvisionperceptor/restrictedvisionperceptor_c.cpp: * data/rsg/agent/nao/naoneckhead.rsg: - - Add MyOrientation sensing by Patrick (setSenseMyOrien in rsg file) + - added MyOrientation sensing by Patrick (setSenseMyOrien in rsg file) 2013-04-25 Hedayat Vatankhah <hed...@gm...> Modified: trunk/rcssserver3d/plugin/soccer/agentstate/agentstate.cpp =================================================================== --- trunk/rcssserver3d/plugin/soccer/agentstate/agentstate.cpp 2013-06-05 20:03:19 UTC (rev 354) +++ trunk/rcssserver3d/plugin/soccer/agentstate/agentstate.cpp 2013-06-08 21:23:54 UTC (rev 355) @@ -251,7 +251,8 @@ return; } - game_state->ReturnUniform(GetTeamIndex(), GetUniformNumber()); + game_state->ReturnUniform(GetTeamIndex(), GetUniformNumber(), + GetRobotType()); } bool Modified: trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.cpp =================================================================== --- trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.cpp 2013-06-05 20:03:19 UTC (rev 354) +++ trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.cpp 2013-06-08 21:23:54 UTC (rev 355) @@ -38,14 +38,21 @@ mFupTime = 0; mLastModeChange = 0; mGameHalf = GH_FIRST; + mRobotTypeCount[0].push_back(0); // add count for type 0 (default type) + mRobotTypeCount[1].push_back(0); + mHeteroCount[0] = 0; + mHeteroCount[1] = 0; mScore[0] = 0; mScore[1] = 0; mLastKickOffGameHalf = GH_NONE; mNextHalfKickOff = TI_NONE; mLeftInit = Vector3f(0,0,0); mRightInit = Vector3f(0,0,0); + mAgentRadius = 3.5; mFinished = false; mGamePaused = true; + mMaxHeteroTypeCount = 3; + mMaxTotalHeteroCount = 9; } GameStateAspect::~GameStateAspect() @@ -266,6 +273,82 @@ } bool +GameStateAspect::InsertRobotType(TTeamIndex idx, int type) +{ + int i; + + switch (idx) + { + case TI_LEFT: + i = 0; + break; + case TI_RIGHT: + i = 1; + break; + default: + return false; + } + + if (type) // heterogeneous player + { + if (mHeteroCount[i] == mMaxTotalHeteroCount) + { + GetLog()->Error() + << "ERROR: (GameStateAspect::InsertRobotType) Hetero player" + " count limit reached.\n"; + return false; + } + + ++mHeteroCount[i]; + + if (mRobotTypeCount[i].size() <= type) + mRobotTypeCount[i].resize(type+1); + + if (mRobotTypeCount[i][type] == mMaxHeteroTypeCount) + { + GetLog()->Error() + << "ERROR: (GameStateAspect::InsertRobotType) No more robots " + "of type " << type << " are allowed.\n"; + return false; + } + } + + ++mRobotTypeCount[i][type]; + + return true; +} + +bool +GameStateAspect::EraseRobotType(TTeamIndex idx, int type) +{ + int i; + + switch (idx) + { + case TI_LEFT: + i = 0; + break; + case TI_RIGHT: + i = 1; + break; + default: + return false; + } + + if (mRobotTypeCount[i].size() <= type || !mRobotTypeCount[i][type]) + { + return false; + } + + if (type) // heterogeneous player + --mHeteroCount[i]; + + --mRobotTypeCount[i][type]; + + return true; +} + +bool GameStateAspect::RequestUniform(boost::shared_ptr<AgentState> agentState, std::string teamName, unsigned int unum) { @@ -297,6 +380,15 @@ return false; } + if (!InsertRobotType(idx, agentState->GetRobotType())) + { + GetLog()->Error() + << "ERROR: (GameStateAspect::RequestUniform) cannot insert robot" + " of type " << agentState->GetRobotType() << " to team " + << teamName << "\n"; + return false; + } + agentState->SetUniformNumber(unum); agentState->SetTeamIndex(idx); //agentState->SetPerceptName(teamName, ObjectState::PT_Default); @@ -311,7 +403,7 @@ } bool -GameStateAspect::ReturnUniform(TTeamIndex ti, unsigned int unum) +GameStateAspect::ReturnUniform(TTeamIndex ti, unsigned int unum, int type) { if (! EraseUnum(ti,unum)) { @@ -321,6 +413,14 @@ return false; } + if (!EraseRobotType(ti, type)) + { + GetLog()->Error() + << "ERROR: (GameStateAspect::ReturnUniform) cannot erase robot " + " type " << type << " from team " << ti << "\n"; + return false; + } + return true; } @@ -445,6 +545,9 @@ SoccerBase::GetSoccerVar(*this, "CoinTossForKickOff", coinTossKickOff); if (!coinTossKickOff) mNextHalfKickOff = TI_LEFT; + + SoccerBase::GetSoccerVar(*this, "MaxHeteroTypeCount", mMaxHeteroTypeCount); + SoccerBase::GetSoccerVar(*this, "MaxTotalHeteroCount", mMaxTotalHeteroCount); } int Modified: trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.h =================================================================== --- trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.h 2013-06-05 20:03:19 UTC (rev 354) +++ trunk/rcssserver3d/plugin/soccer/gamestateaspect/gamestateaspect.h 2013-06-08 21:23:54 UTC (rev 355) @@ -24,6 +24,7 @@ #include <soccercontrolaspect/soccercontrolaspect.h> #include <set> +#include <vector> class AgentState; @@ -87,7 +88,7 @@ std::string teamName, unsigned int unum); /** notifies that a uniform number is free again */ - bool ReturnUniform(TTeamIndex ti, unsigned int unum); + bool ReturnUniform(TTeamIndex ti, unsigned int unum, int type); /** returns the next uniform number not taken for the given team */ int RequestUniformNumber(TTeamIndex ti) const; @@ -133,6 +134,18 @@ contain a uniform number unum and erases it. */ bool EraseUnum(TTeamIndex idx, int unum); + /** + * Adds a robot of the given type to the given team if permitted. + * @return true if permitted + */ + bool InsertRobotType(TTeamIndex idx, int type); + + /** + * Removes a robot of the given type from the given team if exists. + * @return true on success + */ + bool EraseRobotType(TTeamIndex idx, int type); + /** returns the team index corresponding to the given teamName. If the teamname does not exist and less than two teams are registered, the given team name is registered. @@ -170,6 +183,12 @@ /** the set of uniform number for each team */ TUnumSet mUnumSet[2]; + /** the array of robot type counts for each team */ + std::vector<int> mRobotTypeCount[2]; + + /** the number of heterogeneous players for each team */ + int mHeteroCount[2]; + /** the scores of two teams */ int mScore[2]; @@ -187,6 +206,12 @@ /** flag if the game is running or paused (e.g. in goal_left/right state) */ bool mGamePaused; + + /** the maximum number of heterogeneous players of a single type per team */ + int mMaxHeteroTypeCount; + + /** the maximum number of total heterogeneous players for a team */ + int mMaxTotalHeteroCount; }; DECLARE_CLASS(GameStateAspect); Modified: trunk/rcssserver3d/rcssserver3d/naosoccersim.rb =================================================================== --- trunk/rcssserver3d/rcssserver3d/naosoccersim.rb 2013-06-05 20:03:19 UTC (rev 354) +++ trunk/rcssserver3d/rcssserver3d/naosoccersim.rb 2013-06-08 21:23:54 UTC (rev 355) @@ -60,6 +60,8 @@ # agent parameters addSoccerVar('AgentRadius', 0.4) +addSoccerVar('MaxHeteroTypeCount', 3) +addSoccerVar('MaxTotalHeteroCount', 9) # ball parameters addSoccerVar('BallRadius', 0.042) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |