-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
executable file
·49 lines (43 loc) · 1.21 KB
/
generator.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
#!/usr/bin/python
import sys
import random
pcsSize = 4
dirTab = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def PrintPcs(pcs):
for line in pcs:
print (''.join(line))
def GenPcs(pcs, x, y):
pcs[y][x] = '#'
i = 1
while (i < pcsSize):
while (1):
d = random.randint(0,pcsSize - 1)
if (((y + dirTab[d][0] >= 0) and (y + dirTab[d][0] < pcsSize))
and ((x + dirTab[d][1] >= 0) and (x + dirTab[d][1] < pcsSize))):
if (pcs[y + dirTab[d][0]][x + dirTab[d][1]] == '#'):
i -= 1;
i += 1;
pcs[y + dirTab[d][0]][x + dirTab[d][1]] = '#'
y += dirTab[d][0];
x += dirTab[d][1];
break ;
def CreatePcs():
pcs = [['.' for x in range(pcsSize)] for x in range(pcsSize)]
GenPcs(pcs, random.randint(0,pcsSize - 1), random.randint(0,pcsSize - 1))
PrintPcs(pcs)
if __name__ == '__main__':
# If there is only one argument
if (len(sys.argv) == 2):
# Convert string to integer
pcsNbr = int(sys.argv[1])
if (pcsNbr > 0 and pcsNbr <= 26):
# Until there are pieces to be shown
while pcsNbr:
CreatePcs()
pcsNbr -= 1
if (pcsNbr):
print ('')
else:
print ("Piece number can't have to be between 1 and 26")
else:
print ("Usage: python3 generator.py [Piece number]")