-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneweval_mod.py
More file actions
89 lines (80 loc) · 1.98 KB
/
neweval_mod.py
File metadata and controls
89 lines (80 loc) · 1.98 KB
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
m = {}
class temp():
def __init__(self,s,c):
self.string = s
self.chance = c
def temp(s,c):
return s+c
def check(s,a):
if isinstance(s,type("")):
s = list(s)
h = 0
for i in range(9):
if s[i] == a:
h += (1<<i)
if (h&7) == 7:
return 1
if (h&56) == 56:
return 1
if (h&448) == 448:
return 1
if (h&292) == 292:
return 1
if (h&146) == 146:
return 1
if (h&73) == 73:
return 1
if (h&273) == 273:
return 1
if (h&84) == 84:
return 1
return 0
def dfs(s,c):
global m
if check(s,'x')==1:
m[temp(s,c)] = 1.0
return 1.0
elif check(s,'o')==1:
m[temp(s,c)]= -1.0
return -1.0
if temp(s,c) in m.keys():
return m[temp(s,c)]
if isinstance(s,type("")):
s = list(s)
x = -2.0
y = 2.0
fl = 0
for i in range(9):
if s[i] == '-':
s[i] = c;
r = ''.join(s)
if c == 'x':
x =max(dfs(r,'o'),x)
else:
y = min(dfs(r,'x'),y)
s[i]='-'
fl += 1
if(fl==0):
fl=1
r = ''.join(s)
if c == 'x':
m[temp(r,c)] = x/fl
return x/fl
else:
m[temp(r,c)] = y/fl
return y/fl
def start():
global m
s = "---------"
m = {}
dfs(s,'x')
i = 0;
print check("x-o-ooxxx",'x')
print m["x-o-oox-xx"]
i=0
rrr = m.keys()
rrr.sort()
for k in rrr:
i += 1
print k,":",m[k]
print i