engine.py
def negamax(game_state, depth, alpha, beta):
    """Compute a value of game_state. The value is seen from the perspective of the
    player in turn. A favorable position for that player is given a positive value.
    """

    #global node_counter
    #node_counter += 1

    # If max depth is reached or if king is captured.
    if depth == 0 or abs(game_state.value) > 500:
        if game_state.white_to_play:
            return game_state.value
        else:
            return -game_state.value

    # Test child nodes.
    moves = game_state.pseudo_legal_moves_no_castlings()
    value_list = []

    # If no moves were found.
    if moves == []:
        return 0

    # Else, return a value based on child node values.
    best_value = -1000000
    for move in moves:
        game_state.make_move(move)
        new_value = -negamax(game_state, depth-1, -beta, -alpha)
        game_state.undo_move(move)
        best_value = max(best_value, new_value)
        alpha = max(alpha, new_value)
        if beta <= alpha:
            break
    return best_value
Compute a value of game_state. The value is seen from the perspective of the
    player in turn. A favorable position for that player is given a positive value.
    
Compute a value of game_state. The value is seen from the perspective of the
player in turn. A favorable position for that player is given a positive value.
Compute a value of game_state . The value is seen from the perspective of the player in turn . A favorable position for that player is given a positive value .
def negamax(game_state, depth, alpha, beta):
    if depth == 0 or abs(game_state.value) > 500:
        if game_state.white_to_play:
            return game_state.value
        else:
            return -game_state.value
    moves = game_state.pseudo_legal_moves_no_castlings()
    value_list = []
    if moves == []:
        return 0
    best_value = -1000000
    for move in moves:
        game_state.make_move(move)
        new_value = -negamax(game_state, depth-1, -beta, -alpha)
        game_state.undo_move(move)
        best_value = max(best_value, new_value)
        alpha = max(alpha, new_value)
        if beta <= alpha:
            break
    return best_value
def negamax ( game_state , depth , alpha , beta ) : if depth == 0 or abs ( game_state . value ) > 500 : if game_state . white_to_play : return game_state . value else : return - game_state . value moves = game_state . pseudo_legal_moves_no_castlings ( ) value_list = [ ] if moves == [ ] : return 0 best_value = - 1000000 for move in moves : game_state . make_move ( move ) new_value = - negamax ( game_state , depth - 1 , - beta , - alpha ) game_state . undo_move ( move ) best_value = max ( best_value , new_value ) alpha = max ( alpha , new_value ) if beta <= alpha : break return best_value
Compute a value of game_state.
Compute a value of game_state .
"""Compute a value of game_state. The value is seen from the perspective of the
    player in turn. A favorable position for that player is given a positive value.
    """ #global node_counter #node_counter += 1 # If max depth is reached or if king is captured. # Test child nodes. # If no moves were found. # Else, return a value based on child node values.
game_state
depth
alpha
beta