Public Types | Public Member Functions | Private Member Functions

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

Sélection d'une action avec la méthode Alpha Beta. 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 alpha_beta avec élagage alpha béta.

Private Member Functions

score calcul (int depth, const state &current_state, bool computer_turn, score alpha, score beta) const
 Evaluation d'un coup par la méthode alpha_beta.

Detailed Description

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

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

Author:
Julien Jorge & Sébastien Angibaud

Definition at line 134 of file game_ai.hpp.


Member Typedef Documentation

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

Definition at line 138 of file game_ai.hpp.

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

Definition at line 139 of file game_ai.hpp.

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

Definition at line 137 of file game_ai.hpp.


Member Function Documentation

template<class State >
State::score claw::ai::game::alpha_beta< State >::calcul ( int  depth,
const state current_state,
bool  computer_turn,
score  alpha,
score  beta 
) const [private]

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

Todo:
Voir si un coup est gagnant, les suivants du même niveau ne sont pas testés.
Parameters:
depth profondeur.
current_state état du jeu.
computer_turn indique si c'est au tour de l'ordinateur.
alpha Borne inférieure.
beta Borne supérieure.

Definition at line 247 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
        score_val = current_state.evaluate();   // on évalue l'état où l'on est.
      else
        {
          if (computer_turn)    // si c'est l'ordi qui va jouer
            {             // c'est un noeud MAX : sort l'action la plus forte
              score_val = current_state.min_score();
                          
              it = next_actions.begin();

              while ( it!=next_actions.end() && (score_val < beta) )
                {
                  // le coup appliqué remontera le min de ses fils
                  new_state=static_cast<state*>(current_state.do_action(*it));

                  // on évalue le coup du joueur
                  score s = calcul( depth-1, *new_state, false, 
                                    std::max(alpha, score_val), beta );

                  // on choisit l'action qui nous rapporte le plus
                  if (s > score_val) 
                    score_val = s;
                                          
                  delete new_state;
                                          
                  ++it;
                }
            }
          else    // c'est le tour du joueur
            {     // c'est un noeud MIN : sort l'action la plus faible
              score_val = current_state.max_score();
                                        
              it = next_actions.begin();

              while ( it!=next_actions.end() && (score_val > alpha) )
                {
                  // le coup appliqué remontera le max de ses fils
                  new_state=static_cast<state*>(current_state.do_action(*it));

                  // on évalue le coup de l'ordi
                  score s = calcul( depth-1, *new_state, true, alpha,
                                    std::min(beta, score_val) );
                                                
                  // on choisit l'action qui lui rapporte le moins.
                  if (s < score_val)
                    score_val = s;
                  ++it;
                                                
                  delete new_state;
                }
            }
        }
    }

  return score_val;
} // alpha_beta::calcul()

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

Evaluation d'un coup par la méthode alpha_beta avec élagage alpha béta.

Parameters:
depth profondeur.
current_state état du jeu.
computer_turn indique si c'est au tour de l'ordinateur .

Definition at line 225 of file game_ai.tpp.

{
  return this->calcul( depth, current_state, computer_turn, 
                       current_state.min_score(), current_state.max_score() ) ;
} // alpha_beta::operator()


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