-
Notifications
You must be signed in to change notification settings - Fork 0
/
fproj.py
145 lines (128 loc) · 3.63 KB
/
fproj.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sys
import random
# generate random array of arrays
def randox():
x = []
for i in range(0,8):
while True:
c = random.randint(1,8)
#check for duplication
dupl = False
for d in x:
if d == c:
dupl = True
break
#endfor
if not dupl:
break
#endwhile
x.append(c)
#endfor
return x
#end randox
def add2line(line,size,level):
if level == 1:
if size == 8:
line = line+"..+------+"
elif size == 7:
line = line+"..+-----+."
elif size == 6:
line = line+"...+----+."
elif size == 5:
line = line+"...+---+.."
elif size == 4:
line = line+"....+--+.."
elif size == 3:
line = line+"....+-+..."
elif size == 2:
line = line+".....++..."
else:
line = line+".....+...."
elif level > 1:
if size < level:
line = line+" "
elif size == level:
if size == 8:
line = line+" +------+"
elif size == 7:
line = line+" +-----+ "
elif size == 6:
line = line+" +----+ "
elif size == 5:
line = line+" +---+ "
elif size == 4:
line = line+" +--+ "
elif size == 3:
line = line+" +-+ "
elif size == 2:
line = line+" ++ "
else:
line = line+" + "
else:
if size == 8:
line = line+" + +"
elif size == 7:
line = line+" + + "
elif size == 6:
line = line+" + + "
elif size == 5:
line = line+" + + "
elif size == 4:
line = line+" + + "
elif size == 3:
line = line+" + + "
elif size == 2:
line = line+" ++ "
else:
line = line+" + "
else:
# so level == 0
line = line+" "+str(size)+" "
return line
#end add2line
def create_line(x,level):
line=""
for i in range(0,8):
line = add2line(line,x[i],level)
#endfor
return line
#end create_line
def display(x):
for i in range(9,0,-1):
line = create_line(x,i-1)
print(line)
#endfor
#end display
def main():
x = randox()
while True:
display(x)
print("if you want to swap, enter a,b")
res=input("if you want to end, enter 0: ")
if res[0] == '0':
print("program done")
break
if res[0] < '1' or res[0] > '8':
print("incorrect input, redo")
continue
if res[1] != ',':
print("incorrect input, redo")
continue
if res[2] < '1' or res[2] > '8':
print("incorrect input, redo")
continue
if res[1] == res[2]:
print("incorrect input, redo")
continue
a = ord(res[0])-ord('0')
b = ord(res[2])-ord('0')
print("swappin box ",a," with a box ",b)
for i in range(0,8):
if x[i] == a:
a1 = i
elif x[i] == b:
b1 = i
x[a1],x[b1] = x[b1],x[a1]
#endwhile
#end main
main()