00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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 };
00090
00091
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 };
00110
00111
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 };
00127
00128
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 };
00147
00148
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 };
00164
00165
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 };
00183
00184 }
00185 }
00186 }
00187
00188 #include <claw/impl/game_ai.tpp>
00189
00190 #endif // __CLAW_IA_JEUX_HPP__