forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtik_tak.py
111 lines (90 loc) · 2.99 KB
/
tik_tak.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
#Tik-tak game
board=["anything",1,2,3,4,5,6,7,8,9]
switch="p1"
j=9
print("\n\t\t\tTIK-TAC-TOE")
def print_board():
#import os
#os.system('cls')
print("\n\n")
print(" | |" )
print("",board[1]," | ",board[2]," | ",board[3] )
print("____|_____|____")
print(" | |" )
print("",board[4]," | ",board[5]," | ",board[6] )
print("____|_____|____")
print(" | |" )
print("",board[7]," | ",board[8]," | ",board[9] )
print(" | |" )
def enter_number(p1_sign,p2_sign):
global switch
global j
k=9
while(j):
if k==0:
break
if switch=="p1":
p1_input=int(input("\nplayer 1 :- "))
if p1_input<=0:
print("chose number from given board")
else:
for e in range(1,10):
if board[e]==p1_input:
board[e]=p1_sign
print_board()
c=checkwin()
if c==1:
print("\n\n Congratulation ! player 1 win ")
return
switch="p2"
j-=1
k-=1
if k==0:
print("\n\nGame is over")
break
if k==0:
break
if switch=="p2":
p2_input=int(input("\nplayer 2 :- "))
if p2_input<=0:
print("chose number from given board")
#return
else:
for e in range(1,10):
if board[e]==p2_input:
board[e]=p2_sign
print_board()
w=checkwin()
if w==1:
print("\n\n Congratulation ! player 2 win")
return
switch="p1"
j-=1
k-=1
def checkwin():
if board[1]==board[2]==board[3]:
return 1
elif board[4]==board[5]==board[6]:
return 1
elif board[7]==board[8]==board[9]:
return 1
elif board[1]==board[4]==board[7]:
return 1
elif board[2]==board[5]==board[8]:
return 1
elif board[3]==board[6]==board[9]:
return 1
elif board[1]==board[5]==board[9]:
return 1
elif board[3]==board[5]==board[7]:
return 1
else:
print("\n\nGame continue")
def play():
print_board()
p1_sign=input("\n\nplayer 1 chose your sign [0/x] = ")
p2_sign=input("player 2 chose your sign [0/x] = ")
enter_number(p1_sign,p2_sign)
print("\n\n\t\t\tDeveloped By :- UTKARSH MATHUR")
if __name__=="__main__":
play()