title: Using the minimax algorithm, how do I access the node that returned the best value so it can be utilised?
body: <p>I am currently completing an assignment for a uni paper. I am making an AI for a checkers game. I understand the principles of the minimax algorithm, however, when it came to implementing it I am struggling to see how I can access the node with the best move so it can be implemented. It may be that I have implemented the code incorrectly which, has put me in this situation. However, as far as I can see it is only returning the best score that was evaluated. How do I then get the node that returned it to the Root?</p>
  <p>This is the code for the GameTree that has the minimax function in it. I want to be able to use the node that sent the best score in the GetNextMove()</p>
  <pre><code>#include &quot;gametree.h&quot;
  //Constructor
  GameTree::GameTree()
  {
  
  }
  
  /* This function is part of the evalutaion of which move is best by looking for the best
   * score in the tree. which is set up by the nodes calling themselves via the Move::PosMove
   *  function. This function was used because it was taught in class and it enables pruning. 
   *  this function goes down the left side to the bottom of the tree first. Because the 
   *  children of each node are stored in a set the highest score is the first to be seen.
   *  this will enable maximum pruning, so will speed up the search for the best move.
   *  Called by Move::AiMove() */
  int GameTree::minimax(Node *node, int depth, int alpha, int beta, bool isMaxNode)
  {
      int Alpha = alpha;
      int Beta = beta;
      
      if (depth == 0|| endGame ==1)
      {
          nScore= node-&gt;score;
          return nScore;
      }
      if (isMaxNode)
      {
          int HighScore = -1000;
          for (int i =0; i&lt; (int)node-&gt;children.size(); i++)
          {
              nScore= minimax(node, depth-1, Alpha, Beta, false);
              HighScore= max(HighScore,nScore);
              Alpha= max(Alpha, HighScore);
              if (beta&lt;=alpha)
              {
                  break;
              }
          }
          return Alpha;
      }
  
      else
      {
          int LowScore = 1000;
          for (int i =0; i&lt; (int)node-&gt;children.size(); i++)
          {
              nScore= minimax(node,depth-1, Alpha, Beta, true);
              LowScore= min(LowScore,nScore);
              Beta= min(Beta, LowScore);
              if (beta&lt;=alpha)
              {
                  break;
              }
          }
          return Beta;
      }
  }
  
  /* This function serches for the best move based on teh minimax evaluation by looking at
   *  the children of the root node.
   *  Called By Move::AiMove() */
  void GameTree::GetNextMove()
  {
      nodeNext = *nodeRoot-&gt;children.begin();
      for (Node *n : nodeRoot-&gt;children)
      {
          if (n-&gt;score &gt; nodeNext-&gt;score)
          {
              nodeNext = n;
          }
      }
      nodeNext-&gt;UpdateDisplay(4);
      return;
  
  }
  </code></pre>
  <p>Thank you, in advance for your help I have received a lot of help from this website, without ever having to ask a question. Hopefully, you can help me again. Thanks.</p>