week0/tictactoe/tictactoe.py
def minimax(board):
    """
    Returns the optimal action for the current player on the board.
    """

    def max_value(board):
        optimal_move = ()
        if terminal(board):
            return utility(board), optimal_move
        else:
            v = -5
            for action in actions(board):
                minval = min_value(result(board, action))[0]
                if minval > v:
                    v = minval
                    optimal_move = action
            return v, optimal_move

    def min_value(board):
        optimal_move = ()
        if terminal(board):
            return utility(board), optimal_move
        else:
            v = 5
            for action in actions(board):
                maxval = max_value(result(board, action))[0]
                if maxval < v:
                    v = maxval
                    optimal_move = action
            return v, optimal_move

    curr_player = player(board)

    if terminal(board):
        return None

    if curr_player == X:
        return max_value(board)[1]

    else:
        return min_value(board)[1]

    Returns the optimal action for the current player on the board.
    
Returns the optimal action for the current player on the board.
Returns the optimal action for the current player on the board .
def minimax(board):
    def max_value(board):
        optimal_move = ()
        if terminal(board):
            return utility(board), optimal_move
        else:
            v = -5
            for action in actions(board):
                minval = min_value(result(board, action))[0]
                if minval > v:
                    v = minval
                    optimal_move = action
            return v, optimal_move
    def min_value(board):
        optimal_move = ()
        if terminal(board):
            return utility(board), optimal_move
        else:
            v = 5
            for action in actions(board):
                maxval = max_value(result(board, action))[0]
                if maxval < v:
                    v = maxval
                    optimal_move = action
            return v, optimal_move
    curr_player = player(board)
    if terminal(board):
        return None
    if curr_player == X:
        return max_value(board)[1]
    else:
        return min_value(board)[1]
def minimax ( board ) : def max_value ( board ) : optimal_move = ( ) if terminal ( board ) : return utility ( board ) , optimal_move else : v = - 5 for action in actions ( board ) : minval = min_value ( result ( board , action ) ) [ 0 ] if minval > v : v = minval optimal_move = action return v , optimal_move def min_value ( board ) : optimal_move = ( ) if terminal ( board ) : return utility ( board ) , optimal_move else : v = 5 for action in actions ( board ) : maxval = max_value ( result ( board , action ) ) [ 0 ] if maxval < v : v = maxval optimal_move = action return v , optimal_move curr_player = player ( board ) if terminal ( board ) : return None if curr_player == X : return max_value ( board ) [ 1 ] else : return min_value ( board ) [ 1 ]
Returns the optimal action for the current player on the board.
Returns the optimal action for the current player on the board .
"""
    Returns the optimal action for the current player on the board.
    """
board