Public Types | Public Member Functions

claw::ai::game::min_max< State > Class Template Reference

Sélection d'une action avec la méthode MinMax. More...

#include <game_ai.hpp>

List of all members.

Public Types

typedef State state
typedef State::action action
typedef State::score score

Public Member Functions

score operator() (int depth, const state &current_state, bool computer_turn) const
 Evaluation d'un coup par la méthode MinMax.

Detailed Description

template<class State>
class claw::ai::game::min_max< State >

Sélection d'une action avec la méthode MinMax.

Author:
Julien Jorge

Definition at line 117 of file game_ai.hpp.


Member Typedef Documentation

template<class State >
typedef State::action claw::ai::game::min_max< State >::action

Definition at line 121 of file game_ai.hpp.

template<class State >
typedef State::score claw::ai::game::min_max< State >::score

Definition at line 122 of file game_ai.hpp.

template<class State >
typedef State claw::ai::game::min_max< State >::state

Definition at line 120 of file game_ai.hpp.


Member Function Documentation

template<class State >
State::score claw::ai::game::min_max< State >::operator() ( int  depth,
const state current_state,
bool  computer_turn 
) const

Evaluation d'un coup par la méthode MinMax.

Todo:
Voir si un coup est gagnant, les suivants du même niveau ne sont pas testés.
Parameters:
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.

{
  score score_val;

  // on a atteint la profondeur demandée ou la partie est terminée
  if ( current_state.final() || (depth == 0) )
    score_val = current_state.evaluate(); // on retourne l'évaluation de l'état.
  else
    {
      std::list<action> next_actions;
      typename std::list<action>::const_iterator it;
      state* new_state;

      // on récupère les états suivants.
      current_state.nexts_actions( next_actions );

      if ( next_actions.empty() )       // si on ne peut plus rien faire
        // on évalue l'état où l'on est.
        score_val = current_state.evaluate();   
      else
        {
          if (computer_turn)    // si c'est l'ordi qui va jouer
            {                                   
              score_val = current_state.min_score();
                          
              for (it = next_actions.begin(); it!=next_actions.end(); ++it)
                {
                  new_state=static_cast<state*>(current_state.do_action(*it));

                  // on évalue le coup du joueur
                  score s = (*this)( depth-1, *new_state, false );
                                          
                  // on choisit l'action qui nous rapporte le plus
                  if (s > score_val)
                    score_val = s;

                  delete new_state;
                }
            }
          else  // c'est le tour du joueur
            {           
              score_val = current_state.max_score();
                          
              for (it = next_actions.begin(); it!=next_actions.end(); ++it)
                {
                  new_state=static_cast<state*>(current_state.do_action(*it));
                                  
                  // on évalue le coup de l'ordi
                  score s = (*this)( depth-1, *new_state, true );
                                  
                  // on choisit l'action qui lui rapporte le moins.
                  if (s < score_val)
                    score_val = s;
                                  
                  delete new_state;
                }
            }
        }
    }
  
  return score_val;
} // min_max::operator()


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