A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
23
Task/Maze-generation/Python/maze-generation.py
Normal file
23
Task/Maze-generation/Python/maze-generation.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from random import shuffle, randrange
|
||||
|
||||
def make_maze(w = 16, h = 8):
|
||||
vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)]
|
||||
ver = [["| "] * w + ['|'] for _ in range(h)] + [[]]
|
||||
hor = [["+--"] * w + ['+'] for _ in range(h + 1)]
|
||||
|
||||
def walk(x, y):
|
||||
vis[y][x] = 1
|
||||
|
||||
d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, y - 1)]
|
||||
shuffle(d)
|
||||
for (xx, yy) in d:
|
||||
if vis[yy][xx]: continue
|
||||
if xx == x: hor[max(y, yy)][x] = "+ "
|
||||
if yy == y: ver[y][max(x, xx)] = " "
|
||||
walk(xx, yy)
|
||||
|
||||
walk(randrange(w), randrange(h))
|
||||
for (a, b) in zip(hor, ver):
|
||||
print(''.join(a + ['\n'] + b))
|
||||
|
||||
make_maze()
|
||||
Loading…
Add table
Add a link
Reference in a new issue