-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtic.py
177 lines (154 loc) · 4.57 KB
/
tic.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
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
import os,sys,random,time
drawn=0
series=0
board=[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
win=1
draw=-1
running=0
game=running
person=random.randint(1,2)
stop=1
mark='x'
score1=0
score2=0
total_series=series
def again():
global board
board=[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
global win
win=1
global draw
draw=-1
global running
running=0
global game
game=running
global person
person=random.randint(1,2)
global stop
stop=1
global mark
mark='x'
global series
series=series-1
return series
def drawboard():
print(" %c | %c | %c "%(board[1],board[2],board[3]))
print("___|___|___")
print(" %c | %c | %c "%(board[4],board[5],board[6]))
print("___|___|___")
print(" %c | %c | %c "%(board[7],board[8],board[9]))
print(" | | ")
def checkposition(x):
if (board[x]==' '):
return True
else:
return False
def scoreboard():
print(" SCORE BOARD ")
print(" OUT OF %d MATCHES"%total_series)
print("_________________________________ ")
print(" AARUSH | ABHISHEK | draw ")
print(" | |")
print(" %d | %d | %d "%(score1,score2,drawn))
print("__________________________________")
print("\n")
def checkforwin():
global game
if((board[1]==board[2]==board[3]) and (board[1]!=' ')):
game=win
elif((board[4]==board[5]==board[6]) and (board[4]!=' ')):
game=win
elif((board[7]==board[8]==board[9]) and (board[7]!=' ')):
game=win
elif((board[1]==board[4]==board[7]) and (board[1]!=' ')):
game=win
elif((board[2]==board[5]==board[8]) and (board[2]!=' ')):
game=win
elif((board[3]==board[6]==board[9]) and (board[3]!=' ')):
game=win
elif((board[1]==board[5]==board[9]) and (board[1]!=' ')):
game=win
elif((board[3]==board[5]==board[7]) and (board[3]!=' ')):
game=win
elif((board[1]!=' ') and (board[2]!=' ') and (board[3]!=' ') and (board[4]!=' ') and (board[5]!=' ') and (board[6]!=' ') and (board[7]!=' ') and (board[8]!=' ') and (board[9]!=' ')):
game=draw
else:
game=running
print("tic",end="")
time.sleep(2)
print(" tac",end="")
time.sleep(2)
print(" toe",end="")
print("\nbe ready folks")
series=int(input("enter the series \n>>>"))
total_series=series
while(series>0):
while(game==running):
drawboard()
if(person%2!=0):
print("AARUSH its your turn : ")
mark='x'
elif(person%2==0):
print("ABHISHEK its your turn : ")
mark='o'
choice=int(input("enter the value from 1 to 9 to put the value"))
if(checkposition(choice)==True and (0<choice<10)):
board[choice]=mark;
person+=1
checkforwin()
else:
print(" ERROR \n")
print("\n")
print("please enter at the vacant place")
choice=int(input("enter the value from 1 to 9 to put the value"))
if(checkposition(choice)==True and (0<choice<10)):
board[choice]=mark;
person+=1
checkforwin()
checkforwin()
drawboard()
if(game==draw):
print("game draw")
drawn+=1
elif(game==win):
person-=1
if(person%2!=0):
print("AARUSH YOU won")
print("\n")
score1+=1
else:
print("ABHISHEK YOU won")
print("\n")
score2+=1
scoreboard()
again()
if score1>score2:
print("*************************************************")
print("\n")
print(" AARUSH HAS WON THE SERIES KUDOS ")
print("\n")
print("*************************************************")
elif score1==score2:
print("*************************************************")
print("\n")
print(" DRAW MATCH ")
print("\n")
print("*************************************************")
else:
print("*************************************************")
print("\n")
print(" ABHISHEK HAS WON THE SERIES KUDOS ")
print("\n")
print("*************************************************")
'''
os.system('python tic.py')
'''
'''
a=input("would you like to continue")
if (a=='y' or a=='Y'):
os.execv(sys.executable,['python']+sys.argv)
os.execv(__file__,sys.argv)
else:
exit(0)
'''