player_type.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_PARAM_PLAYER_TYPE_H
00033 #define RCSC_PARAM_PLAYER_TYPE_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/rcg/types.h>
00037 #include <rcsc/soccer_math.h>
00038 #include <rcsc/types.h>
00039 
00040 #include <map>
00041 #include <vector>
00042 #include <iostream>
00043 
00044 namespace rcsc {
00045 
00046 class ServerParam;
00047 
00052 class PlayerType {
00053 private:
00054     int M_id;
00055     double M_player_speed_max;
00056     double M_stamina_inc_max;
00057     double M_player_decay;
00058     double M_inertia_moment;
00059     double M_dash_power_rate;
00060     double M_player_size;
00061     double M_kickable_margin;
00062     double M_kick_rand;
00063     double M_extra_stamina;
00064     double M_effort_max;
00065     double M_effort_min;
00066 
00067     // additional parameters
00068 
00069     double M_kickable_area;
00070 
00071     // if player's dprate & effort is not enough,
00072     // player never reach player_speed_max
00073     double M_real_speed_max;
00074 
00075     double M_player_speed_max2; // squared value
00076     double M_real_speed_max2;   // squared value
00077 
00079     int M_cycles_to_reach_max_speed;
00080 
00082     std::vector< double > M_dash_distance_table;
00083 
00084     // stamina cconsumption table by continuous dashes
00085     //std::vector< double > M_stamina_table;
00086 
00087 public:
00093     PlayerType()
00094         : M_id( Hetero_Unknown )
00095       { }
00096 
00113     PlayerType( const ServerParam & sparam,
00114                 const int id,
00115                 const double & pspdmax,
00116                 const double & sincmax,
00117                 const double & pdecay,
00118                 const double & imoment,
00119                 const double & dprate,
00120                 const double & psize,
00121                 const double & kmargin,
00122                 const double & krand,
00123                 const double & estamina,
00124                 const double & effmax,
00125                 const double & effmin );
00126 
00131     explicit
00132     PlayerType( const ServerParam & sparam );
00133 
00140     PlayerType( const ServerParam & sparam,
00141                 const char * msg,
00142                 const double & version );
00143 
00149     PlayerType( const ServerParam & sparam,
00150                 const rcg::player_type_t & from );
00151 
00156     void convertTo( rcg::player_type_t & to ) const;
00157 
00162     std::string toStr() const;
00163 
00164 private:
00165 
00170     void parseV8( const char * msg );
00171 
00176     void parseV7( const char * msg );
00177 
00182     void initAdditionalParams( const ServerParam & sparam );
00183 
00184 public:
00185 
00186     int id() const
00187       {
00188           return M_id;
00189       }
00190     const
00191     double & playerSpeedMax() const
00192       {
00193           return M_player_speed_max;
00194       }
00195     const
00196     double & staminaIncMax() const
00197       {
00198           return M_stamina_inc_max;
00199       }
00200     const
00201     double & playerDecay() const
00202       {
00203           return M_player_decay;
00204       }
00205     const
00206     double & inertiaMoment() const
00207       {
00208           return M_inertia_moment;
00209       }
00210     const
00211     double & dashPowerRate() const
00212       {
00213           return M_dash_power_rate;
00214       }
00215     const
00216     double & playerSize() const
00217       {
00218           return M_player_size;
00219       }
00220     const
00221     double & kickableMargin() const
00222       {
00223           return M_kickable_margin;
00224       }
00225     const
00226     double & kickRand() const
00227       {
00228           return M_kick_rand;
00229       }
00230     const
00231     double & extraStamina() const
00232       {
00233           return M_extra_stamina;
00234       }
00235     const
00236     double & effortMax() const
00237       {
00238           return M_effort_max;
00239       }
00240     const
00241     double & effortMin() const
00242       {
00243           return M_effort_min;
00244       }
00245 
00247     // additional parameters
00248 
00249     const
00250     double & kickableArea() const
00251       {
00252           return M_kickable_area;
00253       }
00254     const
00255     double & realSpeedMax() const
00256       {
00257           return M_real_speed_max;
00258       }
00259     const
00260     double & playerSpeedMax2() const
00261       {
00262           return M_player_speed_max2;
00263       }
00264     const
00265     double & realSpeedMax2() const
00266       {
00267           return M_real_speed_max2;
00268       }
00269 
00274     const
00275     std::vector< double > & dashDistanceTable() const
00276       {
00277           return M_dash_distance_table;
00278       }
00279 
00281 
00289     int getMaxDashCyclesSavingStamina( const ServerParam & sparam,
00290                                        const double & dash_power,
00291                                        const double & current_stamina,
00292                                        const double & current_recovery ) const;
00293 
00294     /*
00295       \brief estimate the number of available dashes with max power
00296       \param stamina available stamina
00297       \return estimated cycle
00298      */
00299     //int maxDashCyclesWith( const double & stamina ) const;
00300 
00301     /*
00302       \brief get the consumed stamina value after nr dashes with the max power
00303       from the velocity 0.
00304       \param n_dash dash count
00305       \return consumed stamina value
00306 
00307       this method can be used when player's recover is not decayed.
00308      */
00309     //double consumedStaminaAfterNrDash( const int n_dash ) const;
00310 
00312 
00317     int cyclesToReachMaxSpeed( const double & dash_power ) const;
00318 
00325     int cyclesToReachMaxSpeed() const
00326       {
00327           return M_cycles_to_reach_max_speed;
00328       }
00330 
00335     int cyclesToReachDistance( const double & dash_dist ) const;
00337 
00343     bool canOverSpeedMax( const double & dash_power,
00344                           const double & effort ) const
00345       {
00346           return ( std::fabs( dash_power ) * dashPowerRate() * effort
00347                    > playerSpeedMax() * ( 1.0 - playerDecay() ) );
00348       }
00350 
00356     double getDashPowerToKeepMaxSpeed( const ServerParam & sparam,
00357                                        const double & effort ) const;
00358 
00364     double getDashPowerToKeepMaxSpeed( const ServerParam & sparam ) const
00365       {
00366           return getDashPowerToKeepMaxSpeed( sparam, effortMax() );
00367       }
00368 
00375     double getDashPowerToKeepSpeed( const double & speed,
00376                                     const double & effort ) const
00377       {
00378           return speed * ( ( 1.0 - playerDecay() )
00379                            / (dashPowerRate() * effort ) );
00380       }
00381 
00387     double getOneStepStaminaComsumption( const ServerParam & sparam ) const
00388       {
00389           return getDashPowerToKeepMaxSpeed( sparam, effortMax() ) - staminaIncMax();
00390       }
00391 
00392 
00394 
00401     double kickRate( const ServerParam & sparam,
00402                      const double & ball_dist,
00403                      const double & dir_diff ) const;
00404 
00410     double dashRate( const double & effort ) const
00411       {
00412           return effort * dashPowerRate();
00413       }
00414 
00421     double effectiveTurn( const double & command_moment,
00422                           const double & speed ) const
00423       {
00424           return command_moment / ( 1.0 + inertiaMoment() * speed );
00425       }
00426 
00433     double finalSpeed( const double & dash_power,
00434                        const double & effort ) const
00435       {
00436           return std::min( playerSpeedMax(),
00437                            ( ( std::fabs(dash_power) * dashPowerRate() * effort ) // == accel
00438                              / ( 1.0 - playerDecay() ) ) ); // sum inf geom series
00439       }
00441 
00447     Vector2D inertiaTravel( const Vector2D & initial_vel,
00448                             const int n_step ) const
00449       {
00450           return inertia_n_step_travel( initial_vel, n_step, playerDecay() );
00451       }
00452 
00460     Vector2D inertiaPoint( const Vector2D & initial_pos,
00461                            const Vector2D & initial_vel,
00462                            const int n_step ) const
00463       {
00464           return inertia_n_step_point( initial_pos,
00465                                        initial_vel,
00466                                        n_step,
00467                                        playerDecay() );
00468       }
00469 
00475     Vector2D inertiaFinalTravel( const Vector2D & initial_vel ) const
00476       {
00477           return inertia_final_travel( initial_vel, playerDecay() );
00478       }
00479 
00486     Vector2D inertiaFinalPoint( const Vector2D & initial_pos,
00487                                 const Vector2D & initial_vel ) const
00488       {
00489           return inertia_final_point( initial_pos, initial_vel, playerDecay() );
00490       }
00491 
00493 
00500     bool normalizeAccel( const Vector2D & velocity,
00501                          const AngleDeg & accel_angle,
00502                          double * accel_mag ) const;
00503 
00510     bool normalizeAccel( const Vector2D & velocity,
00511                          Vector2D * accel ) const;
00513 
00521     void predictStaminaAfterWait( const ServerParam & sparam,
00522                                   const int n_wait,
00523                                   double * stamina,
00524                                   double * effort,
00525                                   const double & recovery ) const;
00526 
00535     void predictStaminaAfterDash( const ServerParam & sparam,
00536                                   const double & dash_power,
00537                                   double * stamina,
00538                                   double * effort,
00539                                   double * recovery ) const;
00540 
00550     void predictStaminaAfterNrDash( const ServerParam & sparam,
00551                                     const double & dash_power,
00552                                     const int n_dash,
00553                                     double * stamina,
00554                                     double * effort,
00555                                     double * recovery ) const;
00556 
00562     std::ostream & print( std::ostream & os ) const;
00563 };
00564 
00565 
00569 
00574 class PlayerTypeSet {
00575 public:
00577     typedef std::map< int, PlayerType > PlayerTypeMap;
00578 private:
00580     PlayerTypeMap M_player_type_map;
00581 
00583     PlayerType M_dummy_type;
00584 
00588     PlayerTypeSet();
00589 
00590 public:
00594     ~PlayerTypeSet();
00595 
00600     static
00601     PlayerTypeSet & instance();
00602 
00607     inline
00608     static
00609     const
00610     PlayerTypeSet & i()
00611       {
00612           return instance();
00613       }
00614 
00619     void resetDefaultType( const ServerParam & sparam );
00620 
00625     void insert( const PlayerType & param );
00626 
00627 private:
00634     void createDummyType();
00635 
00636 public:
00637 
00642     const
00643     PlayerTypeMap & playerTypeMap() const
00644       {
00645           return M_player_type_map;
00646       }
00647 
00652     const
00653     PlayerType & dummyType() const
00654       {
00655           return M_dummy_type;
00656       }
00657 
00663     const
00664     PlayerType * get( const int id ) const;
00665 
00671     std::ostream & print( std::ostream & os ) const;
00672 };
00673 
00674 }
00675 
00676 #endif

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