Sélection d'une action avec la méthode MinMax. More...
#include <game_ai.hpp>
Public Types | |
typedef State | state |
typedef State::action | action |
typedef State::score | score |
Public Member Functions | |
score | operator() (int depth, const state ¤t_state, bool computer_turn) const |
Evaluation d'un coup par la méthode MinMax. |
Sélection d'une action avec la méthode MinMax.
Definition at line 117 of file game_ai.hpp.
typedef State::action claw::ai::game::min_max< State >::action |
Definition at line 121 of file game_ai.hpp.
typedef State::score claw::ai::game::min_max< State >::score |
Definition at line 122 of file game_ai.hpp.
typedef State claw::ai::game::min_max< State >::state |
Definition at line 120 of file game_ai.hpp.
State::score claw::ai::game::min_max< State >::operator() | ( | int | depth, | |
const state & | current_state, | |||
bool | computer_turn | |||
) | const [inline] |
Evaluation d'un coup par la méthode MinMax.
depth | Profondeur. | |
current_state | Etat du jeu. | |
computer_turn | Indique si c'est au tour de l'ordinateur. |
Definition at line 145 of file game_ai.tpp.
00146 { 00147 score score_val; 00148 00149 // on a atteint la profondeur demandée ou la partie est terminée 00150 if ( current_state.final() || (depth == 0) ) 00151 score_val = current_state.evaluate(); // on retourne l'évaluation de l'état. 00152 else 00153 { 00154 std::list<action> next_actions; 00155 typename std::list<action>::const_iterator it; 00156 state* new_state; 00157 00158 // on récupère les états suivants. 00159 current_state.nexts_actions( next_actions ); 00160 00161 if ( next_actions.empty() ) // si on ne peut plus rien faire 00162 // on évalue l'état où l'on est. 00163 score_val = current_state.evaluate(); 00164 else 00165 { 00166 if (computer_turn) // si c'est l'ordi qui va jouer 00167 { 00168 score_val = current_state.min_score(); 00169 00170 for (it = next_actions.begin(); it!=next_actions.end(); ++it) 00171 { 00172 new_state=static_cast<state*>(current_state.do_action(*it)); 00173 00174 // on évalue le coup du joueur 00175 score s = (*this)( depth-1, *new_state, false ); 00176 00177 // on choisit l'action qui nous rapporte le plus 00178 if (s > score_val) 00179 score_val = s; 00180 00181 delete new_state; 00182 } 00183 } 00184 else // c'est le tour du joueur 00185 { 00186 score_val = current_state.max_score(); 00187 00188 for (it = next_actions.begin(); it!=next_actions.end(); ++it) 00189 { 00190 new_state=static_cast<state*>(current_state.do_action(*it)); 00191 00192 // on évalue le coup de l'ordi 00193 score s = (*this)( depth-1, *new_state, true ); 00194 00195 // on choisit l'action qui lui rapporte le moins. 00196 if (s < score_val) 00197 score_val = s; 00198 00199 delete new_state; 00200 } 00201 } 00202 } 00203 } 00204 00205 return score_val; 00206 } // min_max::operator()