def read_conversation(connection: ServerConnection, message: str, game_state: GameState) -> GameState:
    ''' Sends message to server and handles received messages '''
    connectfour_network.send_message(connection, message)
    AI_message = connectfour_network.receive_message(connection)

    if AI_message == "OKAY":
        # our move
        game_state = handle_moves(game_state, message)
        connectfour_UI.print_board(game_state)

        # AI's move
        AI_move = connectfour_network.receive_message(connection)
        print("AI decided to {}!".format(str(AI_move)))
        game_state = handle_moves(game_state, AI_move)
        connectfour_UI.print_board(game_state)

    elif AI_message == "INVALID":
        print("\nInvalid move")
        print()
        pass

    elif AI_message.startswith("WINNER"):
        # our move
        game_state = handle_moves(game_state, message)
        connectfour_UI.print_board(game_state)

    return game_state
def play_AI(connection: ServerConnection, username: str):
    ''' Starts connect four game with server, creates a new game, and prints the winner '''
    connectfour_network.send_message(connection, "I32CFSP_HELLO {}".format(username))
    print(connectfour_network.receive_message(connection)) # WELCOME name
    connectfour_network.send_message(connection, "AI_GAME")

    game_mirror = connectfour_console.new_game()
    connectfour_UI.print_board(game_mirror)

    while connectfour_console.winner(game_mirror) == 0:
        message = read_move()

        if message == "!q":
            break
        else:
            if connectfour_network.receive_message(connection) == "READY":
                game_mirror = read_conversation(connection, message, game_mirror)

    connectfour_UI.print_game_over(game_mirror)