2.14 Corrigés des exercices
35
}
}
if (listeCoups .empty ())
break ;
int eval = alphabeta (7 , -Taille * Taille ,
Taille * Taille , 'O' , coup );
cout << "eval�=� " << eval << endl ;
cout << "Je�joue�en�" << coup .X << " " <<
coup . y << endl ;
virus . joue (coup );
return 0;
2.14.8 Variation principale
La variation principale de l'arbre de la figure 2.5 est de toujours choisir le coup le plus
à gauche.
int alphabeta ( int depth , int alpha , int beta ,
char joueur , lis t & vp ) {
if ( depth == 0)
}
return virus . evaluation (joueur );
list listeCoups = virus . coupsLegaux (joueur );
if ( listeCoups . empty ())
return virus . evaluat ionSiPlusDeCoupsPossibles (joueur );
char autre = virus . adversaire (joueur );
for (list:: iterator it = listeCoups .begin ();
}
it != listeCoups .end (); ++ it ) {
virus .joue (* it );
lis t vptemp ;
int eval = -alphabeta ( depth - 1, -beta , -alpha , autre ,
vptemp );
if (eval >a lpha) {
alpha = eval ;
}
vp = vptemp ;
vp .pu sh_front (* it );
virus . dejoue (* it );
i f ( a l p h a >= be ta )
return beta ;
return alpha ;
35
}
}
if (listeCoups .empty ())
break ;
int eval = alphabeta (7 , -Taille * Taille ,
Taille * Taille , 'O' , coup );
cout << "eval�=� " << eval << endl ;
cout << "Je�joue�en�" << coup .X << " " <<
coup . y << endl ;
virus . joue (coup );
return 0;
2.14.8 Variation principale
La variation principale de l'arbre de la figure 2.5 est de toujours choisir le coup le plus
à gauche.
int alphabeta ( int depth , int alpha , int beta ,
char joueur , lis t
if ( depth == 0)
}
return virus . evaluation (joueur );
list
if ( listeCoups . empty ())
return virus . evaluat ionSiPlusDeCoupsPossibles (joueur );
char autre = virus . adversaire (joueur );
for (list
}
it != listeCoups .end (); ++ it ) {
virus .joue (* it );
lis t
int eval = -alphabeta ( depth - 1, -beta , -alpha , autre ,
vptemp );
if (eval >a lpha) {
alpha = eval ;
}
vp = vptemp ;
vp .pu sh_front (* it );
virus . dejoue (* it );
i f ( a l p h a >= be ta )
return beta ;
return alpha ;
