Exemplo n.º 1
0
def demo_path(puzzle, path):
    print("Enter speed (ms):")
    ms = util.read_number()
    sleep_time = ms / 1000
    print(puzzle_to_str(puzzle))
    path_len = len(path)
    while path:
        if sleep_time < 0:
            util.hit_enter()
        else:
            time.sleep(sleep_time)
        util.clear_screen()
        puzzle = puz.apply_action(puzzle, path[0])
        path = path[1:]
        print(puzzle_to_str(puzzle))
        print()
        print(path_len - len(path), "/", path_len)
        solved_tiles = puz.solved_tiles(puzzle)
        print(len(solved_tiles), solved_tiles)
Exemplo n.º 2
0
 def expand(self):
     return [Node(puzzle.apply_action(self.p, a),
                  self.hist + [a], self.heuristic)
             for a in self.useful_actions()]