def generate(self): print 'Generating...' global size, heuristicNo state = generateSlidingBlockGrid(size) print 'Solving...' global sb sb = SlidingBlock(state) global search global lastAction lastAction = None if heuristicNo == 1: search = astar_search(sb, lambda x: h1(x)) elif heuristicNo == 2: search = astar_search(sb, lambda x: h2(x)) elif heuristicNo == 3: search = astar_search(sb, lambda x: h3(x)) elif heuristicNo == 4: search = astar_search(sb, lambda x: h4(x)) if search == None: self.generate() return print "Actions to solution:", len(search.solution()) if (len(search.solution())): lastAction = 0 else: lastAction = None grid.reset(state) return
def step(self): global lastAction, search, sb if lastAction != None: state = sb.result(grid.state, search.solution()[lastAction]) lastAction += 1 if (not lastAction < len(search.solution())): lastAction = None grid.reset(state) return True return False
def generate(self): print 'Generating...' global size, heuristicNo state = generateSlidingBlockGrid(size) print 'Solving...' global sb sb = SlidingBlock(state) global search global lastAction lastAction = None if heuristicNo == 1: search = astar_search(sb, lambda x : h1(x)) elif heuristicNo == 2: search = astar_search(sb, lambda x : h2(x)) elif heuristicNo == 3: search = astar_search(sb, lambda x : h3(x)) elif heuristicNo == 4: search = astar_search(sb, lambda x : h4(x)) if search == None: self.generate() return print "Actions to solution:", len(search.solution()) if (len(search.solution())): lastAction = 0 else: lastAction = None grid.reset(state) return
def solve(self): for i in range(len(search.solution())): self.after(i*500, self.step) return
def solve(self): for i in range(len(search.solution())): self.after(i * 500, self.step) return