Public Types | Public Member Functions

claw::ai::game::select_random_action< Method > Class Template Reference

Sélection d'une action parmis les meilleures avec une méthode quelconque. More...

#include <game_ai.hpp>

List of all members.

Public Types

typedef Method::state state
typedef Method::action action
typedef Method::score score

Public Member Functions

void operator() (int depth, const state &current_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.

Detailed Description

template<class Method>
class claw::ai::game::select_random_action< Method >

Sélection d'une action parmis les meilleures avec une méthode quelconque.

Author:
Julien Jorge & Sébastien Angibaud

Definition at line 173 of file game_ai.hpp.


Member Typedef Documentation

template<class Method >
typedef Method::action claw::ai::game::select_random_action< Method >::action

Definition at line 177 of file game_ai.hpp.

template<class Method >
typedef Method::score claw::ai::game::select_random_action< Method >::score

Definition at line 178 of file game_ai.hpp.

template<class Method >
typedef Method::state claw::ai::game::select_random_action< Method >::state

Definition at line 176 of file game_ai.hpp.


Member Function Documentation

template<class Method >
void claw::ai::game::select_random_action< Method >::operator() ( int  depth,
const state current_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.

Parameters:
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().

{
  std::list<action> l;
  typename std::list<action>::iterator it;
  action_eval<action, score> eval( new_action, current_state.min_score() );
  Method method;
  max_vector< action_eval<action, score> > events( eval );

  // actions jouables par l'ordi
  current_state.nexts_actions( l );

  for (it=l.begin(); it!=l.end(); ++it)
    {
      state* new_state;
                        
      // on effectue chaque action
      new_state = static_cast<state*>(current_state.do_action(*it));

      // et on regarde ce qu'elle vaut.
      eval.action = *it;
      eval.eval = method(depth-1, *new_state, !computer_turn);

      delete new_state;

      // si c'est la meilleure, on la garde.
      events.add( eval );
    }

  int i = rand() % events.get_v().size();
  new_action = events.get_v()[i].action;
} // select_random_action::operator()


The documentation for this class was generated from the following files: