예제 #1
0
class GUI(tk.Tk):
    def __init__(self, columns, rows):
        tk.Tk.__init__(self)
        self.columns = columns
        self.rows = rows
        self.gac = GAC(columns, rows)
        self.search = Search(self.gac)
        solution = self.search.a_star()
        "ASDASDJKASHDKAJSD"
        self.canvas = tk.Canvas(self, width=800, height=800, borderwidth=0)
        self.canvas.pack(side="top", fill="both", expand="true")

        menubar = tk.Menu(self)

        mapMenu = tk.Menu(menubar)
        mapMenu.add_command(label="Scenario 0",
                            command=lambda: self.changeMap('scenario0.txt'))
        mapMenu.add_command(label="Scenario 1",
                            command=lambda: self.changeMap('scenario1.txt'))
        mapMenu.add_command(label="Scenario 2",
                            command=lambda: self.changeMap('scenario2.txt'))
        mapMenu.add_command(label="Scenario 3",
                            command=lambda: self.changeMap('scenario3.txt'))
        mapMenu.add_command(label="Scenario 4",
                            command=lambda: self.changeMap('scenario4.txt'))
        mapMenu.add_command(label="Scenario 5",
                            command=lambda: self.changeMap('scenario5.txt'))
        mapMenu.add_command(label="Scenario 6",
                            command=lambda: self.changeMap('scenario6.txt'))
        menubar.add_cascade(label="Maps", menu=mapMenu)
        self.config(menu=menubar)

    def changeMap(self, mapFileName):
        print mapFileName
        os.execl(sys.executable, 'python', __file__, mapFileName)
예제 #2
0
파일: a_star.py 프로젝트: kittleik/aiprog
class GUI(tk.Tk):
    def __init__(self, columns, rows):
        tk.Tk.__init__(self)
        self.columns = columns
        self.rows = rows
        self.gac = GAC(columns,rows)
        self.search = Search(self.gac)
        solution = self.search.a_star()
        "ASDASDJKASHDKAJSD"
        self.canvas = tk.Canvas(self, width = 800, height = 800, borderwidth = 0)
        self.canvas.pack(side="top", fill="both", expand="true")



        menubar = tk.Menu(self)

        mapMenu = tk.Menu(menubar)
        mapMenu.add_command(label="Scenario 0", command= lambda: self.changeMap('scenario0.txt'))
        mapMenu.add_command(label="Scenario 1", command= lambda: self.changeMap('scenario1.txt'))
        mapMenu.add_command(label="Scenario 2", command= lambda: self.changeMap('scenario2.txt'))
        mapMenu.add_command(label="Scenario 3", command= lambda: self.changeMap('scenario3.txt'))
        mapMenu.add_command(label="Scenario 4", command= lambda: self.changeMap('scenario4.txt'))
        mapMenu.add_command(label="Scenario 5", command= lambda: self.changeMap('scenario5.txt'))
        mapMenu.add_command(label="Scenario 6", command= lambda: self.changeMap('scenario6.txt'))
        menubar.add_cascade(label="Maps", menu=mapMenu)
        self.config(menu=menubar)



    def changeMap(self,mapFileName):
        print mapFileName
        os.execl(sys.executable, 'python', __file__, mapFileName)
예제 #3
0
        grid.build_wall()

    elif menu.remove:
        grid.remove_wall()

    if menu.run():
        for row in grid.grid:
            for node in row:
                node.visited = False
                node.in_path = False
        if menu.BFS:
            search.BFS(grid.start_node, grid.end_node)
        elif menu.DFS:
            search.DFS(grid.start_node, grid.end_node)
        elif menu.A_star:
            search.a_star(grid.start_node, grid.end_node)

# call back function for menu options
    menu.choose_serach()
    menu.build_walls()
    menu.remove_walls()
    menu.set_start()
    menu.set_end()
    menu.visulise()
    menu.clear_clicked()
    menu.choose_serach()

    if menu.solve():
        grid.user_solve()

    if menu.build_maze():
예제 #4
0
                pos_x, pos_y = myGrid.getCell(pos_x, pos_y)
                rec = pygame.Rect(pos_x, pos_y, 20, 20)
                pygame.draw.rect(myGrid.screen, config.fill, rec)
                myMatrix.setCell(pos_y // 20, pos_x // 20, "B")
                pygame.display.update()
            except:
                pass
    pygame.display.flip()

# Start a thread of the algorithm user selected
if algorithm == "BFS":
    t1 = threading.Thread(target=myMatrix.bfs())
elif algorithm == "DFS":
    t1 = threading.Thread(target=myMatrix.dfs())
elif algorithm == "A-Star":
    t1 = threading.Thread(target=myMatrix.a_star())

t1.start()

# Color in cells from the search algorithm and wait for quitgame
while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    if not gridQ.empty():
        x, y, clr = gridQ.get()

        myGrid.fillSquare(x, y, clr)
        pygame.display.update()