Seth Lam 0 Newbie Poster

I posted a question about algorithms for Tic Tac Toe's invincible AI (that never loses, only wins or ties), and found a scoring method. Here is the code I came up with. As of this moment it takes the next available space, so the scoring appears not to be working. Why? And how can I fix this problem?

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);                    
}

Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.