From 03eb347e0d930a7911a8028286e61e161f9a19f8 Mon Sep 17 00:00:00 2001 From: Dima Date: Sat, 23 May 2026 19:34:11 +0300 Subject: [PATCH] =?UTF-8?q?1=20=D1=8D=D1=82=D0=B0=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nikolaevda/task2/Zadanie2.py | 57 +++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/nikolaevda/task2/Zadanie2.py b/nikolaevda/task2/Zadanie2.py index 5559d77..5c34ea6 100644 --- a/nikolaevda/task2/Zadanie2.py +++ b/nikolaevda/task2/Zadanie2.py @@ -1 +1,56 @@ -from numpy import \ No newline at end of file +import sys +from collections import deque +import heapq +import time +import os + +class Cell: + """клетка лабиринта""" + def __init__(self, x, y, is_wall=False, is_start=False, is_exit=False): + self.x = x + self.y = y + self.is_wall = is_wall + self.is_start = is_start + self.is_exit = is_exit + + def is_passable(self): + return not self.is_wall + + def __repr__(self): + return f"Cell({self.x}, {self.y})" + + +class Maze: + """лабиринт""" + def __init__(self, width, height): + self.width = width + self.height = height + self.cells = [[Cell(x, y) for x in range(width)] for y in range(height)] + self.start = None + self.exit = None + + def get_cell(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + return self.cells[y][x] + return None + + def get_neighbors(self, cell): + neighbors = [] + directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] + for dx, dy in directions: + neighbor = self.get_cell(cell.x + dx, cell.y + dy) + if neighbor and neighbor.is_passable(): + neighbors.append(neighbor) + return neighbors + + def set_start(self, x, y): + cell = self.get_cell(x, y) + if cell: + cell.is_start = True + self.start = cell + + def set_exit(self, x, y): + cell = self.get_cell(x, y) + if cell: + cell.is_exit = True + self.exit = cell \ No newline at end of file