formation.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_FORMATION_FORMATION_H
00033 #define RCSC_FORMATION_FORMATION_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 
00037 #include <boost/shared_ptr.hpp>
00038 
00039 #include <string>
00040 #include <list>
00041 #include <vector>
00042 #include <iostream>
00043 
00044 namespace rcsc {
00045 
00050 class Formation {
00051 public:
00052 
00053     enum SideType {
00054         SIDE = -1, 
00055         SYNMETRY = 1, 
00056         CENTER = 0, 
00057     };
00058 
00063     struct Snapshot {
00064         Vector2D ball_; 
00065         std::vector< Vector2D > players_; 
00066 
00067         Snapshot()
00068           {
00069               players_.reserve( 11 );
00070           }
00071 
00072         Snapshot( const Vector2D & ball,
00073                   const std::vector< Vector2D > & players )
00074             : ball_( ball )
00075             , players_( players )
00076           { }
00077     };
00078 
00079 protected:
00080 
00088     int M_synmetry_number[11];
00089 
00090 
00091 public:
00092 
00096     Formation();
00097 
00098 
00099     virtual
00100     ~Formation()
00101       { }
00102 
00107     virtual
00108     Snapshot createDefaultParam() = 0;
00109 
00114     virtual
00115     std::string methodName() const = 0;
00116 
00122     bool isSideType( const int unum ) const
00123       {
00124           if ( unum < 1 || 11 < unum ) return false;
00125           return ( M_synmetry_number[unum - 1] < 0 );
00126       }
00127 
00133     bool isCenterType( const int unum ) const
00134       {
00135           if ( unum < 1 || 11 < unum ) return false;
00136           return ( M_synmetry_number[unum - 1] == 0 );
00137       }
00138 
00144     bool isSynmetryType( const int unum ) const
00145       {
00146           if ( unum < 1 || 11 < unum ) return false;
00147           return ( M_synmetry_number[unum - 1] > 0 );
00148       }
00149 
00156     int getSynmetryNumber( const int unum ) const
00157       {
00158           if ( unum < 1 || 11 < unum ) return 0;
00159           return M_synmetry_number[unum - 1];
00160       }
00161 
00162     //--------------------------------------------------------------
00163 
00172     bool updateRole( const int unum,
00173                      const int synmetry_unum,
00174                      const std::string & role_name );
00175 
00176 protected:
00177 
00184     virtual
00185     void createNewRole( const int unum,
00186                         const std::string & role_name,
00187                         const SideType type ) = 0;
00188 
00194     virtual
00195     void setRoleName( const int unum,
00196                       const std::string & name ) = 0;
00197 
00198 
00203     void setCenterType( const int unum );
00204 
00209     void setSideType( const int unum );
00210 
00216     bool setSynmetryType( const int unum,
00217                           const int synmetry_unum );
00218 
00219 public:
00220 
00227     virtual
00228     std::string getRoleName( const int unum ) const = 0;
00229 
00235     virtual
00236     Vector2D getPosition( const int unum,
00237                           const Vector2D & focus_point ) const = 0;
00238     /*
00239       \brief get all positions for the current focus point
00240       \param focus_point current focus point, usually ball position
00241       \param positions contaner to store the result
00242      */
00243     virtual
00244     void getPositions( const Vector2D & focus_point,
00245                        std::vector< Vector2D > & positions ) const = 0;
00246 
00251     virtual
00252     void train( const std::list< Snapshot > & train_data ) = 0;
00253 
00259     virtual
00260     bool read( std::istream & is ) = 0;
00261 
00267     virtual
00268     std::ostream & print( std::ostream & os ) const = 0;
00269 
00270 
00271 protected:
00272 
00279     int readName( std::istream & is );
00280 
00286     std::ostream & printName( std::ostream & os ) const;
00287 
00288 };
00289 
00293 typedef boost::shared_ptr< Formation > FormationPtr;
00294 
00295 }
00296 
00297 #endif

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