Exemplo n.º 1
0
def king_safety(board, side):
    score = 0
    king = 12
    if side == 1:
        king = 13
    enemy = 1 - side
    king_location = PM.get_piece_location(king, board)
    if PM.is_frozen(king_location, board, side):
        score -= 50
    if PM.is_king_in_check(board, king_location, side):
        return score - 500
    else:
        enemy_coordinator = 5
        if side == 1:
            enemy_coordinator = 4
        coordinator_location = PM.get_piece_location(enemy_coordinator, board)
        enemy_king = 13
        if side == 1:
            enemy_king = 12
        enemy_king_location = PM.get_piece_location(enemy_king, board)
        if coordinator_location is not None:
            if coordinator_location[0] == king_location[0]:
                if abs(enemy_king_location[1] - king_location[1]) == 1:
                    score -= 100
                else:
                    score -= 50
            elif coordinator_location[1] == king_location[1]:
                score -= 10
    return score
def king_safety(board, side):
    score = 0
    king = 12
    if side == 1:
        king = 13
    enemy = 1 - side
    king_location = PM.get_piece_location(king, board)
    if PM.is_king_in_check(board, king_location, side):
        return 100
    else:
        for i in range(8):
            next = PM.get_next_space(king_location, i)
            if next == None: continue
            if board[next[0]][next[1]] == 0:
                score -= 2
            elif board[next[0]][next[1]] % 2 == enemy:
                score -= 10
            else:
                score += 2
    return score