def handle_moves(game_state: GameState, message: str) -> GameState: ''' Converts move command message into function call, returns new gamestate ''' try: if message.startswith("DROP"): return connectfour_console.drop(game_state, int(message.split(" ")[1])-1) elif message.startswith("POP"): return connectfour_console.pop(game_state, int(message.split(" ")[1])-1) except connectfour_console.InvalidMoveError: print("Invalid move") return game_state
def read_move(game_state: GameState) -> GameState: ''' Asks user whether they want to drop or pop, and returns a function call to the move ''' while True: try: move_num = read_num() move_type = input("> Would you like to drop or pop? Type drop/pop\n") if move_type.lower() == "drop": return connectfour_console.drop(game_state, move_num) elif move_type.lower() == "pop": return connectfour_console.pop(game_state, move_num) else: print("Please type 'drop' or 'pop' (not case-sensitive)\n") except connectfour_console.InvalidMoveError: print("Invalid move, try again. (Piece is not yours or column is empty)")