Sélection d'une action parmis les meilleures avec une méthode quelconque. More...
#include <game_ai.hpp>
Public Types | |
typedef Method::state | state |
typedef Method::action | action |
typedef Method::score | score |
Public Member Functions | |
void | operator() (int depth, const state ¤t_state, action &new_action, bool computer_turn) const |
Sélection d'une action. La sélection se fait aléatoirement sur les coups ayant le meilleur score. |
Sélection d'une action parmis les meilleures avec une méthode quelconque.
Definition at line 173 of file game_ai.hpp.
typedef Method::action claw::ai::game::select_random_action< Method >::action |
Definition at line 177 of file game_ai.hpp.
typedef Method::score claw::ai::game::select_random_action< Method >::score |
Definition at line 178 of file game_ai.hpp.
typedef Method::state claw::ai::game::select_random_action< Method >::state |
Definition at line 176 of file game_ai.hpp.
void claw::ai::game::select_random_action< Method >::operator() | ( | int | depth, | |
const state & | current_state, | |||
action & | new_action, | |||
bool | computer_turn | |||
) | const [inline] |
Sélection d'une action. La sélection se fait aléatoirement sur les coups ayant le meilleur score.
depth | Profondeur. | |
current_state | Etat du jeu. | |
new_action | entrée / sortie L'action selectionnée. Si aucune action n'a un score supérieur au score minimal, ce paramètre n'est pas modifié. | |
computer_turn | Indique si c'est au tour de l'ordinateur. |
Definition at line 390 of file game_ai.tpp.
References claw::max_vector< E >::add(), and claw::max_vector< E >::get_v().
00392 { 00393 std::list<action> l; 00394 typename std::list<action>::iterator it; 00395 action_eval<action, score> eval( new_action, current_state.min_score() ); 00396 Method method; 00397 max_vector< action_eval<action, score> > events( eval ); 00398 00399 // actions jouables par l'ordi 00400 current_state.nexts_actions( l ); 00401 00402 for (it=l.begin(); it!=l.end(); ++it) 00403 { 00404 state* new_state; 00405 00406 // on effectue chaque action 00407 new_state = static_cast<state*>(current_state.do_action(*it)); 00408 00409 // et on regarde ce qu'elle vaut. 00410 eval.action = *it; 00411 eval.eval = method(depth-1, *new_state, !computer_turn); 00412 00413 delete new_state; 00414 00415 // si c'est la meilleure, on la garde. 00416 events.add( eval ); 00417 } 00418 00419 int i = rand() % events.get_v().size(); 00420 new_action = events.get_v()[i].action; 00421 } // select_random_action::operator()