def mobility(board, side):
    enemy = 1 - side
    moves = 0
    #copy = BC.BC_state(board, side)
    #print(copy)
    for r in range(8):
        for c in range(8):
            piece = board[r][c]
            if PIECES[piece] != '-' and piece % 2 == side:
                limit = 8
                if PIECES[piece] in ['p', 'P']:
                    limit = 4
                for i in range(limit):
                    dest = PM.get_next_space((r, c), i)
                    while dest is not None:
                        dest_piece = board[dest[0]][dest[1]]
                        if PIECES[dest_piece] != '-':
                            if dest_piece % 2 == side: break
                            if PIECES[piece] not in [
                                    'i', 'I', 'l', 'L', 'k', 'K'
                            ]:
                                if dest_piece % 2 == enemy: break
                        if PM.can_move((r, c), dest, board, i):
                            moves += 1
                        if PIECES[piece] in ['k', 'K']: break
                        dest = PM.get_next_space(dest, i)
    #print("\n")
    #print(moves)
    #print(copy)
    return moves
def get_moves(location, state, dir, whoseMove, successors):
    dest = PM.get_next_space(location, dir)
    piece = state.board[location[0]][location[1]]
    enemy = 1 - whoseMove
    while dest is not None:
        dest_piece = state.board[dest[0]][dest[1]]
        if dest_piece != 0 and dest_piece % 2 == whoseMove: break
        if PIECES[piece] not in ['i', 'I', 'l', 'L', 'k', 'K']:
            if dest_piece != 0 and dest_piece % 2 == enemy: break
        if PM.can_move(location, dest, state.board, dir):
            move = (location, dest, dir)
            successors.append(move)
        if piece in ['k', 'K']: break
        dest = PM.get_next_space(dest, dir)
    return successors
def get_moves(location, state, dir, whoseMove):
    successors = []
    dest = PM.get_next_space(location, dir)
    piece = state.board[location[0]][location[1]]
    enemy = 1 - whoseMove
    while dest is not None:
        dest_piece = state.board[[dest[0]]][dest[1]]
        if dest_piece != 0 and dest_piece % 2 == whoseMove: break
        if PIECES[piece] not in ['i', 'I', 'l', 'L', 'k','K']:
            if dest_piece != 0 and dest_piece % 2 == enemy: break
        if PM.can_move(location, dest, state, dir):
            #print(location)
            #print(dest)
            #print("\n")
            new_state = PM.move(location, dest, state, dir)
            successors.append(new_state)
        dest = PM.get_next_space(dest, dir)
        if piece in ['k','K']: break
        #print(dest)
        #print("\n")
    return successors
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