Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #ifndef __CLAW_GAME_AI_HPP__
00032 #define __CLAW_GAME_AI_HPP__
00033
00034 #include <list>
00035
00036 namespace claw
00037 {
00038 namespace ai
00039 {
00040 namespace game
00041 {
00042
00043
00053 template<typename Action, typename Numeric = int>
00054 class game_state
00055 {
00056 public:
00058 typedef Numeric score;
00059
00061 typedef Action action;
00062
00063 public:
00064 virtual ~game_state();
00065
00067 virtual score evaluate() const = 0;
00068
00069 static score min_score();
00070 static score max_score();
00071
00076 virtual void next_actions( std::list<action>& l ) const = 0;
00077
00083 virtual game_state* do_action( const action& a ) const = 0;
00084
00086 virtual bool final() const = 0;
00087
00088 protected :
00089 score fit( score score_val ) const;
00090
00091 protected :
00093 static const score s_min_score;
00094
00096 static const score s_max_score;
00097
00098 };
00099
00100
00101
00109 template <typename Action, typename Numeric>
00110 class action_eval
00111 {
00112 public:
00113 action_eval( const Action& a, const Numeric& e);
00114
00115 bool operator< ( const action_eval& ae ) const;
00116
00117
00118 public:
00120 Action action;
00121
00123 Numeric eval;
00124
00125 };
00126
00127
00128
00138 template <typename State>
00139 class min_max
00140 {
00141 public:
00142 typedef State state;
00143 typedef typename State::action action;
00144 typedef typename State::score score;
00145
00146 score operator()
00147 ( int depth, const state& current_state, bool computer_turn ) const;
00148 };
00149
00150
00151
00161 template <typename State>
00162 class alpha_beta
00163 {
00164 public:
00165 typedef State state;
00166 typedef typename State::action action;
00167 typedef typename State::score score;
00168
00169 score operator()
00170 ( int depth, const state& current_state, bool computer_turn ) const;
00171 private:
00172 score compute
00173 ( int depth, const state& current_state, bool computer_turn,
00174 score alpha, score beta ) const;
00175 };
00176
00177
00178
00187 template<typename Method>
00188 class select_action
00189 {
00190 public:
00191 typedef typename Method::state state;
00192 typedef typename Method::action action;
00193 typedef typename Method::score score;
00194
00195 void operator()
00196 ( int depth, const state& current_state, action& new_action,
00197 bool computer_turn ) const;
00198 };
00199
00200
00201
00210 template<typename Method>
00211 class select_random_action
00212 {
00213 public:
00214 typedef typename Method::state state;
00215 typedef typename Method::action action;
00216 typedef typename Method::score score;
00217
00218 void operator()( int depth, const state& current_state,
00219 action& new_action, bool computer_turn ) const;
00220 };
00221
00222 }
00223 }
00224 }
00225
00226 #include <claw/impl/game_ai.tpp>
00227
00228 #endif // __CLAW_IA_JEUX_HPP__