player_object.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_PLAYER_OBJECT_H
00033 #define RCSC_PLAYER_PLAYER_OBJECT_H
00034 
00035 #include <rcsc/player/abstract_player_object.h>
00036 
00037 #include <rcsc/player/localization.h>
00038 #include <rcsc/player/fullstate_sensor.h>
00039 
00040 #include <rcsc/geom/vector_2d.h>
00041 #include <rcsc/geom/angle_deg.h>
00042 #include <rcsc/types.h>
00043 
00044 #include <functional>
00045 
00046 namespace rcsc {
00047 
00052 class PlayerObject
00053     : public AbstractPlayerObject {
00054 private:
00056     static int S_pos_count_thr;
00058     static int S_vel_count_thr;
00060     static int S_face_count_thr;
00061 
00062     double M_dist_from_self; 
00063     AngleDeg M_angle_from_self; 
00064 
00065     int M_ghost_count; 
00066 
00067     Vector2D M_rpos; 
00068     int M_rpos_count; 
00069 
00070     AngleDeg M_pointto_angle; 
00071     int M_pointto_count; 
00072 
00073     int M_tackle_count; 
00074 public:
00075 
00079     PlayerObject();
00080 
00086     PlayerObject( const SideID side,
00087                   const Localization::PlayerT & p );
00088 
00092     ~PlayerObject()
00093       { }
00094 
00101     static
00102     void set_count_thr( const int pos_thr,
00103                         const int vel_thr,
00104                         const int face_thr );
00105 
00106     // ------------------------------------------
00107 
00112     const
00113     double & distFromSelf() const
00114       {
00115           return M_dist_from_self;
00116       }
00117 
00122     const
00123     AngleDeg & angleFromSelf() const
00124       {
00125           return M_angle_from_self;
00126       }
00127 
00132     bool isGhost() const
00133       {
00134           return M_ghost_count > 0;
00135       }
00136 
00141     int ghostCount() const
00142       {
00143           return M_ghost_count;
00144       }
00145 
00150     const
00151     Vector2D & rpos() const
00152       {
00153           return M_rpos;
00154       }
00155 
00160     const
00161     AngleDeg & pointtoAngle() const
00162       {
00163           return M_pointto_angle; // global pointing angle
00164       }
00165 
00170     int pointtoCount() const
00171       {
00172           return M_pointto_count;
00173       }
00174 
00179     int tackleCount() const
00180       {
00181           return M_tackle_count;
00182       }
00183 
00188     bool isTackling() const;
00189 
00190 
00195     bool posValid() const
00196       {
00197           return M_pos_count < S_pos_count_thr;
00198       }
00199 
00204     bool rposValid() const
00205       {
00206           return M_rpos_count < S_pos_count_thr;
00207       }
00208 
00213     bool velValid() const
00214       {
00215           return M_vel_count < S_vel_count_thr;
00216       }
00217 
00222     bool bodyValid() const
00223       {
00224           return M_body_count < S_face_count_thr;
00225       }
00226 
00231     bool faceValid() const
00232       {
00233           return M_face_count < S_face_count_thr;
00234       }
00235 
00241     bool isKickable( const double & buf = 0.05 ) const;
00242 
00243     // ------------------------------------------
00247     void update();
00248 
00252     void setGhost()
00253       {
00254           ++M_ghost_count;
00255       }
00256 
00262     void updateBySee( const SideID side,
00263                       const Localization::PlayerT & p );
00264 
00271     void updateByFullstate( const FullstateSensor::PlayerT & p,
00272                             const Vector2D & self_pos,
00273                             const Vector2D & ball_pos );
00274 
00282     void updateByHear( const SideID heard_side,
00283                        const int heard_unum,
00284                        const bool goalie,
00285                        const Vector2D & heard_pos );
00286 
00294     void updateByHear( const SideID heard_side,
00295                        const int heard_unum,
00296                        const bool goalie,
00297                        const Vector2D & heard_pos,
00298                        const AngleDeg & heard_body );
00299 
00307     void updateSelfBallRelated( const Vector2D & self,
00308                                 const Vector2D & ball );
00309 
00313     void forget();
00314 
00316 
00319     class UpdateOp
00320         : public std::unary_function< PlayerObject, void > {
00321     public:
00322         result_type operator()( argument_type & player )
00323           {
00324               player.update();
00325           }
00326     };
00327 
00331     class IsInvalidOp
00332         : public std::unary_function< PlayerObject, bool > {
00333     public:
00334         result_type operator()( const argument_type & player ) const
00335           {
00336               return ( ! player.posValid() );
00337           }
00338     };
00339 
00341 
00344     class CountCmp
00345         : public std::binary_function< PlayerObject, PlayerObject, bool > {
00346     public:
00347         result_type operator()( const first_argument_type & lhs,
00348                                 const second_argument_type & rhs ) const
00349           {
00350               if ( lhs.goalie() ) return true;
00351               if ( rhs.goalie() ) return false;
00352               return lhs.posCount() < rhs.posCount();
00353           }
00354     };
00355 
00359     class PtrCountCmp
00360         : public std::binary_function< PlayerObject *, PlayerObject *, bool > {
00361     public:
00362         result_type operator()( const first_argument_type lhs,
00363                                 const second_argument_type rhs ) const
00364           {
00365               if ( lhs->goalie() ) return true;
00366               if ( rhs->goalie() ) return false;
00367               return lhs->posCount() < rhs->posCount();
00368           }
00369     };
00370 
00372 
00375     class PtrSelfDistCmp
00376         : public std::binary_function< PlayerObject *, PlayerObject *, bool > {
00377     public:
00378         result_type operator()( const first_argument_type lhs,
00379                                 const second_argument_type rhs ) const
00380           {
00381               return lhs->distFromSelf() < rhs->distFromSelf();
00382           }
00383     };
00384 
00388     class PtrBallDistCmp
00389         : public std::binary_function< PlayerObject *, PlayerObject *, bool > {
00390     public:
00391         result_type operator()( const first_argument_type lhs,
00392                                 const second_argument_type rhs ) const
00393           {
00394               return lhs->distFromBall() < rhs->distFromBall();
00395           }
00396     };
00397 
00398 };
00399 
00401 typedef std::list< PlayerObject > PlayerCont;
00403 typedef std::vector< PlayerObject * > PlayerPtrCont;
00404 
00405 }
00406 
00407 #endif

librcscに対してThu May 1 15:41:21 2008に生成されました。  doxygen 1.5.0