def solvePuzzle(self):
        self.lblSteps['text']=''
        self.lblSteps.update()
        self.lblExpandedNodes['text']=''
        self.lblExpandedNodes.update()
        self.lblrunningTime['text']=''
        self.lblrunningTime.update()
        self.drawBoard(self.rushhour.get_board())

        heuristic = ZeroHeuristic()
        if self.heuristicChoice.get() == 2:
            heuristic = DistanceFromTargetToExit()
        elif self.heuristicChoice.get() == 3:
            heuristic = BlockingExitHeuristic()
        elif self.heuristicChoice.get() == 4:
            heuristic = BlockingLowerBoundEstimation()
        aStar = AStar(heuristic)
        elapsedTime = time.time()
        sol = aStar.aStar(self.rushhour)
        runningTime = round((time.time()-elapsedTime)*1000)
        lbl = Label(self.bottomRightPanel, text = 'Steps: ')
        lbl.grid(row = 7, column = 0,sticky=W)

        steps = 0
        for board in sol['Solution']:
            self.drawBoard(board.get_board())
            self.lblSteps['text'] = str(steps)
            self.lblSteps.update()
            steps += 1
            time.sleep(.5)
        lbl = Label(self.bottomRightPanel, text = 'Expanded Nodes: ')
        lbl.grid(row = 8, column = 0,sticky=W)

        lbl = Label(self.bottomRightPanel, text = 'Running Time: ')
        lbl.grid(row = 9, column = 0,sticky=W)

        self.lblExpandedNodes['text'] = str(sol['Expanded Nodes'])
        self.lblrunningTime['text'] = str(runningTime)+' ms'
        while not self.__onBoundries(x, y, randomSize, randomVType) :
            x = random.randint(0,5)
            y = random.randint(0,5)
        return Vehicle(randomVehicleID,x,y,randomVType)

##########################
boardConfigsFolder = "C:/Users/Abbas/PycharmProjects/Rush Hour Puzzle Game/New folder"
if __name__ == '__main__':
    aStar = AStar(BlockingExitHeuristic())
    rushHourPuzzles = []
    generator = Generator(12,12)
    i = 0
    while i < 25:
        puzzle = generator.generate()
        if puzzle:
            sol = aStar.aStar(puzzle)
            if sol['Steps'] > 10 :
                while True:
                    alreadyExist = False
                    for p in rushHourPuzzles:
                        if p.isSamePuzzle(puzzle):
                            alreadyExist = True
                            break
                    if not alreadyExist:
                        break
                    puzzle = generator.generate()

                rushHourPuzzles.append(puzzle)
                filename =boardConfigsFolder+"/" +"12_{0}.txt".format(i)
                savePuzzle(puzzle, filename)
                print("Puzzle {0}".format(i), "Steps {0}".format(sol['Steps']))
Exemplo n.º 3
0
def main(args):
    search = AStar(sys.argv[1])
    search.aStar()