Maze Pattern Building in Python

410 Views Asked by At

Hello I am a newbie to python and using python 3. I wish to learn patterns and printing e.g stars etc. I want to make maze pattern but i confused to make maze no 2-no4

No 1

    @ @@@@@@@@@@@@@
    @             @
    @@@@@@@@@@@@@ @
    @             @
    @ @@@@@@@@@@@@@
    @             @
    @@@@@@@@@@@@@ @
    @             @
    @ @@@@@@@@@@@@@
    @             @
    @@@@@@@@@@@@@ @
    @             @
    @ @@@@@@@@@@@@@
    @             @
    @@@@@@@@@@@@@ @

No 2

    @ @@@@@@@@@@@@@
    @ @   @   @   @
    @ @ @ @ @ @ @@@
    @ @ @ @ @ @   @
    @ @ @ @ @ @@@ @
    @ @ @ @ @     @
    @ @ @ @ @@@@@@@
    @ @ @ @       @
    @ @ @ @@@@@@@ @
    @ @ @         @
    @ @ @@@@@@@@@@@
    @ @           @
    @ @@@@@@@@@@@ @
    @             @
    @@@@@@@@@@@@@@@

No 3 

    @ @@@@@@@@@@@@@
    @ @           @
    @ @ @@@@@@@@@ @
    @ @ @       @ @
    @ @ @ @@@@@ @ @
    @ @ @ @   @ @ @
    @ @ @ @ @ @ @ @
    @ @ @ @ @ @ @ @
    @ @ @ @@@ @ @ @
    @ @ @     @ @ @
    @ @ @@@@@@@ @ @
    @ @         @ @
    @ @@@@@@@@@@@ @
    @             @
    @@@@@@@@@@@@@@@

No 4 

    @ @@@@@@@@@@@@@
    @ @           @
    @ @ @@@@@@@@@ @
    @ @ @       @ @
    @ @ @ @@@@@ @ @
    @ @ @ @   @ @ @
    @ @ @ @ @ @ @ @
    @ @ @ @ @ @ @ @
    @ @ @ @ @ @ @ @
    @ @ @   @ @ @ @
    @ @ @@@@@ @ @ @
    @ @       @ @ @
    @ @@@@@@@@@ @ @
    @           @ @
    @@@@@@@@@@@@@ @

This is my code maze no1:

def SimpleMaze(S):
    bool=1
    for i in range(S):
        if (i+1)%2==0:
            print('@'+' '*(S-2)+'@')
        else:
            if bool==1:
                print('@'+' '+'@'*(S-2))
            else:
                print('@'*(S-2)+' '+'@')
            bool=not bool
S= input("Nilai S:")
SimpleMaze(int(S))
1

There are 1 best solutions below

0
On

You built Maze 1 by assembling it row by row, but the other mazes appear to have messier patterns when you think about them in terms of rows.

Here's another way to break down the problem. Start with a solid block, with rows 0..R and columns 0..C (inclusive).

@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@

Then envision yourself creating a maze by driving a bulldozer through it, opening up the path as you go. Under this approach, we can represent a maze as a set of driving instructions. For example, Maze 1 looks like this:

Start at r==-1, c==1.
Go South 2 steps.
Go East until c==C-1.
Go South 2 steps.
Go West until c==1.
Repeat ... until r>R.

I think Mazes 2 through 4 will be easier to think about in those terms. Ideally, each of those concepts (go south, go east, etc) could be implemented as simple functions or methods.