00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00063 #include "AmIFirstToBall.h"
00064 #include "view_constants.h"
00065
00066
00067 RS_BEGIN_NAMESPACE
00068
00069
00070 AmIFirstToBall::AmIFirstToBall(bool includeTeammates, float assumedSpeed)
00071 : Predicate(), agentView(NULL), ballView(NULL), playerView(NULL), includeTeammates(includeTeammates),assumedSpeed(assumedSpeed)
00072 {
00073 getView(ballView, BALL_VIEW_ID);
00074 getView(agentView, AGENT_VIEW_ID);
00075 getView(playerView, PLAYER_VIEW_ID);
00076 }
00077
00078
00079 AmIFirstToBall::AmIFirstToBall(const AmIFirstToBall& obj)
00080 : Predicate(obj), agentView(NULL), ballView(NULL), playerView(NULL)
00081 {
00082 getView(ballView, BALL_VIEW_ID);
00083 getView(agentView, AGENT_VIEW_ID);
00084 getView(playerView, PLAYER_VIEW_ID);
00085 includeTeammates = obj.includeTeammates;
00086 assumedSpeed = obj.assumedSpeed;
00087 }
00088
00089
00090 AmIFirstToBall::~AmIFirstToBall()
00091 {
00092 viewManager->releaseView(BALL_VIEW_ID);
00093 viewManager->releaseView(AGENT_VIEW_ID);
00094 viewManager->releaseView(PLAYER_VIEW_ID);
00095 }
00096
00097
00098 AmIFirstToBall& AmIFirstToBall::operator= (const AmIFirstToBall& obj)
00099 {
00100 if ( this != &obj ) {
00101 Predicate::operator=(obj);
00102 }
00103 ballView = obj.ballView;
00104 agentView = obj.agentView;
00105 playerView = obj.playerView;
00106 includeTeammates = obj.includeTeammates;
00107 assumedSpeed = obj.assumedSpeed;
00108
00109 return *this;
00110 }
00111
00112
00113 FuzzyBool AmIFirstToBall::evaluate()
00114 {
00115 PointUE myPos, ballPos;
00116 VectorUE ballSpeed;
00117 float staminaEffect = 1;
00118 float myTimeToBall;
00119 myPos = agentView->getPosition();
00120 ballPos = ballView->getPosition();
00121 ballSpeed = ballView->getSpeedVector();
00122 if (myPos.isUnknown()){
00123 return FuzzyBool(0.5);
00124 }
00125 if (ballPos.isUnknown()){
00126 return FuzzyBool(0.5);
00127 }
00128 if (ballSpeed.isUnknown()){
00129 ballSpeed = VectorUE(0,0);
00130 }
00131 std::vector<PlayerObject> others = playerView->getOpponents();
00132 if (includeTeammates){
00133 for (std::vector<PlayerObject>::const_iterator i = playerView->getTeammates().begin();
00134 i != playerView->getTeammates().end(); i++)
00135 others.push_back(*i);
00136 for (std::vector<PlayerObject>::const_iterator i = playerView->getUnknownPlayers().begin();
00137 i != playerView->getUnknownPlayers().end(); i++)
00138 others.push_back(*i);
00139 }
00140
00141 if (others.empty()) {
00142
00143 return FuzzyBool(1.0);
00144 }
00145
00146 Vector ballToPlayer(ballPos.getPoint(),myPos.getPoint());
00147 float relativeBallSpeed = ballToPlayer.dotProduct(ballSpeed.getVector());
00148
00149
00150
00151
00152
00153
00154
00155 myTimeToBall = ballToPlayer.getLength() /
00156 ((assumedSpeed + relativeBallSpeed)*staminaEffect);
00157 if(myTimeToBall<0)
00158 return FuzzyBool(0.0);
00159
00160 std::cerr << "first: MyTime: " << myTimeToBall << std::endl;
00161
00162
00163 for (std::vector<PlayerObject>::const_iterator o = others.begin();
00164 o != others.end(); o++){
00165
00166 PointUE oPos = o->getPosition();
00167
00168
00169
00170 if (oPos.isKnown()){
00171 Vector ballToOpponent(ballPos.getPoint(),oPos.getPoint());
00172 float relativeBallSpeed = ballToOpponent.dotProduct(ballSpeed.getVector());
00173 float hisTimeToBall = ballToOpponent.getLength() /
00174 (assumedSpeed + relativeBallSpeed);
00175
00176 if(hisTimeToBall > 0 && hisTimeToBall < myTimeToBall)
00177 return FuzzyBool(0.0);
00178 }
00179 }
00180
00181
00182 return FuzzyBool(1.0);
00183 }
00184
00185
00186 void AmIFirstToBall::update(const UInt32)
00187 {
00188 }
00189
00190
00191 RS_END_NAMESPACE
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 #ifndef RS_USE_INLINE
00206 # include "AmIFirstToBall.icc"
00207 #endif