formation_sbsp.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_SBSP_H
00033 #define RCSC_FORMATION_FORMATION_SBSP_H
00034 
00035 #include <rcsc/formation/formation.h>
00036 #include <rcsc/geom/rect_2d.h>
00037 #include <boost/array.hpp>
00038 
00039 namespace rcsc {
00040 
00045 class FormationSBSP
00046     : public Formation {
00047 public:
00048 
00053     struct Role {
00054         int number_; 
00055         int synmetry_; 
00056         std::string name_; 
00057         Vector2D pos_; 
00058         Vector2D attract_; 
00059         Rect2D region_; 
00060         bool behind_ball_; 
00061 
00062         Role();
00063 
00064         Role( const Vector2D & attract,
00065               const Rect2D & region,
00066               const bool behind_ball );
00067 
00068         void randomize();
00069 
00070         bool read( std::istream & is );
00071 
00072         std::ostream & print( std::ostream & os ) const;
00073     };
00074 
00079     class Param {
00080     private:
00081         std::string M_name; 
00082         boost::array< Role, 11 > M_roles; 
00083 
00084         Param(); // not used
00085     public:
00086 
00087         explicit
00088         Param( const std::string & name )
00089             : M_name( name )
00090           { }
00091 
00092         int getSynmetry( const int unum ) const
00093           {
00094               return M_roles.at( unum - 1 ).synmetry_;
00095           }
00096 
00097         Role & getRole( const int unum )
00098           {
00099               return M_roles.at( unum - 1 );
00100           }
00101 
00102         const
00103         Role & getRole( const int unum ) const
00104           {
00105               return M_roles.at( unum - 1 );
00106           }
00107 
00108 
00109         Vector2D getPosition( const int unum,
00110                               const Vector2D & ball_pos ) const;
00111 
00112 
00113         bool check();
00114 
00115         void createSynmetryParam();
00116 
00117         bool read( std::istream & is );
00118 
00119         std::ostream & print( std::ostream & os ) const;
00120 
00121     };
00122 
00123 
00124 private:
00125 
00126     Param M_param;
00127 
00128 public:
00129 
00133     FormationSBSP();
00134 
00139     static
00140     std::string name()
00141       {
00142           return std::string( "SBSP" );
00143       }
00144 
00149     static
00150     Formation * create()
00151       {
00152           return ( new FormationSBSP );
00153       }
00154 
00155     //--------------------------------------------------------------
00156 
00161     virtual
00162     std::string methodName() const
00163       {
00164           return FormationSBSP::name();
00165       }
00166 
00167 
00172     virtual
00173     Snapshot createDefaultParam();
00174 
00175 protected:
00176 
00182     virtual
00183     void setRoleName( const int unum,
00184                       const std::string & name );
00185 
00192     virtual
00193     void createNewRole( const int unum,
00194                         const std::string & role_name,
00195                         const SideType type );
00196 
00197 public:
00198 
00205     virtual
00206     std::string getRoleName( const int unum ) const;
00207 
00213     virtual
00214     Vector2D getPosition( const int unum,
00215                           const Vector2D & ball_pos ) const;
00216 
00217     /*
00218       \brief get all positions for the current focus point
00219       \param focus_point current focus point, usually ball position
00220       \param positions contaner to store the result
00221      */
00222     virtual
00223     void getPositions( const Vector2D & focus_point,
00224                        std::vector< Vector2D > & positions ) const;
00225 
00230     virtual
00231     void train( const std::list< Snapshot > & train_data );
00232 
00238     virtual
00239     bool read( std::istream & is );
00240 
00246     virtual
00247     std::ostream & print( std::ostream & os ) const;
00248 
00249 private:
00250 
00255     const
00256     Param & param() const
00257       {
00258           return M_param;
00259       }
00260 };
00261 
00262 }
00263 
00264 #endif

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