Bonjour tout le monde.

Je me permet de poster ce message car j'ai un réel problème. Mon algorithme d'évaluation pour mon IA est plutôt bon mais j'ai un petit problème avec mon algorithme min-max.

En effet, je n'arrive pas à renvoyer les valeurs -1000 qui correspondent au contre de l'ordinateur. Lorsque j'ai 3 pions alignés, il ne me contre pas alors que lorsqu'il a 3 pions alignés, il joue bien le 4ème pour gagner.

Voici mon code : (Je précise que je teste simplement avec une profondeur de 1 pour vérifier si les valeurs sont bien renvoyées)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
void Ordi::jouerOrdi(int prof) {
    int max = -10000;
    int tmp;
    int nb_alea;
    vector<int> vect;
 
    /*if(this->getJ()->getCouleur() == 'R')
        max = -10000;
    else
        max = 10000;*/
 
    for(int i=0; i<=nbC-1; i++) {
        if(p->ajouterJeton('R', i+1)) {
            //if(this->getJ()->getCouleur() == 'R') {
            tmp = this->max(prof-1, 'R');
            cout << tmp << endl;
            if(tmp > max) {
                max = tmp;
                vect.clear();
                vect.push_back(i+1);
            }
            else if(tmp == max)
                vect.push_back(i+1);
            //}
            /*else {
                tmp = this->min(prof-1, this->getJ()->getCouleur());
                if(tmp < max) {
                    max = tmp;
                    vect.clear();
                    vect.push_back(i+1);
                }
            }*/
            //if(tmp == max && (tmp != 1000 || tmp != -1000)) {
            //    vect.push_back(i+1);
            //}
            p->annulerCoup(i);
        }
    }
    nb_alea = (rand() % vect.size());
    p->ajouterJeton('R', vect.at(nb_alea));
    vect.clear();
}
 
int Ordi::min(int prof, char coul) {
    int max = -10000;
    int tmp;
 
    if(prof == 0 || p->grilleGagnante() || p->grillePleine())
        max = this->evaluate(coul);
    else {
        for(int i=0; i<=nbC-1; i++) {
            //if(this->getJ()->getCouleur() == 'J')
            //{
                if(p->ajouterJeton('J', i+1)) {
                    tmp = this->max(prof-1, 'J');
                    if(tmp > max)
                        max = tmp;
                    p->annulerCoup(i);
                }
            //}
            /*else
            {
                if(p->ajouterJeton('R', i+1)) {
                    tmp = this->max(prof-1, 'R');
                    if(tmp > max)
                        max = tmp;
                    p->annulerCoup(i);
                }
            }*/
 
        }
    }
 
    return max;
}
 
int Ordi::max(int prof, char coul) {
    int min = 10000;
    int tmp;
 
    if(prof == 0 || p->grilleGagnante() || p->grillePleine())
            min = this->evaluate(coul);
    else {
        for(int i=0; i<=nbC-1; i++) {
            if(p->ajouterJeton('R', i+1)) {
                tmp = this->min(prof-1, 'R');
                if(tmp < min)
                    min = tmp;
                p->annulerCoup(i);
            }
        }
    }
 
    return min;
}
 
int Ordi::evaluate(char coul) {
    int ret = 0;
 
    if(p->grillePleine() && !p->grilleGagnante()) {
        ret = 0;
    }
    else if(p->grilleGagnante()) {
        if(coul == 'R')
            ret = 1000;
        else
            ret = -1000;
    }
 
    /*else { ... }