2026-rff_mp/zhigalovrd/lab2/visualizer.py

24 lines
825 B
Python

from typing import List, Optional
from maze import Maze, Cell
class ConsoleView:
@staticmethod
def render(maze: Maze, path: Optional[List[Cell]] = None, player_pos: Optional[Cell] = None):
path_set = set(path) if path else set()
for y in range(maze.height):
row = ''
for x in range(maze.width):
cell = maze.get_cell(x, y)
if player_pos and cell is player_pos:
row += 'P'
elif cell.is_start:
row += 'S'
elif cell.is_exit:
row += 'E'
elif cell.is_wall:
row += '#'
elif path and cell in path_set:
row += '.'
else:
row += ' '
print(row)