forked from sanezek/pentago
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpentagogame.py
More file actions
249 lines (220 loc) · 6.93 KB
/
pentagogame.py
File metadata and controls
249 lines (220 loc) · 6.93 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#pentago
pole=[ # kw=1 kw=2
[0,0,0,0,0,0], # 0 0 0| 0 0 0
[0,0,0,0,0,0], # 0 0 0| 0 0 0
[0,0,0,0,0,0], # 0 0 0| 0 0 0
[0,0,0,0,0,0], #_____________
[0,0,0,0,0,0], # kw=3 kw=4
[0,0,0,0,0,0] # 0 0 0| 0 0 0
] # 0 0 0| 0 0 0
# 0 0 0| 0 0 0
pole2=[]
player=1
def format2():
global pole
pole=[]
for i in range(3):
pole.append(pole2[0][i]+pole2[1][i])
for i in range(3):
pole.append(pole2[2][i]+pole2[3][i])
def format3():
global pole2
pole2=[]
pole2.append([pole[0][0:3],pole[1][0:3],pole[2][0:3]])
pole2.append([pole[0][3:],pole[1][3:],pole[2][3:]])
pole2.append([pole[3][0:3],pole[4][0:3],pole[5][0:3]])
pole2.append([pole[3][3:],pole[4][3:],pole[5][3:]])
def set_cvet(cor,cv): #cordins=[x,y];cv= (1 or 2)
global pole
y=cor[1]
x=cor[0]
pole[x][y]=cv
format3()
def povp(kw):
n=[]
kw-=1
f=pole2[kw]
for i in range(3):
n.append([f[2][i],f[1][i],f[0][i]])
pole2[kw]=n
format2()
def povl(kw):
povp(kw)
povp(kw)
povp(kw)
def prow():
format2()
w1=0
w2=0
for i in range(6):
if pole[i][0]==0:
continue
elif (pole[i][0]==1 and pole[i][1]==1 and pole[i][2]==1 and pole[i][3]==1 and pole[i][4]==1):
w1=1
elif (pole[i][0]==2 and pole[i][1]==2 and pole[i][2]==2 and pole[i][3]==2 and pole[i][4]==2):
w2=1
for i in range(6):
if pole[0][i]==0:
continue
elif (pole[0][i]==1 and pole[1][i]==1 and pole[2][i]==1 and pole[3][i]==1 and pole[4][i]==1):
w1=1
elif (pole[0][i]==2 and pole[1][i]==2 and pole[2][i]==2 and pole[3][i]==2 and pole[4][i]==2):
w2=1
for i in range(6):
if pole[i][5]==0:
continue
elif (pole[i][5]==1 and pole[i][4]==1 and pole[i][3]==1 and pole[i][2]==1 and pole[i][1]==1):
w1=1
elif (pole[i][5]==2 and pole[i][4]==2 and pole[i][3]==2 and pole[i][2]==2 and pole[i][1]==2):
w2=1
for i in range(6):
if pole[5][i]==0:
continue
elif (pole[5][i]==1 and pole[4][i]==1 and pole[3][i]==1 and pole[2][i]==1 and pole[1][i]==1):
w1=1
elif (pole[5][i]==2 and pole[5][i]==2 and pole[3][i]==2 and pole[2][i]==2 and pole[1][i]==2):
w2=1
if(pole[0][0]==1 and pole[1][1]==1 and pole[2][2]==1 and pole[3][3]==1 and pole[4][4]==1):
w1=1
if(pole[0][0]==2 and pole[1][1]==2 and pole[2][2]==2 and pole[3][3]==2 and pole[4][4]==2):
w2=1
if(pole[0][5]==1 and pole[1][4]==1 and pole[2][3]==1 and pole[3][2]==1 and pole[4][1]==1):
w1=1
if(pole[0][5]==2 and pole[1][4]==2 and pole[2][3]==2 and pole[3][2]==2 and pole[4][1]==2):
w2=1
if(pole[5][5]==1 and pole[4][4]==1 and pole[3][3]==1 and pole[2][2]==1 and pole[1][1]==1):
w1=1
if(pole[5][5]==2 and pole[4][4]==2 and pole[3][3]==2 and pole[2][2]==2 and pole[1][1]==2):
w2=1
if(pole[5][0]==1 and pole[4][1]==1 and pole[3][2]==1 and pole[2][3]==1 and pole[1][4]==1):
w1=1
if(pole[5][0]==2 and pole[4][1]==2 and pole[3][2]==2 and pole[2][3]==2 and pole[1][4]==2):
w2=1
if(pole[1][0]==1 and pole[2][1]==1 and pole[3][2]==1 and pole[4][3]==1 and pole[5][4]==1):
w1=1
if(pole[1][0]==2 and pole[2][1]==2 and pole[3][2]==2 and pole[4][3]==2 and pole[5][4]==2):
w2=1
if(pole[0][1]==1 and pole[1][2]==1 and pole[2][3]==1 and pole[3][4]==1 and pole[4][5]==1):
w1=1
if(pole[0][1]==2 and pole[1][2]==2 and pole[2][3]==2 and pole[3][4]==2 and pole[4][5]==2):
w2=1
if(pole[0][4]==1 and pole[1][3]==1 and pole[2][2]==1 and pole[3][1]==1 and pole[4][0]==1):
w1=1
if(pole[0][4]==2 and pole[1][3]==2 and pole[2][2]==2 and pole[3][1]==2 and pole[4][0]==2):
w2=1
if(pole[1][5]==1 and pole[2][4]==1 and pole[3][3]==1 and pole[4][2]==1 and pole[5][1]==1):
w1=1
if(pole[1][5]==2 and pole[2][4]==2 and pole[3][3]==2 and pole[4][2]==2 and pole[1][5]==2):
w2=1
if w1==1 and w2==1:
return(3)
elif w1==0 and w2==0 :
return(0)
elif w1==1:
return(1)
elif w2==1:
return(2)
def printpole():
print()
for i in range(3):
a=str(pole2[0][i][0])+' '+str(pole2[0][i][1])+' '+str(pole2[0][i][2])+' '+str(pole2[1][i][0])+' '+str(pole2[1][i][1])+' '+str(pole2[1][i][2])
print(a)
print()
for i in range(3):
a=str(pole2[2][i][0])+' '+str(pole2[2][i][1])+' '+str(pole2[2][i][2])+' '+str(pole2[3][i][0])+' '+str(pole2[3][i][1])+' '+str(pole2[3][i][2])
print(a)
print()
def game():
printpole()
print('ход {} игрока'.format(player))
if coms['hod'][1]==1:
print('поставьте фишку')
if coms['hod'][1]==0:
print('поверние любое из полей')
inp=input('>').split()
if len(inp)!=0:
com=inp[0]
if (com in coms) :
if coms[com][1]==1:
comm=coms[com][0]
if len(inp)==2:
try:
comm(inp[1])
except TypeError:
print("недостаточно данных, попробуйте снова")
elif len(inp)==3:
comm(inp[1],inp[2])
elif len(inp)==1:
try:
comm()
except TypeError:
print("недостаточно данных, попробуйте снова")
else:
print('\nUnknown command\n'+help2())
d=prow()
if d==1:
print('Первый игрок победил, поздравляю')
exit()
elif d==2:
print('Второй игрок победил, поздравляю')
exit()
elif d==3:
print('Поздравляю победила дружба, но КАК ВЫ ЭТО СДЕЕЛАЛИ???')
exit()
else:
print(help())
def hod(x,y):
try:
x=int(x)-1
y=int(y)-1
if pole[y][x]==0:
set_cvet([y,x],player)
coms['hod'][1]=0
coms['povp'][1]=1
coms['povl'][1]=1
else:
print('Пожалуйста,поместите фишку в свободную ячейку')
except ValueError:
print('Данные не в нужном формате, попробуйте снова')
def help2():
return'Вот список доступных команд:\nhelp - помощь\nhod x y - ход игрока у которго право хода по координатам x y \npovp kw - поворот вправо квадрато под номер kw\npovд kw - поворот влево квадрато под номер kw\nexit - выход'
def help():
print('Вот список доступных команд:\nhelp - помощь\nhod x y - ход игрока у которго право хода по координатам x y \npovp kw - поворот вправо квадрато под номер kw\npovд kw - поворот влево квадрато под номер kw\nexit - выход')
def povl2(kw):
try:
kw=int(kw)
povl(kw)
global player
if player==1:
player=2
else:
player=1
coms['hod'][1]=1
coms['povp'][1]=0
coms['povl'][1]=0
except ValueError:
print('Данные не в нужном формате, попробуйте снова')
def povp2(kw):
try:
global player
kw=int(kw)
povp(kw)
if player==1:
player=2
else:
player=1
coms['hod'][1]=1
coms['povp'][1]=0
coms['povl'][1]=0
except ValueError:
print('Данные не в нужном формате, попробуйте снова')
coms={
'help':[help,1], #haha
'hod':[hod,1],
'povl':[povl2,0],
'povp':[povp2,0],
'exit':[exit,1]
}
format3()
while 1:
game()