-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
109 lines (94 loc) · 2.88 KB
/
main.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
lis = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
def line():
print(" | |")
def inline(lis, ind):
print(" {} | {} | {}".format(lis[ind], lis[ind + 1], lis[ind + 2]))
def stline():
print("---------------")
def printmat():
for i in range(0, 9, 3):
line()
inline(lis, i)
if i != 6:
stline()
printmat()
def check():
for inwhi in range(0, 9, 3):
if (lis[inwhi] == lis[inwhi + 1]) and (lis[inwhi + 2] == lis[inwhi + 1]):
if lis[inwhi] == a:
print("PLAYER 1 WINS")
return 1
else:
print("PLAYER 2 WINS")
return 1
for inwhi in range(0, 3):
if (lis[inwhi] == lis[inwhi + 3]) and (lis[inwhi + 3] == lis[inwhi + 6]):
if lis[inwhi] == a:
print("PLAYER 1 WINS")
return 1
else:
print("PLAYER 2 WINS")
return 1
if (lis[0] == lis[4]) and (lis[4] == lis[8]):
if lis[0] == a:
print("PLAYER 1 WINS")
return 1
else:
print("PLAYER 2 WINS")
return 1
if (lis[2] == lis[4]) and (lis[4] == lis[6]):
if lis[2] == a:
print("PLAYER 1 WON")
return 1
else:
print("PLAYER 2 WON")
return 1
return 0
a = input("Player 1 choose your mark 'X' or '0' : ")
b = None
if a == 'X':
b = '0'
else:
b = 'X'
print("Mark for Player1 is {}".format(a))
print("Mark for Player2 is {}".format(b))
print("Rules : First Player1 will choose a number which will be replaced ")
print("by his/her mark then Player2 will choose a number which will be ")
print("replaced by his/her mark and it'll continue subsequently in the later stage of the game")
whi = 0
while whi < 9:
if whi % 2 == 0:
pos = int(input("Player1 choose your position (1-9) : ")) - 1
if pos<0:
print("Enter between 1-9.")
whi -= 1
elif pos>=9:
print("Enter between 1-9.")
whi -= 1
else:
if (lis[pos]) == b:
print("Enter positions that are not used")
whi -= 1
else:
lis[pos] = a
else:
pos = int(input("Player2 choose your position (1-9) : ")) - 1
if pos < 0:
print("Enter between 1-9.")
whi -= 1
elif pos >= 9:
print("Enter between 1-9.")
whi -= 1
else:
if (lis[pos]) == a:
print("Enter positions that are not used")
whi -= 1
else:
lis[pos] = b
printmat()
check1 = check()
if check1 == 1:
break
whi += 1
if check1 == 0 and whi == 9:
print("No one wins")