title: Is this implementation of the negamax algorithm correct
body: <p>I'm trying to implement the negamax algorithm, and this is how I thought it should be:</p>
  
  <pre><code>public Move getBestMove(Board board){
   List&lt;Move&gt; possibleMoves = board.getPossibleMoves();
   Move optimalMove;
   int maxScore;
   foreach(Move move in possibleMoves){
    Board newBoard = board.clone();
    newBoard.makeMove(move);
    int score = negamax(newBoard, DEPTH, Integer.MAX, Integer.MIN, 1);
    if (score &gt; maxScore){
      optimalMove = move;
      maxScore = score;
    }
   }
  }
  </code></pre>
  
  <p>And the corresponding negamax function</p>
  
  <pre><code>public int negamax(Board board, int depth, int alpha, int beta, int sign){
   if(depth == null || board.getPossibleMovesNumber(colour) == 0){
    return calculateBoardFunction(board);
   }
   else{
    List&lt;Move&gt; possibleMoves = board.getPossibleMoves();
    foreach(Move move in possibleMoves){
     Board newBoard = board.clone();
     newBoard.makeMove(move);
     alpha = Math.max(alpha, -negamax(newBoard, depth-1, -beta, -alpha, -sign);
     if(alpha &gt;= beta){
       break;
     }
    }
   return alpha;
  }
  </code></pre>
  
  <p>Yeah I know it's not compiling but I'm just trying to pseudocode it a bit. </p>
  
  <p><strong>Edit</strong></p>
  
  <p>The calculateBoardFunction(Board board) will ALWAYS evaluate the board for the color that the best move is calculated for.</p>
  
  <p>Also, i've tried to make it generic, so it works the same for every game (chess, reversi, go) etc... (but that's not part of the question)</p>
  
  <p>Also I used the wikipedia's negamax pseudocode as an example. But using that code I >>think&lt;&lt; I could create the game tree very well, with the correct heuristics values. but the reason I have the code in the <code>getBestMove</code> function, is to figure out what move is actually the best. </p>
  
  <p>But im not sure if I can do that. </p>