-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.py
123 lines (102 loc) · 4.78 KB
/
evaluate.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
from boardstate import *
WHITE_6PATTERNS = [['empty', 'white', 'white', 'white', 'white','empty'],
['empty', 'white', 'white', 'white', 'empty','empty'],
['empty', 'empty', 'white', 'white', 'white','empty'],
['empty', 'white', 'white', 'empty', 'white','empty'],
['empty', 'white', 'empty', 'white', 'white','empty'],
['empty', 'empty', 'white', 'white', 'empty','empty'],
['empty', 'empty', 'white', 'empty', 'white','empty'],
['empty', 'white', 'empty', 'white', 'empty','empty'],
['empty', 'empty', 'white', 'empty', 'empty','empty'],
['empty', 'empty', 'empty', 'white', 'empty','empty']]
WHITE_6SCORES = [50000,5000,5000,500,500,100,100,100,10,10]
# WHITE_6SCORES = [8640,720,720,720,720,120,120,120,20,20] #based on Dong (2015)
WHITE_5PATTERNS = [['white', 'white', 'white', 'white', 'white'],
['white', 'white', 'white', 'white', 'empty'],
['empty', 'white', 'white', 'white', 'white'],
['white', 'white', 'empty', 'white', 'white'],
['white', 'empty', 'white', 'white', 'white'],
['white', 'white', 'white', 'empty', 'white']]
WHITE_5SCORES = [1000000,5000,5000,5000,5000,5000]
# WHITE_5SCORES = [50000,720,720,720,720,720] #based on Dong (2015)
BLACK_6PATTERNS = [['empty', 'black', 'black', 'black', 'black','empty'],
['empty', 'black', 'black', 'black', 'empty','empty'],
['empty', 'empty', 'black', 'black', 'black','empty'],
['empty', 'black', 'black', 'empty', 'black','empty'],
['empty', 'black', 'empty', 'black', 'black','empty'],
['empty', 'empty', 'black', 'black', 'empty','empty'],
['empty', 'empty', 'black', 'empty', 'black','empty'],
['empty', 'black', 'empty', 'black', 'empty','empty'],
['empty', 'empty', 'black', 'empty', 'empty','empty'],
['empty', 'empty', 'empty', 'black', 'empty','empty']]
BLACK_6SCORES = [50000,5000,5000,500,500,100,100,100,10,10]
# BLACK_6SCORES = [8640,720,720,720,720,120,120,120,20,20] #based on Dong (2015)
BLACK_5PATTERNS = [['black', 'black', 'black', 'black', 'black'],
['black', 'black', 'black', 'black', 'empty'],
['empty', 'black', 'black', 'black', 'black'],
['black', 'black', 'empty', 'black', 'black'],
['black', 'empty', 'black', 'black', 'black'],
['black', 'black', 'black', 'empty', 'black']]
BLACK_5SCORES = [1000000,5000,5000,5000,5000,5000]
# BLACK_5SCORES = [50000,720,720,720,720,720] #based on Dong (2015)
def sublist(small, big):
'''
Return True if small is a sublist of big.
'''
for i in range(len(big)-len(small)+1):
for j in range(len(small)):
if big[i+j] != small[j]:
break
else:
return True
return False
def enum_to_string(vector):
'''
Change BoardState.WHITE to 'white'.
'''
string_list = []
for item in vector:
if item == BoardState.BLACK:
string_list.append('black')
elif item == BoardState.WHITE:
string_list.append('white')
else:
string_list.append('empty')
return string_list
def evaluate_vector(vector):
'''
Return the score for a vector (line or column or diagonal)
'''
string_list = enum_to_string(vector)
score = {'white': 0, 'black': 0}
length = len(string_list)
if length == 5:
for i in range(len(WHITE_5PATTERNS)):
if WHITE_5PATTERNS[i] == string_list:
score['white'] += WHITE_5SCORES[i]
if BLACK_5PATTERNS[i] == string_list:
score['black'] += BLACK_5SCORES[i]
return score
for i in range(length - 5):
temp = [string_list[i], string_list[i + 1], string_list[i + 2],
string_list[i + 3], string_list[i + 4]]
for i in range(len(WHITE_5PATTERNS)):
if WHITE_5PATTERNS[i] == temp:
score['white'] += WHITE_5SCORES[i]
if BLACK_5PATTERNS[i] == temp:
score['black'] += BLACK_5SCORES[i]
for i in range(length - 6):
temp = [
string_list[i],
string_list[i + 1],
string_list[i + 2],
string_list[i + 3],
string_list[i + 4],
string_list[i + 5],
]
for i in range(len(WHITE_6PATTERNS)):
if WHITE_6PATTERNS[i] == temp:
score['white'] += WHITE_6SCORES[i]
if BLACK_6PATTERNS[i] == temp:
score['black'] += BLACK_6SCORES[i]
return score