Anonymous user
Maze generation: Difference between revisions
→{{header|Python}}: replacing both method (they were pretty similar)
(→{{header|Python}}: replacing both method (they were pretty similar)) |
|||
Line 1,448:
=={{header|Python}}==
<lang python>from random import
def make_maze(
vis = [[0] *
vis[y][x] = 1
if j >= 0 and j < width and i >= 0 and i < height▼
if not visited[i][j] ]▼
d = [(x -
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)] = " "
for (a, b) in zip(hor, ver):
| |
+ + + + + +
| | | | | | | | | |▼
▲ walk(0, 0)
| | | | | | | | | |▼
+ +--+ +--+--+ + +--+ +--+--+ +--+--+ + +▼
| | | | | | | |▼
| | | | | | | |▼
+ +--+--+ +--+--+
|
+ +--+ +--+--+--+ + +--+--+--+--+ +--+ + +▼
▲ print("".join(s1 + ["*\n"] + s2 + ["|"]))
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</lang>▼
▲show_maze(make_maze(8, 11))</lang>output<lang>+--+--+--+--+--+--+--+--+--+--+--+
▲| | | | |
▲+--+ + +--+ + + +--+ +--+ +
▲| | | | | | | |
▲| | | | | | | |
▲+ +--+ + + +--+ +--+--+ + +
▲+--+ +--+ +--+ +--+ + +--+--+
▲+ + + +--+ +--+--+ +--+--+ +
▲+ + +--+ +--+--+--+--+ + + +
▲| | | |
▲+--+--+--+--+--+--+--+--+--+--+--+</lang>
▲seen = [[False] * H for _ in xrange(W)]
▲visit(randrange(W), randrange(H))
=={{header|Tcl}}==
|