1

建立一個極小位置樹對於Connect4比賽,我需要這個的Alpha-Beta算法轉換成由Aske Plaat在他的MTD(F)算法解釋AlphaBetaWithMemory算法:https://people.csail.mit.edu/plaat/mtdf.html#abmem如何在JavaScript

所以,我需要一些提示關於如何構建可能移動的minimax樹板位置,以便能夠以與AlphaBetaWithMemory相同的方式遍歷其子節點。

我真的希望你們能給我一些建議,請。

謝謝。

Game.prototype.alphabeta = function(board, depth, alpha, beta, maximizingPlayer) { 

    // Call score of our board 
    var score = board.score(); 

    // Break 
    if (board.isFinished(depth, score)) return [null, score]; 

    if(maximizingPlayer) 
    { 
     // Column, Score 
     var max = [null, -99999]; 

     // POSSIBLE MOVES 
     for (var column = 0; column < that.columns; column++) 
     { 
      var new_board = board.copy(); // Create new board 

      if (new_board.place(column)) { 

       that.iterations++; // Debug 

       var next_move = that.alphabeta(new_board, depth-1, alpha, beta, false); // Recursive calling 

       // Evaluate new move 
       if (max[0] == null || next_move[1] > max[1]) { 
        max[0] = column; 
        max[1] = next_move[1]; 
        alpha = next_move[1]; 
       } 

       if (alpha >= beta) return max; 
      } 
     } 

     return max; 
    } 
    else 
    { 
     // Column, score 
     var min = [null, 99999]; 

     // POSSIBLE MOVES 
     for (var column = 0; column < that.columns; column++) { 
      var new_board = board.copy(); 

      if (new_board.place(column)) { 

       that.iterations++; 

       var next_move = that.alphabeta(new_board, depth-1, alpha, beta, true); 

       if (min[0] == null || next_move[1] < min[1]) { 
        min[0] = column; 
        min[1] = next_move[1]; 
        beta = next_move[1]; 
       } 

       if (alpha >= beta) return min; 
      } 
     } 
     return min; 
    } 
} 

回答

0

AlphaBetaWithMemory算法是使用一個Transposition Table標準α,β算法。

所以,如果你的alpha beta算法有效,你只需要添加一個轉置表來存儲以前的搜索信息。沒有轉座表,MTD(f)仍然是正確的,但效率不高。