0

Hello, I have been researching the minimax algorithm for a few days, but I can't apply it properly. I have read that for the 8 lines in Tic Tac Toe, you give certain scores. However, I don't understand what they are trying to tell me. Could I have a simple explaination of the algorithm and how to apply it?

Thanks :)

3
Contributors
6
Replies
20
Views
4 Years
Discussion Span
Last Post by Adak
1

Do you have code to post? A description of the algorithm? What you are saying is not enough to help you.

0

The algorithm part that I understood is to play all possible moves, and get the best possible score, so I made this piece of code:

int getFutureScore(char square[], char turn)    
{
      int num, currentBest, score;

       if(turn == 'C')                       currentBestScore = -100;       
       else                                     currentBestScore = 100;        

       for(num=0; num<9; num++)
       {
                    if(square[num] == ' ')
                    {
                           if(turn == 'C')      
                           {
                               square[num] = 'O';
                               score = getFutureScore(positions, 'U'); 
                               square[num] = ' ';
                           }
                           else                  
                           {
                                square[num] = 'X';
                                score = getFutureScore(positions, 'C');
                                square[num] = ' ';
                           }
                           if(turn == 'C' && score > currentBest)                                    
                          currentBest= score;
                           if(turn == 'U' && score < currentBest)   
                          currentBest= score;
                    }       
          }   
         return(currentBest);                    
}

Edited by Seth Lam

1

This isn't complete. The variables currentBestScore and positions are not defined here. Did you mean currentBest, and square instead?

Votes + Comments
Yes I'm sorry, mixed up my variables
0

Here's a code update:

int getFutureScore(char square[], char turn)    
{
      int num, currentBest, score;
       if(turn == 'C')                       currentBest = -100;       
       else                                     currentBest = 100;        
       for(num=0; num<9; num++)
       {
                    if(square[num] == ' ')
                    {
                           if(turn == 'C')      
                           {
                               square[num] = 'O';
                               score = getFutureScore(square, 'U'); 
                               square[num] = ' ';
                           }
                           else                  
                           {
                                square[num] = 'X';
                                score = getFutureScore(square, 'C');
                                square[num] = ' ';
                           }
                           if(turn == 'C' && score > currentBest)                                    
                          currentBest= score;
                           if(turn == 'U' && score < currentBest)   
                          currentBest= score;
                    }       
          }   
         return(currentBest);                    
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.