Bonjour, nouveau sur le forum, je me permet de poster ce message ici.

Je suis actuellement en train de dev un jeu d'Othello en C++ uniquement en mode console. J'ai un peu de mal a implementer l'algo minimax sachant que le but est de creer une IA imbattable.

Ce qu'il faut savoir :
- L'ordi joue toujours les X
- L'humain joue toujours les O
- Les O commencent toujours
- Chaque joueur attend son tour, sauf si l'opposant ne peut pas jouer

J'ai donc implementer trois fonctions :

- une pour evaluer la position la position joue de l'ordi

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
 
int Othello1::EvaluateCPUPosition(int * othello)
{
    int max = 0;
 
    int rslt = INT_MIN;
 
    vector<vector<int> > playablePositions = Othello1::GetAllPlayablePositionsForPlayer(Othello1::X_disc);
 
    for (int i = 0 ; i < playablePositions.size() ; i++)
    {
        int tmp_othello [][] = othello;
 
        tmp_othello[playablePositions[i][0]][playablePositions[i][1]] == Othello1::X_disc;
 
        max = Transform(Othello1::X_disc, playablePositions[i][0], playablePositions[i][1]);
 
        if (max >= rslt)
        {
            rslt = max;
        }
    }
 
    return rslt;
}
- une pour evaluer la position joue de l'humain

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
 
int Othello1::EvaluatePlayerPosition(int* othello)
{
    int min = 0;
 
    int rslt = INT_MAX;
 
    vector<vector<int> > playablePositions = Othello1::GetAllPlayablePositionsForPlayer(Othello1::O_disc);
 
    for (int i = 0 ; i < playablePositions.size() ; i++)
    {
        int tmp_othello [][] = othello;
 
        tmp_othello[playablePositions[i][0]][playablePositions[i][1]] == Othello1::O_disc;
 
        min = Transform(Othello1::O_disc, playablePositions[i][0], playablePositions[i][1]);
 
        if (min <= rslt)
        {
            rslt = min;
        }
    }
 
    return rslt;
}
- et enfin la fonction minimax

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
 
int Othello1::Minimax(int * othello, int depth)
{
    if (depth < Othello1::maxDepth)
    {
        int cpuScore = 0;
 
        int huScore = 0;
 
        cpuScore = EvaluateCPUPosition(othello);
 
        huScore = EvaluatePlayerPosition(othello);
 
        gameValue = huScore + cpuScore;
 
        Minimax(othello, depth);
 
        depth++;
    }
 
    return gameValue;
}
Il me semble que je n'ai pas tout saisi.

"Othello1::GetAllPlayablePositionsForPlayer" retourne un vecteur a deux dimensions contenant les positions x et y jouables pour le joueur passe en parametre.

"Othello::Transform" retourne les pions apres qu'un joueur ait pose son pion, elle retourne le nombre de pions retournes.

Faut il que j'en cree une autre similaire que retourne les positions jouables suivantes en fonction de la position jouee par l'ordi precedemment ?

J'apprecie tout aide, et je reste a disposition pour eclaircir certains points obscures. Merci d'avance