-
Notifications
You must be signed in to change notification settings - Fork 0
/
tictactoe.py
119 lines (108 loc) · 3.3 KB
/
tictactoe.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
b ={
'a1':' ','a2':' ','a3':' ',
'a4':' ','a5':' ','a6':' ',
'a7':' ','a8':' ','a9':' ',
}
player = 1
total_moves = 0
end_check = 0
def check():
# for player one
# for horizontal
if b['a1'] == 'x'and b['a2']=='x'and b['a3']=='x':
print('player 1 won')
return 1
if b['a4'] == 'x'and b['a5']=='x'and b['a6']=='x':
print('player 1 won')
return 1
if b['a7'] == 'x'and b['a8']=='x'and b['a9']=='x':
print('player 1 won')
return 1
# for vertical
if b['a1'] == 'x'and b['a3']=='x'and b['a7']=='x':
print('player 1 won')
return 1
if b['a2'] == 'x'and b['a5']=='x'and b['a8']=='x':
print('player 1 won')
return 1
if b['a3'] == 'x'and b['a6']=='x'and b['a9']=='x':
print('player 1 won')
return 1
# for diagnal
if b['a1'] == 'x'and b['a5']=='x'and b['a9']=='x':
print('player 1 won')
return 1
if b['a3'] == 'x'and b['a5']=='x'and b['a7']=='x':
print('player 1 won')
return 1
# for player 2
if b['a1'] == 'o'and b['a2']=='o'and b['a3']=='o':
print('player 2 won')
return 1
if b['a4'] == 'o'and b['a5']=='o'and b['a6']=='o':
print('player 2 won')
return 1
if b['a7'] == 'o'and b['a8']=='o'and b['a9']=='o':
print('player 2 won')
return 1
# for vertical
if b['a1'] == 'o'and b['a3']=='o'and b['a7']=='o':
print('player 2 won')
return 1
if b['a2'] == 'o'and b['a5']=='o'and b['a8']=='o':
print('player 2 won')
return 1
if b['a3'] == 'o'and b['a6']=='o'and b['a9']=='o':
print('player 2 won')
return 1
# for diagnal
if b['a1'] == 'o'and b['a5']=='o'and b['a9']=='o':
print('player 2 won')
return 1
if b['a3'] == 'o'and b['a5']=='o'and b['a7']=='o':
print('player 2 won')
return 1
return 0
print('00000000000000000000000000000000000000000000000000')
print('''
player one and two can input "x" and "o" by there position in this manner
''')
print('''
a1 | a2 | a3
+ +
a4 | a5 | a6
+ +
a7 | a8 | a9
''')
print("0000000000000000000000000000000000000000000000000000")
input('press enter to play best of luck')
while True:
print(b['a1']+'|'+b['a2']+'|'+b['a3'])
print('-+-+-')
print(b['a4'] + '|' + b['a5'] + '|' + b['a6'])
print('-+-+-')
print(b['a7'] + '|' + b['a8'] + '|' + b['a9'])
end_check = check()
if total_moves == 9 or end_check == 1:
break
while True:
if player == 1:
p1 = input('player no.1 chance : ')
if p1 in b and b[p1]==' ':
b[p1]='x'
player = 2
break
else:
print('chutiya hai kya ! vaapis input kar !')
continue
else:
p2 = input('player no.2 chance : ')
if p2 in b and b[p2]==' ':
b[p2]='o'
player = 1
break
else:
print('chutiya hai kya ! vaapis input kar !')
continue
total_moves+=1
print('00000000000000000000000000000000000')