• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

game_ai.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_GAME_AI_HPP__
00031 #define __CLAW_GAME_AI_HPP__
00032 
00033 #include <list>
00034 
00035 namespace claw
00036 {
00037   namespace ai
00038   {
00039     namespace game
00040     {
00041       //**************************** game_state ********************************
00042 
00049       template <class Action, class Numeric = int> class game_state
00050       {
00051       public:
00053         typedef Numeric score;
00054         typedef Action action;
00055 
00056         virtual ~game_state();
00057 
00059         virtual score evaluate() const = 0;
00060 
00061         static score min_score();
00062         static score max_score();
00063 
00068         virtual void nexts_actions( std::list<action>& l ) const = 0;
00069 
00075         virtual game_state* do_action( const action& a ) const = 0;
00076 
00078         virtual bool final() const = 0;
00079 
00080       protected :
00081 
00082         score fit( score score_val ) const;
00083 
00084       protected :
00086         static const score s_min_score;
00088         static const score s_max_score;
00089       }; // class game_state
00090 
00091       //**************************** action_eval ******************************
00092 
00096       template <class Action, class Numeric> class action_eval
00097       {
00098       public:
00099         action_eval( const Action& a,
00100                      const Numeric& e);
00101 
00102         bool operator< ( const action_eval& ae ) const;
00103         bool operator==( const action_eval& ae ) const;
00104                 
00106         Action action;
00108         Numeric eval;
00109       }; // class action_eval
00110 
00111       //*************************** min_max ***********************************
00112 
00117       template <class State> class min_max
00118       {
00119       public:
00120         typedef State state;
00121         typedef typename State::action action;
00122         typedef typename State::score score;
00123 
00124         score operator()( int depth, const state& current_state, 
00125                           bool computer_turn ) const;
00126       }; // class min_max
00127 
00128       //*************************** alpha_beta ********************************
00129 
00134       template <class State> class alpha_beta
00135       {
00136       public:
00137         typedef State state;
00138         typedef typename State::action action;
00139         typedef typename State::score score;
00140 
00141         score operator()( int depth, const state& current_state, 
00142                           bool computer_turn ) const;
00143       private:
00144         score calcul( int depth, const state& current_state, 
00145                       bool computer_turn, score alpha, score beta ) const;
00146       }; // class alpha_beta
00147 
00148       //*************************** select_action *****************************
00149 
00154       template<class Method> class select_action
00155       {
00156       public:
00157         typedef typename Method::state state;
00158         typedef typename Method::action action;
00159         typedef typename Method::score score;
00160 
00161         void operator()( int depth, const state& current_state,
00162                          action& new_action, bool computer_turn ) const;
00163       }; // class select_action
00164 
00165       //************************ select_random_action *************************
00166 
00172       template<class Method>
00173       class select_random_action
00174       {
00175       public:
00176         typedef typename Method::state state;
00177         typedef typename Method::action action;
00178         typedef typename Method::score score;
00179 
00180         void operator()( int depth, const state& current_state,
00181                          action& new_action, bool computer_turn ) const;
00182       }; // class select_random_action
00183 
00184     } // namespace game
00185   } // namespace it
00186 } // namespace claw
00187 
00188 #include <claw/impl/game_ai.tpp>
00189 
00190 #endif // __CLAW_IA_JEUX_HPP__

Generated on Sun Mar 20 2011 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1