2026-rff_mp/stepushovgs/labyrinth/docs/Отчёт.md

3.7 KiB

Описание работы

Схема реализованных классов:

classDiagram
	class TextFileMazeBuilder {
        +buildFromFile(filename): Maze
    }
    class Maze {
        -cells: Cell[] 
        -width: int
        -height: int
        -start: Cell
        -exit: Cell
        +getCell(x,y): Cell
        +getNeighbors(cell): List~Cell~
    }
    
    class Cell {
        -x: int
        -y: int
        -isWall: bool
        -isStart: bool
        -isExit: bool
        -value: int
        +isPassable(): bool
        +getXY(): tuple[int, int]
        +toStr(): str
    }
    
    class MazeBuilder {
        <<interface>>
        +buildFromFile(filename): Maze
    }
    
    class PathFindingStrategy {
        <<interface>>
        +name(): str
        +findPath(maze, start, exit): tuple[list[tuple[int, int]], int]
    }
    
    class BFSStrategy
    class DFSStrategy
    class AStarStrategy
    class DijkstraStrategy
    
    class SearchStats {
        -timeMs: float
        -visitedCells: int
        -pathLength: int
        -path: list~Cell~
    }
    
    class MazeSolver {
        -Maze maze
        -PathFindingStrategy strategy
        -Observer observer
        +strategyName: str
        +setStrategy(strategy)
        +solve(): SearchStats
    }
    
    class Observer {
        <<interface>>
        +update(event)
    }
    
    class ConsoleView {
        +update(event)
        +render(maze, player_position, path)
    }
    
    class Event {
	    -event: str
	    -maze: Maze
	    -player_position: tuple[int,int]
	    -path: list~Cell~
    }
    
    MazeBuilder <|.. TextFileMazeBuilder
    MazeBuilder --> Maze : creates
    PathFindingStrategy <|.. BFSStrategy
    PathFindingStrategy <|.. DFSStrategy
    PathFindingStrategy <|.. AStarStrategy
    PathFindingStrategy <|.. DijkstraStrategy
    MazeSolver --> PathFindingStrategy : uses
    MazeSolver --> Maze : uses
    Maze --> Cell : uses
    MazeSolver --> SearchStats : return
    Observer <|.. ConsoleView
    ConsoleView --> Event : get
    MazeSolver --> Observer : notifies

Ключевые классы

  1. Листинги ключевых классов (можно выборочно) или ссылка на репозиторий.
  • Классы Cell и Maze представлены в папке source/classes/
  • Реализации интерфейса Builder и класса TextFileMazeBuilder находятся в source/builder/
  • Реализации интерфейса Observer и класса ConsoleView находятся в source/observer/
  • Интерфейс strategy, класс MazeSolver и реализации алгоритмов BFS, DFS, A*, Дейкстры находятся в папке source/strategy/

Результаты экспериментов

!10x10.pdf !50x50.pdf !100x100.pdf !empty.pdf !no_path.pdf

Заполним таблицу для количества посещённых клеток для каждого алгоритма:

Лабиринт BFS DFS A* Дейкстра
10\times10 25 24 24 25
50\times50 1157 1142 805 1157
100\times100 4268 3191 4229 4268
Пустой 5328 5328 5328 5328
Без выхода 1257 1257 1257 1257

Анализ результатов

  1. Анализ эффективности алгоритмов и применимости паттернов.

Выводы

  1. Выводы: как ООП и паттерны помогли сделать код гибким и расширяемым. Что было бы сложно изменить без них.