albjohan
Messages postés2Date d'inscriptionmardi 13 juillet 2004StatutMembreDernière intervention 2 juillet 2005
-
26 juin 2005 à 19:28
albjohan
Messages postés2Date d'inscriptionmardi 13 juillet 2004StatutMembreDernière intervention 2 juillet 2005
-
2 juil. 2005 à 12:12
Bonsoir,
Voici une fonction recusive qui me permet de créer l ensemble des possibilitees du morpion.
Malheureusement en ajoutant dans cette arbre a jeu la variable minimax
(connaitre les branches gagnantes ou perdantes) cela ma fiche un
message d erreur (Projet1.exe a rencontré un problème et doit fermer.
Nous vous prions de nous excuser pour le désagrément encouru) provenant
de "variable->suiv[z]->minmax".
Merci pour un petit coup de pouce car je commence à craquer
struct men_listes {
int minmax;
char valeur [ 9 ];
men_listes *suiv[ 9 ];
};
void chercher_suivant( men_listes *variable ) {
int nouvelle_poss=0;
if (win(variable,'O')) return;
if (win(variable,'X')) return;
if (match_nul(variable)) return;
for(int i=0 ; i < 9; i++){
if (variable->valeur[i]=='.'){
men_listes *temp=new men_listes;
copie_chercher(variable,temp);
temp->valeur[i]=qui_joue(temp);
variable->suiv[nouvelle_poss]=temp;
chercher_suivant( temp );
nouvelle_poss++;
}
}
if (nouvelle_poss != 0){
variable->minmax = variable->suiv[0]->minmax;
char joueur = qui_joue(variable);
for(int z=1 ; z < 9 && variable->suiv[z]!=NULL ; z++){
if (joueur == 'X'){
if (variable->minmax > variable->suiv[z]->minmax){
variable->minmax = variable->suiv[z]->minmax;
}
else if (variable->minmax < variable->suiv[z]->minmax){
variable->minmax = 0;
}
}
else {
if (variable->minmax < variable->suiv[z]->minmax){
variable->minmax = variable->suiv[z]->minmax;
}
else if (variable->minmax > variable->suiv[z]->minmax){
albjohan
Messages postés2Date d'inscriptionmardi 13 juillet 2004StatutMembreDernière intervention 2 juillet 2005 2 juil. 2005 à 12:12
J'ai trouve la solution grace au conseil de mon prof
Il fallait simplement initialiser apres chaque nouvelle creation de l arbre avec la fonction suivante
void init_valeur(men_listes *a){
for(int i=0; i < 9; i++){
a->valeur[i]='.';
}
for(int i=0; i < 9; i++){
a->suiv[i]=NULL;
}
};