Esempio n. 1
0
def mainMenu():
    chessBoard = []
    while True:
        if os.name == 'nt':  # Windows
            os.system('cls')
        elif os.name == 'posix':  # Linux
            os.system('clear')

        print(colorize(header, 'pink'))
        i = 1
        for item in menuItems:
            print("[" + str(i) + "] " + colorize(item, 'blue'))
            i += 1

        choice = int(input(">> "))

        try:
            if choice < 1:
                raise ValueError

            # Call the matching function
            if choice == 1:
                Printer.printDir("Inputs/")
                chessBoard = BoardHandler.createChessboard()
            elif choice == 2:
                Printer.printDir("Inputs/")
                chessBoard = BoardHandler.readChessboard()
            elif choice == 3:
                Printer.printChessBoard(chessBoard)
            elif choice == 7:
                credit()
            elif choice == 8:
                exit(0)
            else:
                print(">> That is not a valid input.")
        except (ValueError, IndexError):
            pass

        while True:
            text = input("\n>> Press enter to continue.")
            if text == "":
                break
            else:
                print("\n>> You did not press enter.")

        print("\n\n")
Esempio n. 2
0
def mainMenu():
    chessBoard = []

    # Clear screen
    while True:
        if os.name == 'nt':  # Windows
            os.system('cls')
        elif os.name == 'posix':  # Linux
            os.system('clear')

        # Print header & menu options
        print(colorize(header, 'pink'))
        i = 1
        for item in menuItems:
            print("[" + str(i) + "] " + colorize(item, 'blue'))
            i += 1

        choice = int(input(">> "))

        try:
            if choice < 1:
                raise ValueError

            # Call the matching function
            if choice == 1:
                Printer.printDir("Inputs/")
                chessBoard = BoardHandler.createChessboard()
            elif choice == 2:
                Printer.printDir("Inputs/")
                chessBoard = BoardHandler.readChessboard()
            elif choice == 3:
                Printer.printChessBoard(chessBoard)
            elif choice == 4:
                maxTry = int(input(">> Enter maximum try : "))
                Printer.printChessBoard(hc.hillC(maxTry, chessBoard))
            elif choice == 5:
                maxTry = int(input(">> Enter maximum try : "))
                Printer.printChessBoard(
                    SimulatedAnnealing.simulatedAnnealing(maxTry, chessBoard))
            elif choice == 6:
                Genetic.GeneticAlgorithm(
                    BoardHandler.createPiecesList(chessBoard))
            elif choice == 7:
                helpMe()
            elif choice == 8:
                credit()
            elif choice == 9:
                exit(0)
            else:
                print(">> That is not a valid input.")
        except (ValueError, IndexError):
            pass

        # Users need to press enter to continue using program (refresh the display)
        while True:
            text = input("\n>> Press enter to continue.")
            if text == "":
                break
            else:
                print("\n>> You did not press enter.")

        print("\n\n")