minimax(player,board) if(game over in current board position) return winner children = all legal moves for player from this board if(max's turn) return maximal score of calling minimax on all the children else (min's turn) return minimal score of calling minimax on all the childrenIf the game is over in the given position, then there is nothing to compute; minimax will simply return the score of the board. Otherwise, minimax will go through each possible child, and (by recursively calling itself) evaluate each possible move. Then, the best possible move will be chosen, where best is the move leading to the board with the most positive score for player 1, and the board with the most negative score for player 2.
alpha-beta(player,board,alpha,beta) if(game over in current board position) return winner children = all legal moves for player from this board if(max's turn) for each child score = alpha-beta(other player,child,alpha,beta) if score > alpha then alpha = score (we have found a better best move) if alpha >= beta then return alpha (cut off) return alpha (this is our best move) else (min's turn) for each child score = alpha-beta(other player,child,alpha,beta) if score < beta then beta = score (opponent has found a better worse move) if alpha >= beta then return beta (cut off) return beta (this is the opponent's best move)Notice that it is to our advantage to generate the best moves first for max and the worst moves first for min; this will cause the algorithm to cut off more quickly. On average, using a good successor generator will allow alpha-beta to search to a level twice as deep as minimax in the same amount of time. Note also that alpha-beta returns the same score as minimax; it simply returns the same result in faster time.
Copyright © 2002-2003, by Yosen Lin. All Rights Reserved.