forked from morgangch/Jam2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_lab.py
88 lines (78 loc) · 2.39 KB
/
gen_lab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python3
import csv
from sys import argv
import math
import random
lenght = 10
height = 10
Labyrinth = [ [[0, 0, 0, 0] for i in range(lenght)] for j in range(height)]
def is_explored(cell):
for i in range(4):
if (cell[i] == 1):
return 1
return 0
def get_nb_non_explored(x, y):
total = []
if (y + 1 < height and is_explored(Labyrinth[y + 1][x]) == 0):
total.append("S")
if (x + 1 < lenght and is_explored(Labyrinth[y][x + 1]) == 0):
total.append("E")
if (y - 1 >= 0 and is_explored(Labyrinth[y - 1][x]) == 0):
total.append("N")
if (x - 1 >= 0 and is_explored(Labyrinth[y][x - 1]) == 0):
total.append("O")
return total
def open_all_doors(x, y):
nb = get_nb_non_explored(x, y)
while (len(nb) > 0):
direc = nb[random.randrange(0, len(nb))]
if (direc == 'S'):
Labyrinth[y][x][1] = 1
Labyrinth[y + 1][x][0] = 1
open_all_doors(x, y + 1)
if (direc == 'E'):
Labyrinth[y][x][2] = 1
Labyrinth[y][x + 1][3] = 1
open_all_doors(x + 1, y)
if (direc == 'N'):
Labyrinth[y][x][0] = 1
Labyrinth[y - 1][x][1] = 1
open_all_doors(x, y - 1)
if (direc == 'O'):
Labyrinth[y][x][3] = 1
Labyrinth[y][x - 1][2] = 1
open_all_doors(x - 1, y)
print(direc)
nb = get_nb_non_explored(x, y)
return 0
def print_labyrinth():
for i in range(height):
for j in range(lenght):
if (Labyrinth[i][j][0] == 1):
print('┌ ', end="┐")
else :
print('┌─', end="┐")
print("")
for j in range(lenght):
if (Labyrinth[i][j][3] == 1):
print(' ', end=" ")
else :
print('│', end=" ")
if (Labyrinth[i][j][2] == 1):
print(' ', end="")
else :
print('│', end="")
print("")
for j in range(lenght):
if (Labyrinth[i][j][1] == 1):
print('└ ', end="┘")
else :
print('└─', end="┘")
print("")
print_labyrinth()
# tests that the get_nb_non_explored fonction work
print(get_nb_non_explored(0,0))
print(get_nb_non_explored(1,0))
print(get_nb_non_explored(1,1))
open_all_doors(0, 0)
print_labyrinth()