|
From: <sgv...@us...> - 2011-03-14 23:17:04
|
Revision: 252
http://simspark.svn.sourceforge.net/simspark/?rev=252&view=rev
Author: sgvandijk
Date: 2011-03-14 23:16:57 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
- New field size
- Players thrown out of panelty area, and wrong kickin side switch bug should be fixed
Modified Paths:
--------------
trunk/rcssserver3d/plugin/soccer/soccerruleaspect/soccerruleaspect.cpp
trunk/rcssserver3d/rcssserver3d/naosoccersim.rb
Modified: trunk/rcssserver3d/plugin/soccer/soccerruleaspect/soccerruleaspect.cpp
===================================================================
--- trunk/rcssserver3d/plugin/soccer/soccerruleaspect/soccerruleaspect.cpp 2011-03-04 00:46:44 UTC (rev 251)
+++ trunk/rcssserver3d/plugin/soccer/soccerruleaspect/soccerruleaspect.cpp 2011-03-14 23:16:57 UTC (rev 252)
@@ -86,17 +86,25 @@
void
SoccerRuleAspect::AutomaticSimpleReferee(TPlayMode playMode)
{
- if (playMode != PM_PlayOn) {
- ResetFaultCounter(TI_LEFT); ResetFaultCounter(TI_RIGHT); //only using automatic refereing in PlayOn
- }
- else {
- CalculateDistanceArrays(TI_LEFT); // Calculates distance arrays for left team
- CalculateDistanceArrays(TI_RIGHT); // Calculates distance arrays for right team
- AnalyseFaults(TI_LEFT); // Analyses simple faults for the left team
- AnalyseFaults(TI_RIGHT); // Analyses simple faults for the right team
- ClearPlayersAutomatic(TI_LEFT); // enforce standing and not overcrowding rules for left team
- ClearPlayersAutomatic(TI_RIGHT); // enforce standing and not overcrowding rules for right team
+ // Reset counters before kickoff
+ if (playMode == PM_BeforeKickOff)
+ {
+ ResetFaultCounter(TI_LEFT);
+ ResetFaultCounter(TI_RIGHT);
}
+ else
+ {
+ CalculateDistanceArrays(TI_LEFT); // Calculates distance arrays for left team
+ CalculateDistanceArrays(TI_RIGHT); // Calculates distance arrays for right team
+ AnalyseFaults(TI_LEFT); // Analyses simple faults for the left team
+ AnalyseFaults(TI_RIGHT); // Analyses simple faults for the right team
+ // Only apply rules during play-on
+ if (playMode == PM_PlayOn)
+ {
+ ClearPlayersAutomatic(TI_LEFT); // enforce standing and not overcrowding rules for left team
+ ClearPlayersAutomatic(TI_RIGHT); // enforce standing and not overcrowding rules for right team
+ }
+ }
}
@@ -123,42 +131,44 @@
void
SoccerRuleAspect::processAgentState(salt::Vector3f pos, int unum, TTeamIndex idx)
{
- float groundZVal = 0.15; //bellow this player is on the ground
- float middleZVal = 0.25; //abovce this player is standing (or trying...)
+ float groundZVal = 0.15; //bellow this player is on the ground
+ float middleZVal = 0.25; //abovce this player is standing (or trying...)
- //increase player not standing if it is not in upward position and inside of field
- if (pos.z() < middleZVal && fabs(pos.y())< mFieldWidth/2 + 0.1) {
- playerNotStanding[unum][idx]++;
- playerStanding[unum][idx]=0; //player not standing
- }
+ //increase player not standing if it is not in upward position and inside of field
+ if (pos.z() < middleZVal && fabs(pos.y())< mFieldWidth / 2 + 0.1)
+ {
+ playerNotStanding[unum][idx]++;
+ playerStanding[unum][idx] = 0; //player not standing
+ }
- //increase player near ground if it is very low and inside of field
- if (pos.z() < groundZVal && fabs(pos.y())< mFieldWidth/2 + 0.1) {
- playerGround[unum][idx]++;
- }
+ //increase player near ground if it is very low and inside of field
+ if (pos.z() < groundZVal && fabs(pos.y())< mFieldWidth / 2 + 0.1)
+ {
+ playerGround[unum][idx]++;
+ }
- //increase player standing or at least trying... Reset ground
- if (pos.z() >= middleZVal) {
- playerStanding[unum][idx]++;
- playerGround[unum][idx]=0;
- }
+ //increase player standing or at least trying... Reset ground
+ if (pos.z() >= middleZVal)
+ {
+ playerStanding[unum][idx]++;
+ playerGround[unum][idx] = 0;
+ }
- //Player standing for some cycles (0.5 seconds) reset not standing count
- if (playerStanding[unum][idx] > 0.5/0.02) {
- playerNotStanding[unum][idx]=0;
- }
-
-// if (playerGround[unum][idx] > 0/0.02)
-// cout << "On the Ground Unum" << unum << " Team: " << idx << " Time: " << playerGround[unum][idx] <<
-// " z= " << pos.z() << endl; //debug
+ //Player standing for some cycles (0.5 seconds) reset not standing count
+ if (playerStanding[unum][idx] > 0.5 / 0.02) {
+ playerNotStanding[unum][idx] = 0;
+ }
}
// Calculates ordering on a distance vector
void SoccerRuleAspect::SimpleOrder(float dArr[][3], int oArr[][3], TTeamIndex idx)
{
- for(int t1=1; t1<=10; t1++)
- for(int t2=t1+1; t2<=11; t2++)
- if (dArr[t1][idx] >= dArr[t2][idx]) oArr[t1][idx]++; else oArr[t2][idx]++;
+ for(int t1 = 1; t1 <= 10; t1++)
+ for(int t2 = t1 + 1; t2 <= 11; t2++)
+ if (dArr[t1][idx] >= dArr[t2][idx])
+ oArr[t1][idx]++;
+ else
+ oArr[t2][idx]++;
// DEBUG
// if (dArr[1][idx]<1000.0) {
@@ -172,53 +182,71 @@
// Calculate Distance arrays and ordering to the ball and own goal
void SoccerRuleAspect::CalculateDistanceArrays(TTeamIndex idx)
{
- if (idx == TI_NONE || mBallState.get() == 0) return;
+ if (idx == TI_NONE || mBallState.get() == 0)
+ return;
std::list<boost::shared_ptr<AgentState> > agent_states;
- if (! SoccerBase::GetAgentStates(*mBallState.get(), agent_states, idx)) return;
+ if (! SoccerBase::GetAgentStates(*mBallState.get(), agent_states, idx))
+ return;
salt::Vector3f ballPos = mBallBody->GetPosition();
- salt::Vector3f ownGoalPos = Vector3f(-mFieldLength/2.0, 0.0, 0.0);
- if (idx==TI_RIGHT) ownGoalPos = Vector3f(mFieldLength/2.0, 0.0, 0.0); //own goal position
+ salt::Vector3f ownGoalPos;
+ if (idx == TI_LEFT)
+ ownGoalPos = Vector3f(-mFieldLength/2.0, 0.0, 0.0);
+ else
+ ownGoalPos = Vector3f(mFieldLength/2.0, 0.0, 0.0);
+
boost::shared_ptr<oxygen::Transform> agent_aspect;
std::list<boost::shared_ptr<AgentState> >::const_iterator i;
- numPlInsideOwnArea[idx] = 0; closestPlayer[idx]=1; closestPlayerDist[idx]=1000.0;
- for(int t=1; t<=11; t++) {
- distArr[t][idx]=1000.0; ordArr[t][idx]=1; distGArr[t][idx]=1000.0; ordGArr[t][idx]=1;
+ numPlInsideOwnArea[idx] = 0;
+ closestPlayer[idx] = 1;
+ closestPlayerDist[idx] = 1000.0;
+ for(int t = 1; t <= 11; t++)
+ {
+ distArr[t][idx]=1000.0;
+ ordArr[t][idx]=1;
+ distGArr[t][idx]=1000.0;
+ ordGArr[t][idx]=1;
}
- for (i = agent_states.begin(); i != agent_states.end(); ++i) {
+ for (i = agent_states.begin(); i != agent_states.end(); ++i)
+ {
SoccerBase::GetTransformParent(**i, agent_aspect);
Vector3f agentPos = agent_aspect->GetWorldTransform().Pos();
int unum = (*i)->GetUniformNumber();
- distArr[unum][idx] = sqrt((agentPos.x()-ballPos.x())*(agentPos.x()-ballPos.x()) +
- (agentPos.y()-ballPos.y())*(agentPos.y()-ballPos.y()));
- distGArr[unum][idx] = sqrt((agentPos.x()-ownGoalPos.x())*(agentPos.x()-ownGoalPos.x()) +
- (agentPos.y()-ownGoalPos.y())*(agentPos.y()-ownGoalPos.y()));
+ distArr[unum][idx] = sqrt((agentPos.x()-ballPos.x())*(agentPos.x()-ballPos.x()) +
+ (agentPos.y()-ballPos.y())*(agentPos.y()-ballPos.y()));
+ distGArr[unum][idx] = sqrt((agentPos.x()-ownGoalPos.x())*(agentPos.x()-ownGoalPos.x()) +
+ (agentPos.y()-ownGoalPos.y())*(agentPos.y()-ownGoalPos.y()));
// determine closest player
- if (distArr[unum][idx] < closestPlayerDist[idx]) {
- closestPlayerDist[idx] = distArr[unum][idx]; closestPlayer[idx] = unum;
- }
+ if (distArr[unum][idx] < closestPlayerDist[idx])
+ {
+ closestPlayerDist[idx] = distArr[unum][idx];
+ closestPlayer[idx] = unum;
+ }
// save player inside area state in previous cycle
- prevPlayerInsideOwnArea[unum][idx] = playerInsideOwnArea[unum][idx];
+ prevPlayerInsideOwnArea[unum][idx] = playerInsideOwnArea[unum][idx];
// determine number of players inside area and set inside area state of player
if (idx == TI_LEFT && mLeftPenaltyArea.Contains(Vector2f(agentPos.x(), agentPos.y())) ||
- idx == TI_RIGHT && mRightPenaltyArea.Contains(Vector2f(agentPos.x(), agentPos.y()))) {
- numPlInsideOwnArea[idx]++;
- playerInsideOwnArea[unum][idx] = 1;
+ idx == TI_RIGHT && mRightPenaltyArea.Contains(Vector2f(agentPos.x(), agentPos.y())))
+ {
+ numPlInsideOwnArea[idx]++;
+ playerInsideOwnArea[unum][idx] = 1;
- //goalie is not repositioned when inside own area...
- if (unum == 1) {
- distGArr[unum][idx] = 0.0;
- }
- }
- else playerInsideOwnArea[unum][idx] = 0;
+ //goalie is not repositioned when inside own area...
+ if (unum == 1)
+ {
+ distGArr[unum][idx] = 0.0;
+ }
+ }
+ else
+ playerInsideOwnArea[unum][idx] = 0;
// Process agent state: standing, sitted, laying down, ...
- processAgentState(agentPos, unum, idx);
+ processAgentState(agentPos, unum, idx);
}
// compute rank of distance to ball
@@ -230,75 +258,58 @@
// Analyse Faults and Creates Fault Time Array
void SoccerRuleAspect::AnalyseFaults(TTeamIndex idx)
{
- TTeamIndex idx2; if (idx == TI_LEFT) idx2 = TI_RIGHT; else idx2 = TI_LEFT; //Other team
- for(int unum=1; unum<=11; unum++) {
-
- //I am the third closest player but i am too near the ball (and not the goalie)
- if ( unum!=1 && closestPlayerDist[idx2] < mMinOppDistance &&
- (distArr[unum][idx] <= mMin3PlDistance+0.01 && ordArr[unum][idx] == 3))
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "Min3Dist " << mMin3PlDistance << " activated - player " << unum << " to be repositioned \n";
- }
- else
- //I am the second closest player but i am too near the ball (and not the goalie)
- if( unum!=1 && closestPlayerDist[idx2] < mMinOppDistance &&
- distArr[unum][idx] <= mMin2PlDistance+0.01 && ordArr[unum][idx] == 2 )
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "Min2Dist " << mMin2PlDistance << " activated - player " << unum << " to be repositioned \n";
- }
- else
- // too many players inside my own penalty area and Im am the last one to enter or
- // the last one to enter was the goalie and I am the one further away from own goal
- if( (numPlInsideOwnArea[idx] > mMaxPlayersInsideOwnArea && unum !=1 && playerInsideOwnArea[unum][idx] == 1 &&
- (prevPlayerInsideOwnArea[unum][idx] == 0 ||
- prevPlayerInsideOwnArea[1][idx] == 0 &&
- playerInsideOwnArea[1][idx] == 1 &&
- mMaxPlayersInsideOwnArea + 1 == ordGArr[unum][idx])))
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "MaxPlInPenalty " << mMaxPlayersInsideOwnArea << " activated - player "
- // << unum << " to be repositioned " << " ord " << ordGArr[unum][idx] << "\n";
- }
- else
- //I am a field player and on the ground for too much time
- if ( unum!=1 && playerGround[unum][idx] > mGroundMaxTime/0.02 )
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "GroundMaxTime " << mGroundMaxTime << " activated - player "
- // << unum << " to be repositioned " << "\n";
- }
- else
- // I am a field player and I am not standing for too much time
- if( unum!=1 && playerNotStanding[unum][idx] > mNotStandingMaxTime/0.02 )
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "StandMaxTime " << mNotStandingMaxTime << " activated - player "
- // << unum << " to be repositioned " << "\n";
- }
+ TTeamIndex idx2;
+ if (idx == TI_LEFT)
+ idx2 = TI_RIGHT;
+ else
+ idx2 = TI_LEFT; //Other team
- else
- //I am the goalie and I am on the ground for too much time
- if ( unum==1 &&
- playerGround[unum][idx] > mGoalieGroundMaxTime/0.02 )
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "GoalieGroundMaxTime " << mGoalieGroundMaxTime << " activated - player "
- // << unum << " to be repositioned " << "\n";
- }
- else
- //I am the goalie and I and not standing for too much time
- if ( unum == 1 && playerNotStanding[unum][idx] > mGoalieNotStandingMaxTime/0.02)
- {
- playerFaultTime[unum][idx]++; //increase player fault time
- //cout << "GoalieStandMaxTime " << mGoalieNotStandingMaxTime << " activated - player "
- // << unum << " to be repositioned " << "\n";
- }
- else {
- playerFaultTime[unum][idx]=0; //reset player fault time
- }
-
+ for(int unum=1; unum<=11; unum++)
+ {
+ // I am the third closest player but i am too near the ball (and not the goalie)
+ if (unum != 1 && closestPlayerDist[idx2] < mMinOppDistance &&
+ (distArr[unum][idx] <= mMin3PlDistance + 0.01 && ordArr[unum][idx] == 3))
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // I am the second closest player but i am too near the ball (and not the goalie)
+ else if(unum != 1 && closestPlayerDist[idx2] < mMinOppDistance &&
+ distArr[unum][idx] <= mMin2PlDistance + 0.01 && ordArr[unum][idx] == 2 )
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // Too many players inside my own penalty area and Im am the last one to enter or
+ // the last one to enter was the goalie and I am the one further away from own goal
+ else if((numPlInsideOwnArea[idx] > mMaxPlayersInsideOwnArea && unum != 1 && playerInsideOwnArea[unum][idx] == 1 &&
+ (prevPlayerInsideOwnArea[unum][idx] == 0 ||
+ (prevPlayerInsideOwnArea[1][idx] == 0 && playerInsideOwnArea[1][idx] == 1 && mMaxPlayersInsideOwnArea + 1 == ordGArr[unum][idx]))))
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // I am a field player and on the ground for too much time
+ else if (unum != 1 && playerGround[unum][idx] > mGroundMaxTime / 0.02)
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // I am a field player and I am not standing for too much time
+ else if(unum!=1 && playerNotStanding[unum][idx] > mNotStandingMaxTime / 0.02)
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // I am the goalie and I am on the ground for too much time
+ else if (unum == 1 && playerGround[unum][idx] > mGoalieGroundMaxTime / 0.02)
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ // I am the goalie and I and not standing for too much time
+ else if (unum == 1 && playerNotStanding[unum][idx] > mGoalieNotStandingMaxTime / 0.02)
+ {
+ playerFaultTime[unum][idx]++;
+ }
+ else
+ {
+ playerFaultTime[unum][idx]=0;
+ }
}
}
@@ -320,28 +331,32 @@
void
SoccerRuleAspect::ClearPlayersAutomatic(TTeamIndex idx)
{
- if (idx == TI_NONE || mBallState.get() == 0) return;
+ if (idx == TI_NONE || mBallState.get() == 0)
+ return;
std::list<boost::shared_ptr<AgentState> > agent_states;
- if (! SoccerBase::GetAgentStates(*mBallState.get(), agent_states, idx)) return;
+ if (! SoccerBase::GetAgentStates(*mBallState.get(), agent_states, idx))
+ return;
salt::Vector3f ballPos = mBallBody->GetPosition();
boost::shared_ptr<oxygen::Transform> agent_aspect;
std::list<boost::shared_ptr<AgentState> >::const_iterator i;
- for (i = agent_states.begin(); i != agent_states.end(); ++i) {
+ for (i = agent_states.begin(); i != agent_states.end(); ++i)
+ {
SoccerBase::GetTransformParent(**i, agent_aspect);
Vector3f agentPos = agent_aspect->GetWorldTransform().Pos();
int unum = (*i)->GetUniformNumber();
- if (playerFaultTime[unum][idx] > mMaxFaultTime/0.02) {
- // I am not a very good soccer player... I am violating the rules...
+ if (playerFaultTime[unum][idx] > mMaxFaultTime / 0.02)
+ {
+ // I am not a very good soccer player... I am violating the rules...
salt::Vector3f new_pos = RepositionOutsidePos(ballPos, unum, idx);
- //Calculate my Reposition pos outside of the field
+ //Calculate my Reposition pos outside of the field
SoccerBase::MoveAgent(agent_aspect, new_pos);
- //Oh my God!! I am flying!! I am going outside of the field
- ResetFaultCounterPlayer(unum, idx);
- //cout << "*********Player Repos Num: " << unum << " Team: " << team << " Pos: " << new_pos << endl;
+ //Oh my God!! I am flying!! I am going outside of the field
+ ResetFaultCounterPlayer(unum, idx);
+ //cout << "*********Player Repos Num: " << unum << " Team: " << team << " Pos: " << new_pos << endl;
}
}
}
@@ -665,7 +680,7 @@
// after the first agent touches the ball move to PM_PLAY_ON. the
// time when the agent last touches the ball must be after the
- // change to the KickIn mode
+ // change to the KickIn mode *plus* pause time
boost::shared_ptr<AgentAspect> agent;
TTime time;
if (! mBallState->GetLastCollidingAgent(agent,time))
@@ -675,7 +690,7 @@
}
TTime lastChange = mGameState->GetLastModeChange();
- if (time > lastChange)
+ if (time > lastChange + mKickInPauseTime)
{
mGameState->SetPlayMode(PM_PlayOn);
GetLog()->Error() << "ERROR: (SoccerRuleAspect) " << "Set Playmode to playon\n";
@@ -745,7 +760,7 @@
}
TTime lastChange = mGameState->GetLastModeChange();
- if (time > lastChange)
+ if (time > lastChange + mKickInPauseTime)
{
mGameState->SetPlayMode(PM_PlayOn);
GetLog()->Error() << "ERROR: (SoccerRuleAspect) " << "Set Playmode to playon\n";
@@ -794,7 +809,7 @@
TTime lastChange = mGameState->GetLastModeChange();
// if the team with the goal kick touched the ball and the ball is
// outside the penalty area, we switch to play on.
- if (time > lastChange)
+ if (time > lastChange + mKickInPauseTime)
{
Vector2f pos(mBallBody->GetPosition().x(),
mBallBody->GetPosition().y());
@@ -840,7 +855,7 @@
// after the first agent touches the ball move to PM_PLAY_ON. the
// time when the agent last touches the ball must be after the
- // change to the KickIn mode
+ // change to the KickIn mode *plus* pause time
boost::shared_ptr<AgentAspect> agent;
TTime time;
if (! mBallState->GetLastCollidingAgent(agent,time))
@@ -849,7 +864,7 @@
}
TTime lastChange = mGameState->GetLastModeChange();
- if (time > lastChange)
+ if (time > lastChange + mKickInPauseTime)
{
mGameState->SetPlayMode(PM_PlayOn);
} else
Modified: trunk/rcssserver3d/rcssserver3d/naosoccersim.rb
===================================================================
--- trunk/rcssserver3d/rcssserver3d/naosoccersim.rb 2011-03-04 00:46:44 UTC (rev 251)
+++ trunk/rcssserver3d/rcssserver3d/naosoccersim.rb 2011-03-14 23:16:57 UTC (rev 252)
@@ -37,8 +37,8 @@
end
# the soccer field dimensions in meters
-addSoccerVar('FieldLength', 18.0)
-addSoccerVar('FieldWidth', 12.0)
+addSoccerVar('FieldLength', 21.0)
+addSoccerVar('FieldWidth', 14.0)
addSoccerVar('FieldHeight', 40.0)
addSoccerVar('GoalWidth', 2.1)
addSoccerVar('GoalDepth', 0.6)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|