2.14 Corrigés des exercices
}
}
if ( eval > alpha)
alpha = eval ;
if (alpha >= beta )
return beta ;
return alpha ;
37
int alphabeta ( int depth , int alpha , int beta , char joueur ,
list & vp ) {
}
i f ( de pt h == 0 )
return quiescence (alpha , beta , joueur );
list listeCoups = virus . coupsLegaux (joueur );
if (listeCoups .empty ())
return virus . evaluationSiPlusDeCoupsPossibles (joueur );
char autre = virus . adversaire (joueur );
for ( list:: iterator it = listeCoups . begin ();
}
it != listeCoups . end (); ++ it ) {
virus . joue (* it );
1 i s t vptemp ;
int eval = -alphabeta ( depth - 1, -beta , -alpha , autre ,
vptemp );
if ( eval > alpha) {
alpha = eval ;
}
vp = vptemp ;
vp .push_front (* it );
virus . dejoue (* it );
if (alpha >= beta )
return beta ;
return alpha ;
2.14.10 Approfondissement itératif
On déclare une variable globale qui donne le temps maximum au bout duquel on
renvoie une réponse. Dès que l' Alpha-Bêta dépasse ce temps il est stoppé et on renvoie la
variation principale de l'itération précédente :
Virus virus ;
clock_t maxClock = 2 * CLOCKS_PER_SEC ; 11 2 secondes
clock_t clockStart ;
}
}
if ( eval > alpha)
alpha = eval ;
if (alpha >= beta )
return beta ;
return alpha ;
37
int alphabeta ( int depth , int alpha , int beta , char joueur ,
list
}
i f ( de pt h == 0 )
return quiescence (alpha , beta , joueur );
list
if (listeCoups .empty ())
return virus . evaluationSiPlusDeCoupsPossibles (joueur );
char autre = virus . adversaire (joueur );
for ( list
}
it != listeCoups . end (); ++ it ) {
virus . joue (* it );
1 i s t
int eval = -alphabeta ( depth - 1, -beta , -alpha , autre ,
vptemp );
if ( eval > alpha) {
alpha = eval ;
}
vp = vptemp ;
vp .push_front (* it );
virus . dejoue (* it );
if (alpha >= beta )
return beta ;
return alpha ;
2.14.10 Approfondissement itératif
On déclare une variable globale qui donne le temps maximum au bout duquel on
renvoie une réponse. Dès que l' Alpha-Bêta dépasse ce temps il est stoppé et on renvoie la
variation principale de l'itération précédente :
Virus virus ;
clock_t maxClock = 2 * CLOCKS_PER_SEC ; 11 2 secondes
clock_t clockStart ;
