import random

def save_maze(filename, width, height, wall_probability):
    maze = []
    for i in range(height):
        row = ""
        for j in range(width):
            if i == 0 or i == height-1:
                row += "#"
            elif j == 0 or j == width-1:
                row += "#"
            else:
                if random.random() < wall_probability:
                    row += "#"
                else:
                    row += " "

        maze.append(list(row))
    maze[1][1] = "S"
    maze[height-2][width-2] = "E"

    for i in range(1, height-1):
        maze[i][1] = " "
    for j in range(1, width-1):
        maze[height-2][j] = " "
    maze[1][1] = "S"
    maze[height-2][width-2] = "E"
    with open(filename, "w", encoding="utf-8") as f:
        for row in maze:
            f.write("".join(row)+"\n")
save_maze(
    "medium_maze.txt",
    50,
    50,
    0.30
)
save_maze(
    "big_maze.txt",
    100,
    100,
    0.40
)
print("Лабиринты созданы")