def minimaxRoot(depth, board,isMaximizing, tour):
possibleMoves = getPossibleMoves(board, tour)
if len(possibleMoves) == 0:
return None
bestMove = float('-inf')
bestMoveFinal = None
for m in possibleMoves:
prev = board[m[3]][m[2]]
board = move_test(m, board)
value = max(bestMove, minimax(depth - 1, board, not isMaximizing, 1-tour))
board = undo(m, board, prev)
if( value > bestMove):
bestMove = value
bestMoveFinal = m
return bestMoveFinal
def minimax(depth, board, is_maximizing, tour):
global nb
nb+=1
if(depth == 0):
return -evaluate(board, tour)
possibleMoves = getPossibleMoves(board, tour)
if len(possibleMoves) == 0:
if gameIsOver(board) and isInCheck(tour,board):
if is_maximizing:
return float('-inf')
else:
return float('inf')
#Meilleur coup pour l'ia
if(is_maximizing):
bestMove = float('-inf')
for m in possibleMoves:
prev = board[m[3]][m[2]]
board = move_test(m, board)
bestMove = max(bestMove, minimax(depth - 1, board, not is_maximizing, 1-tour))
board = undo(m, board, prev)
return bestMove
#Meilleur coup de l'adversaire (= pire coup pour l'ia)
else:
bestMove = float('inf')
for m in possibleMoves:
prev = board[m[3]][m[2]]
board = move_test(m, board)
bestMove = min(bestMove, minimax(depth - 1, board, not is_maximizing, 1-tour))
board = undo(m, board, prev)
return bestMove