def execute(self, p, locked): """p: das Feld auf dem die Aktion ausgeführt werden soll locked: eine Menge von Positionen die nicht bewegt werden dürfen. Die erste Position die durch die Aktion betreten wird, wird autoamtisch gelockt""" log.debug("executing PosAction; start: {}, actions: {}".format(self.start_position, self.actions)) l = locked.copy() l.add(self.locked_position()) # die erste Position wird automatisch gelockt! path = a_star(p.shape[0], puz.empty_position(p), self.start_position, l) assert path, "PosAction not executable, starting position not reachable" init_actions = coords_to_actions(path) # log.info("moving into start pos., path: {}".format(init_actions)) p = puz.apply_actions(p, init_actions) p = puz.apply_actions(p, self.actions) return p, init_actions + self.actions
def rec_a_star(p, selector = SubSelect()): solved = puzzle.solved(p) path = [] while selector.applicable(p): tiles_to_solve = [t for t in solved.flat if t not in selector.apply(solved)] heuristic = lambda puz: manhattan_dist_sum(puz, tiles_to_solve) new_path = ida_star(p, heuristic) path += new_path p = selector.apply(puzzle.apply_actions(p, new_path)) solved = selector.apply(solved) path += a_star(p, manhattan_dist_sum) return path