2026-rff_mp/SorokinAD/[2]lab_2/visualization.py

56 lines
974 B
Python

from abc import ABC, abstractmethod
from maze import Maze
from cell import Cell
class Observer(ABC):
@abstractmethod
def update(self, event: str):
pass
class ConsoleView(Observer):
def update(self, event: str):
print(f"[EVENT]: {event}")
def render(
self,
maze: Maze,
path: list[Cell] = None,
current: Cell = None
):
path = path or []
path_set = set(path)
for row in maze.cells:
line = ""
for cell in row:
if current and cell == current:
line += "P"
elif cell.is_start:
line += "S"
elif cell.is_exit:
line += "E"
elif cell.is_wall:
line += "#"
elif cell in path_set:
line += "."
else:
line += " "
print(line)