Beispiel #1
0
 def on_sample_chosen(self):
     size = self.sample_radio_id.get()
     logging.info('Loading sample of size ' + str(size))
     self.grid_size, self.pipe_ends = Samples.get_puzzle(str(size))
     self.on_grid_size_changed()
     self.grid_manager.load_maze(self.grid_size, self.pipe_ends)
     self.ready_for_run = True
     self.init_run()
            wall_nb = max(start_walls, target_walls)
            score += wall_nb * 10

            # increase score if the distance between the start and target is high
            distance = self.shortest_path(start, target, self.original_id(i))
            if distance > self.grid_size / 2:
                score += distance * 2

            if score > best_score:
                best_pipe = i
                best_score = score

        logging.debug("Choosing next pipe {0}".format(
            self.original_id(best_pipe)))

        # flip the next pipe with the one we want to process
        if best_pipe != self.curr_pipe:
            original_best_pipe_id = self.pipes_mapping[best_pipe]
            self.pipes_mapping[best_pipe] = self.pipes_mapping[self.curr_pipe]
            self.pipes_mapping[self.curr_pipe] = original_best_pipe_id


if __name__ == "__main__":
    setup_logging()
    (size, pipes) = Samples.get_puzzle("12")
    engine = ShortestPathEngine(size, pipes)
    while not engine.solved:
        for next_move in engine.next_moves():
            logging.debug(next_move)
    logging.info(engine.display())