34
Minimax, Alpha-Bêta et heuristiques associées
2.14.7 Alpha-Bêta
Virus virus ;
int alpha be ta ( int depth , int alpha , int beta , char joueur ,
Coup & meilleurCoup) {
}
i f ( de pt h == 0 )
return virus . evaluation (joueur );
list listeCoups = virus . coupsLegaux (joueur );
if ( listeCoups . empty ())
return virus . evaluationSiPlusDeCoupsPossibles (joueur );
char autre = virus . adversaire (joueur );
Coup coup ;
fo r (list :: iterator it = listeCoups .begin ();
it != listeCoups . end (); ++ it ) {
}
virus . joue (* it );
int eval = -alphabeta ( depth - 1, -beta , -alpha , autre ,
coup );
if ( eval > alpha) {
alpha = eval ;
meilleurCoup = * i t;
}
virus . dejoue (* it );
if (alpha >= beta )
return beta ;
return alpha ;
int main () {
list listeCoups ;
while ( true ) {
cout << virus ;
listeCoups = virus . coupsLegaux ( ' @ ' ) ;
if ( listeCoups . empty ())
break ;
cout << "Donnez .... . votre._.coup._.:._." ;
Coup coup ;
coup . couleur = ' @ ' ;
do {
cin >> coup .x >> coup.y;
} while (!virus . coupLegal (coup));
virus .joue (coup );
cout << virus ;
listeCoups = virus . coupsLegaux ( 'O ' );
Précédent

- 48/256

Suivant