from .cell import Cell import logging from graphviz import Digraph, render class Player(Cell): def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.destination = None self.paths = [] self.depth = 0 def plot_paths(self, name:str = "shortest_paths") -> None: dot = Digraph(comment='Paths') for path in self.paths: for i in range(len(path) - 1): dot.edge(str(path[i]), str(path[i + 1])) dot.save(f'{name}.dot') render('dot', 'png', f'{name}.dot') def find_paths(self, destination: tuple = (0, 0)): self.destination = Cell(pose=destination) if self.destination.pose[0] < 0 or self.destination.pose[1] > 8 or self.destination.pose[0] < 0 or self.destination.pose[1] > 8: logging.error("Invalid destination position: it should be between 0 and 7") return while len(self.paths) < 1: self.depth += 1 self.make_moves(self.destination, self.paths)