-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPR17_TicTacToe.py
More file actions
69 lines (54 loc) · 1.5 KB
/
Copy pathPR17_TicTacToe.py
File metadata and controls
69 lines (54 loc) · 1.5 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
# -*- coding: utf-8 -*-
tahta = [["___", "___", "___"],
["___", "___", "___"],
["___", "___", "___"]]
print("\n"*15)
for i in tahta:
print("\t".expandtabs(30), *i, end="\n"*2)
kazanma_ölçütleri = [[[0, 0], [1, 0], [2, 0]],
[[0, 1], [1, 1], [2, 1]],
[[0, 2], [1, 2], [2, 2]],
[[0, 0], [0, 1], [0, 2]],
[[1, 0], [1, 1], [1, 2]],
[[2, 0], [2, 1], [2, 2]],
[[0, 0], [1, 1], [2, 2]],
[[0, 2], [1, 1], [2, 0]]]
x_durumu = []
o_durumu = []
sıra = 1
while True:
if sıra % 2 == 0:
işaret = "X".center(3)
else:
işaret = "O".center(3)
print()
print("İŞARET: {}\n".format(işaret))
x = input("yukarıdan aşağıya [1, 2, 3]: ".ljust(30))
if x == "q":
break
y = input("soldan sağa [1, 2, 3]: ".ljust(30))
if y == "q":
break
x = int(x)-1
y = int(y)-1
print("\n"*15)
if tahta[x][y] == "___":
tahta[x][y] = işaret
if işaret == "X".center(3):
x_durumu += [[x, y]]
elif işaret == "O".center(3):
o_durumu += [[x, y]]
sıra += 1
else:
print("\nORASI DOLU! TEKRAR DENEYİN\n")
for i in tahta:
print("\t".expandtabs(30), *i, end="\n"*2)
for i in kazanma_ölçütleri:
o = [z for z in i if z in o_durumu]
x = [z for z in i if z in x_durumu]
if len(o) == len(i):
print("O KAZANDI!")
quit()
if len(x) == len(i):
print("X KAZANDI!")
quit()