-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathooxx.py
109 lines (107 loc) · 4.33 KB
/
ooxx.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
def ai(wt1):
import random
a = random.randint(1, 10)
if a <= 7:
if wt1[0] == 'O' and wt1[1] == 'O' and wt1[2] != 'X' and wt1[2] != 'O':
wt1[2] = 'X'
elif wt1[0] == 'O' and wt1[2] == 'O' and wt1[1] != 'X' and wt1[1] != 'O':
wt1[1] = 'X'
elif wt1[1] == 'O' and wt1[2] == 'O' and wt1[0] != 'X' and wt1[0] != 'O':
wt1[0] = 'X'
elif wt1[3] == 'O' and wt1[4] == 'O' and wt1[5] != 'X' and wt1[5] != 'O':
wt1[5] = 'X'
elif wt1[3] == 'O' and wt1[5] == 'O' and wt1[4] != 'X' and wt1[4] != 'O':
wt1[4] = 'X'
elif wt1[4] == 'O' and wt1[5] == 'O' and wt1[3] != 'X' and wt1[3] != 'O':
wt1[3] = 'X'
elif wt1[6] == 'O' and wt1[7] == 'O' and wt1[8] != 'X' and wt1[8] != 'O':
wt1[8] = 'X'
elif wt1[6] == 'O' and wt1[8] == 'O' and wt1[7] != 'X' and wt1[7] != 'O':
wt1[7] = 'X'
elif wt1[7] == 'O' and wt1[8] == 'O' and wt1[6] != 'X' and wt1[6] != 'O':
wt1[6] = 'X'
elif wt1[0] == 'O' and wt1[3] == 'O' and wt1[6] != 'X' and wt1[6] != 'O':
wt1[6] = 'X'
elif wt1[0] == 'O' and wt1[6] == 'O' and wt1[3] != 'X' and wt1[3] != 'O':
wt1[3] = 'X'
elif wt1[6] == 'O' and wt1[3] == 'O' and wt1[0] != 'X' and wt1[0] != 'O':
wt1[0] = 'X'
elif wt1[1] == 'O' and wt1[4] == 'O' and wt1[7] != 'X' and wt1[7] != 'O':
wt1[7] = 'X'
elif wt1[1] == 'O' and wt1[7] == 'O' and wt1[4] != 'X' and wt1[4] != 'O':
wt1[4] = 'X'
elif wt1[4] == 'O' and wt1[7] == 'O' and wt1[1] != 'X' and wt1[1] != 'O':
wt1[1] = 'X'
elif wt1[2] == 'O' and wt1[5] == 'O' and wt1[8] != 'X' and wt1[8] != 'O':
wt1[8] = 'X'
elif wt1[2] == 'O' and wt1[8] == 'O' and wt1[5] != 'X' and wt1[5] != 'O':
wt1[5] = 'X'
elif wt1[5] == 'O' and wt1[8] == 'O' and wt1[2] != 'X' and wt1[2] != 'O':
wt1[2] = 'X'
elif wt1[0] == 'O' and wt1[4] == 'O' and wt1[8] != 'X' and wt1[8] != 'O':
wt1[8] = 'X'
elif wt1[0] == 'O' and wt1[8] == 'O' and wt1[4] != 'X' and wt1[4] != 'O':
wt1[4] = 'X'
elif wt1[4] == 'O' and wt1[8] == 'O' and wt1[0] != 'X' and wt1[0] != 'O':
wt1[0] = 'X'
elif wt1[2] == 'O' and wt1[4] == 'O' and wt1[6] != 'X' and wt1[6] != 'O':
wt1[6] = 'X'
elif wt1[2] == 'O' and wt1[6] == 'O' and wt1[4] != 'X' and wt1[4] != 'O':
wt1[4] = 'X'
elif wt1[4] == 'O' and wt1[6] == 'O' and wt1[2] != 'X' and wt1[2] != 'O':
wt1[2] = 'X'
else:
for i in range(9):
if wt1[i] == None:
wt1[i] = 'X'
break
else:
for i in range(9):
if wt1[i] == None:
wt1[i] = 'X'
break
return wt1
def wl(wt1):
wl = "Tie"
if wt1[0] == 'O' and wt1[1] == 'O' and wt1[2] == 'O':
wl = 'Win'
elif wt1[3] == 'O' and wt1[4] == 'O' and wt1[5] == 'O':
wl = 'Win'
elif wt1[6] == 'O' and wt1[7] == 'O' and wt1[8] == 'O':
wl = 'Win'
elif wt1[0] == 'O' and wt1[3] == 'O' and wt1[6] == 'O':
wl = 'Win'
elif wt1[1] == 'O' and wt1[4] == 'O' and wt1[7] == 'O':
wl = 'Win'
elif wt1[2] == 'O' and wt1[5] == 'O' and wt1[8] == 'O':
wl = 'Win'
elif wt1[0] == 'O' and wt1[4] == 'O' and wt1[8] == 'O':
wl = 'Win'
elif wt1[2] == 'O' and wt1[4] == 'O' and wt1[6] == 'O':
wl = 'Win'
elif wt1[0] == 'X' and wt1[1] == 'X' and wt1[2] == 'X':
wl = 'Lose'
elif wt1[3] == 'X' and wt1[4] == 'X' and wt1[5] == 'X':
wl = 'Lose'
elif wt1[6] == 'X' and wt1[7] == 'X' and wt1[8] == 'X':
wl = 'Lose'
elif wt1[0] == 'X' and wt1[3] == 'X' and wt1[6] == 'X':
wl = 'Lose'
elif wt1[1] == 'X' and wt1[4] == 'X' and wt1[7] == 'X':
wl = 'Lose'
elif wt1[2] == 'X' and wt1[5] == 'X' and wt1[8] == 'X':
wl = 'Lose'
elif wt1[0] == 'X' and wt1[4] == 'X' and wt1[8] == 'X':
wl = 'Lose'
elif wt1[2] == 'X' and wt1[4] == 'X' and wt1[6] == 'X':
wl = 'Lose'
else:
tf = False
for i in wt1:
if i == None:
wl = 'Not yet'
tf = True
break
if tf == False:
wl = "Tie"
return wl