def minimax (colour, board): if gameOver(board) or lookedFarEnough(board): return evaluateScore(board) moves = getLegalMoves(colour, board) if colour == black: score = -infinity; for i in moves: score = max(minimax(white, makeMove(board, i)), score) else: score = +infinity; for i in moves: score = min(minimax(black, makeMove(board, i)), score) return score
def alphaBeta (colour, board, alpha, beta): if gameOver(board) or lookedFarEnough(board): return evaluateScore(board) moves = getLegalMoves(colour, board) if colour == black: for i in moves: try = alphaBeta(white, makeMove(board, i), alpha, beta) if try > beta: beta = try # found a better move if beta >= alpha: return beta # no point searching further as WHITE would # choose a different previous move return beta # the best score for a move BLACK has found else: for i in moves: try = alphaBeta(black, makeMove(board, i), alpha, beta) if try < alpha: alpha = try # found a better move if beta >= alpha: # black would chose a previous move return alpha return alpha # the best score for a move WHITE has found
foo = alphaBeta(black, <board>, ∞, -∞)
if gameOver(board) or lookedFarEnough(board): return evaluateScore(board) moves = getLegalMoves(colour, board) if colour == black: for i in moves: try = alphaBeta(white, makeMove(board, i), alpha, beta) if try > beta: beta = try # found a better move if beta >= alpha: return beta # no point searching further as WHITE would # choose a different previous move return beta # the best score for a move BLACK has found
if gameOver(board) or lookedFarEnough(board): return evaluateScore(board) moves = getLegalMoves(colour, board)
moves = [1, 2, 3]
for i in moves: # now we see what move white plays if we were to play move 1 # alpha is +∞, beta is -∞ try = alphaBeta(white, <board position after move 1>, alpha, beta) if try > beta: beta = try # found a better move if beta >= alpha:# notice since alpha is +∞ we can ignore at present return beta # no point searching further as WHITE would # choose a different previous move return beta # the best score for a move BLACK has found
def alphaBeta (colour, board, alpha, beta): if gameOver(board) or lookedFarEnough(board): return evaluateScore(board) moves = getLegalMoves(colour, board) if colour == black: ... else: # moves = [a, b] # alpha = +∞ # beta = -∞ for i in moves: try = alphaBeta(black, makeMove(board, i), alpha, beta) if try < alpha: alpha = try # found a better move if beta >= alpha: # black would chose a previous move return alpha return alpha # the best score for a move WHITE has found
# moves = [a, b] # alpha = +∞ # beta = -∞ for i in moves: # first iteration the value of i = move a try = alphaBeta(black, makeMove(board, i), alpha, beta) # try first time = +10 if try < alpha: # first time this will be true alpha = try # alpha = +10 if beta >= alpha: # false return alpha # not executed return alpha # the best score for a move WHITE has found
# moves = [a, b] # alpha = +10 # beta = -∞ for i in moves: # second iteration the value of i = move b try = alphaBeta(black, makeMove(board, i), alpha, beta) # try second time = +∞ if try < alpha: # second time this will be false alpha = try # not executed if beta >= alpha: # false return alpha # not executed return alpha # the best score for WHITE scores +10
if colour == black: for i in moves: try = alphaBeta(white, makeMove(board, i), alpha, beta) if try > beta: # +10 beta = try # +10 is better than -∞ if beta >= alpha: # false return beta return beta
try = alphaBeta(white, makeMove(board, i), alpha, +10)
# moves = [c, d] # alpha = ∞ # beta = +10 for i in moves: # first iteration the value of i = move c try = alphaBeta(black, makeMove(board, i), alpha, beta) # try first time = 0 if try < alpha: # first time this will be true alpha = try # alpha = 0 if beta >= alpha: # true return alpha # return 0 (notice we do not return +10) return alpha # the best score for a move WHITE has found
#undef USE_CORNER_SCORES
#define USE_CORNER_SCORES
This document was produced using groff-1.22.