-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy2.py
171 lines (166 loc) · 4.39 KB
/
easy2.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
import random
import time
import sys
import os
def easy():
os.system('cls')
play=['1','2','3','4','5','6','7','8','9']
a=flag=0
pos=[]
print('TIC TAC TOE\nEASY MODE\nGame layout\n')
for i in range(1,6):
for j in range(1,6):
if i%2!=0:
if j%2!=0:
print(play[a],end='')
a+=1
else:
print('|',end='')
else:
if j%2!=0:
print('-',end='')
else:
print('+',end='')
print()
a=0
time.sleep(5)
print()
u=input('Choose x or o: ')
print()
if u=='x':#x chunk
for loop in range(9):
if loop%2==0:
print('Your turn\n')
n=input('Enter position: ')
pos.append(n)
os.system('cls')#'clear'
for k in range(9):
if n==play[k]:
play[k]='x'
for i in range(1,6):
for j in range(1,6):
if i%2!=0:
if j%2!=0:
print(play[a],end='')
a+=1
else:
print('|',end='')
else:
if j%2!=0:
print('-',end='')
else:
print('+',end='')
print()
a=0
time.sleep(2)
os.system('cls')#'clear'
if play[0]==play[1]==play[2]=='x' or play[3]==play[4]==play[5]=='x' or play[6]==play[7]==play[8]=='x' or play[0]==play[3]==play[6]=='x' or play[1]==play[4]==play[7]=='x' or play[2]==play[5]==play[8]=='x' or play[0]==play[4]==play[8]=='x' or play[2]==play[4]==play[6]=='x':
print('\nYAY!\nYOU WON\n')
flag=1
#sys.exit()
return
else:
print('COMPUTER\'S TURN\n')
while True:
n=str(random.randrange(1,9))
if n not in pos:
pos.append(n)
break
else:
continue
for k in range(9):
if n==play[k]:
play[k]='o'
for i in range(1,6):
for j in range(1,6):
if i%2!=0:
if j%2!=0:
print(play[a],end='')
a+=1
else:
print('|',end='')
else:
if j%2!=0:
print('-',end='')
else:
print('+',end='')
print()
a=0
time.sleep(2)
if play[0]==play[1]==play[2]=='o' or play[3]==play[4]==play[5]=='o' or play[6]==play[7]==play[8]=='o' or play[0]==play[3]==play[6]=='o' or play[1]==play[4]==play[7]=='o' or play[2]==play[5]==play[8]=='o' or play[0]==play[4]==play[8]=='o' or play[2]==play[4]==play[6]=='o':
print('\nGAME OVER!\nCOMPUTER WON\n')
flag=1
#sys.exit()
return
print()
if flag==0:
print('\nDRAW / TIE\n')
elif u=='o':#o chunk
for loop in range(9):
if loop%2!=0:
print('Your turn\n')
n=input('Enter position: ')
pos.append(n)
os.system('cls')#'clear'
for k in range(9):
if n==play[k]:
play[k]='x'
for i in range(1,6):
for j in range(1,6):
if i%2!=0:
if j%2!=0:
print(play[a],end='')
a+=1
else:
print('|',end='')
else:
if j%2!=0:
print('-',end='')
else:
print('+',end='')
print()
a=0
time.sleep(2)
os.system('cls')#'clear'
if play[0]==play[1]==play[2]=='x' or play[3]==play[4]==play[5]=='x' or play[6]==play[7]==play[8]=='x' or play[0]==play[3]==play[6]=='x' or play[1]==play[4]==play[7]=='x' or play[2]==play[5]==play[8]=='x' or play[0]==play[4]==play[8]=='x' or play[2]==play[4]==play[6]=='x':
print('\nYAY\nYOU WON!!\n')
flag=1
#sys.exit()
return
else:
print('COMPUTER\'S TURN\n')
while True:
n=str(random.randrange(1,9))
if n not in pos:
pos.append(n)
break
else:
continue
for k in range(9):
if n==play[k]:
play[k]='o'
for i in range(1,6):
for j in range(1,6):
if i%2!=0:
if j%2!=0:
print(play[a],end='')
a+=1
else:
print('|',end='')
else:
if j%2!=0:
print('-',end='')
else:
print('+',end='')
print()
a=0
time.sleep(2)
if play[0]==play[1]==play[2]=='o' or play[3]==play[4]==play[5]=='o' or play[6]==play[7]==play[8]=='o' or play[0]==play[3]==play[6]=='o' or play[1]==play[4]==play[7]=='o' or play[2]==play[5]==play[8]=='o' or play[0]==play[4]==play[8]=='o' or play[2]==play[4]==play[6]=='o':
print('\nGAME OVER!! COMPUTER WON\n')
flag=1
#sys.exit()
return
print()
if flag==0:
print('\nDRAW / TIE\n')
# easy()