import random as rd

def CreateMazeFile(size):
    if size==10:
        with open("maze_10x10.txt","w") as f:
            for i in range(size):
                line=""
                for j in range(size):
                    temp=rd.randint(0, 2)
                    if temp==2:
                        line+="#"
                    else:
                        line+=" "
                if i==0:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="E"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                elif i==size-1:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="S"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                line+="\n"
                f.write(line)
    elif size==50:
        with open("maze_50x50.txt","w") as f:
            for i in range(size):
                line=""
                for j in range(size):
                    temp=rd.randint(0, 5)
                    if temp>3:
                        line+="#"
                    else:
                        line+=" "
                if i==0:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="E"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                elif i==size-1:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="S"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                line+="\n"
                f.write(line)
    elif size==100:
        with open("maze_100x100.txt","w") as f:
            for i in range(size):
                line=""
                for j in range(size):
                    temp=rd.randint(0, 5)
                    if temp>3:
                        line+="#"
                    else:
                        line+=" "
                if i==0:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="E"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                elif i==size-1:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="S"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                line+="\n"
                f.write(line)
    elif size==0:
        with open("maze_no_walls.txt","w") as f:
            size=rd.randint(10, 100)
            for i in range(size):
                line=""
                for j in range(size):
                    line+=" "
                if i==0:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="E"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                elif i==size-1:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="S"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                line+="\n"
                f.write(line)
    elif size==-1:
        with open("maze_no_exit.txt","w") as f:
            size=rd.randint(10, 100)
            for i in range(size):
                line=""
                for j in range(size):
                    temp=rd.randint(0, 5)
                    if temp>3:
                        line+="#"
                    else:
                        line+=" "
                if i==size-1:
                    l=list(line)
                    temp=rd.randint(1, size-2)
                    l[temp]="S"
                    line1=""
                    for k in range(len(line)):
                        line1+=l[k]
                    line=line1
                line+="\n"
                f.write(line)


CreateMazeFile(10) #10x10
CreateMazeFile(50) #50x50
CreateMazeFile(100) #100x100
CreateMazeFile(0) #no walls
CreateMazeFile(-1) #no exit
                
    