示例#1
0
文件: UI.py 项目: ReteganCatalin/AI
class Menu():
    def __init__(self):
        self.Controller = Controller()

    def MainMenu(self):
        while (True):
            print("Give size of matrix (if 0 the program will stop):")
            size = int(input())
            if size != 0:
                self.Controller.ResizeAndRestart(size)
                print("Type of solution 1- dfs, 2-greedy")
                pick = input()
                if pick == '1':
                    FinalStates = self.Controller.DFS()
                    if len(FinalStates) != 0:
                        print("Correct States:")
                        for State in FinalStates:
                            print(State)
                    else:
                        print("No Solution Found !")
                else:
                    FinalState = self.Controller.Greedy()
                    if FinalState[0].CheckCorrectState() == True:
                        print("Correct Final State")
                    else:
                        print("Incorrect final state")
                    print(FinalState[0])
            else:
                return
示例#2
0
class UI:
    def __init__(self, size):
        self._initialConfig = Configuration(size)
        self._problem = Problem(self._initialConfig)
        self._controller = Controller(self._problem)

    def printMenu(self):
        print("\n---------------------\n" + "0 - exit\n" +
              "1 - solve with DFS\n" + "2 - solve with Greedy\n" +
              "3 - give new size\n")

    def run(self):
        runM = True
        self.printMenu()
        while runM:

            command = int(input(">"))
            if command == 0:
                runM = False
            elif command == 1:
                self.solveDFS()
            elif command == 2:
                self.solveBestFS()
            elif command == 3:
                self.reconfigure()
            self.printMenu()

    def solveDFS(self):
        startClock = time()
        print(self._controller.DFS(self._problem.getRoot()))
        print("execution time = ", time() - startClock, " seconds")

    def solveBestFS(self):
        startClock = time()
        print(self._controller.Greedy(self._problem.getRoot()))
        print("execution time = ", time() - startClock, " seconds")

    def reconfigure(self):
        size = 5
        try:
            print(
                "Input the size of the board and number of queens (implicit 5)"
            )
            size = int(input("size = "))
        except:
            print("Invalid input, implicit value is still in place")
        self._initialConfig = Configuration(size)
        self._problem = Problem(self._initialConfig)
        self._controller = Controller(self._problem)
示例#3
0
class UI:
    def __init__(self):
        try:
            n = int(input("Input the size of the board (implicit n=4)"))
        except:
            print("Invalid number. Size set to implict: 4.")
            n = 4
        matrix = np.zeros((n, n), dtype=int).tolist()
        self.__initialState = Matrix(n, matrix)
        self.__problem = Problem(self.__initialState)
        self.__controller = Controller(self.__problem)

    def mainMenu(self):
        print("Please choose an option from below:")
        print("0.Exit")
        print("1.Solve with DFS")
        print("2.Solve with greedy")

    def runBFS(self):
        solution = self.__controller.DFS(self.__problem.getRoot())
        if solution == []:
            print("No solution found")
        else:
            for s in solution:
                print(str(s))

    def runGBFS(self):
        solution = self.__controller.Greedy(self.__problem.getRoot())
        if solution == []:
            print("No solution found")
        else:
            print(str(solution))

    def run(self):
        self.mainMenu()
        finished = False
        while not finished:
            try:
                choice = int(input(">>"))
                if choice == 0:
                    finished = True
                elif choice == 1:
                    self.runBFS()
                elif choice == 2:
                    self.runGBFS()
            except ValueError:
                print("Invalid choice. Please choose one of 0,1 or 2")
示例#4
0
文件: UI.py 项目: Blondoor/Uni-work
class UI:
    def __init__(self, cntrl):
        self.cntrl = Controller(4)

    def menu(self):
        s = ''
        s += "0. Exit\n"
        s += "1. Read Board\n"
        s += "2. Resolve the problem using DFS\n"
        s += "3. Resolve the problem using Greedy"
        print(s)

    def readConfig(self):
        try:
            n = int(input("Dimension of the board (implicit value is 4): "))
            self.ctrl = Controller(n)
        except:
            print(
                "Invalid number, constructing the board with the implicit dimension 4"
            )
            self.ctrl = Controller(4)

    def run(self):

        while True:
            try:
                self.menu()
                cmd = int(input(">"))
                if cmd == 0:
                    return False
                elif cmd == 1:
                    self.readConfig()
                elif cmd == 2:
                    queue = self.cntrl.DFS()
                    print(queue)
                elif cmd == 3:
                    queue = self.cntrl.Greedy()
                    print(queue)
            except:
                print("Invalid command")