def check_winner(board_state):
    """
        Iterates over the board spaces,
        Recording the indices of 1's (1) and 0's (0) in two sets.

        Iterates through the winning combinations in WINNERS
        to see if there is a winner.

        Returns 1, 0, or -1 if True wins, False wins,
        or if there is a tie, respectively.

        Returns None if there is no winner or tie.

        (True and False can represent X's or O's in the game
        and either True or False can go first.)
    """

    # the indices of the winning positions.
    WINNERS = set()
    WINNERS.add((0,1,2))
    WINNERS.add((3,4,5))
    WINNERS.add((6,7,8))
    WINNERS.add((0,3,6))
    WINNERS.add((1,4,7))
    WINNERS.add((2,5,8))
    WINNERS.add((0,4,8))
    WINNERS.add((2,4,6))

    indices_ones = set()
    indices_zeroes = set()

    # iterate over board spaces. record indices in sets.
    for i, board_position in enumerate(board_state):
        if board_position == 1:
            indices_ones.add(i)
        elif board_position == 0:
            indices_zeroes.add(i)

    # iterate through the set of winner tuples.
    # for each item in a winning configuration, check
    # if the item is contained in one of the sets.
    for winner in WINNERS:
        One_count = 0
        Zero_count = 0
        for w in winner:
            if w in indices_ones:
                One_count += 1
            elif w in indices_zeroes:
                Zero_count += 1

        # 1 wins
        if One_count == 3:
            return 1
        # 0 wins
        elif Zero_count == 3:
            return 0
    # tie
    return -1 if len(indices_ones) + len(indices_zeroes) == len(board_state) else None