-
Notifications
You must be signed in to change notification settings - Fork 0
/
pos_cache.py
56 lines (43 loc) · 1.54 KB
/
pos_cache.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
import copy
class PositionCache:
def __init__(self, key, score, move, depth, exact):
self.key = key
self.score = score
self.move = move
self.depth = depth
self.exact = exact
def __str__(self):
return "%s %s %s %s %s" % (self.key, self.score, self.move, self.depth, self.exact)
def __cmp__(self, other):
return cmp((self.exact, self.depth), (other.exact, other.depth))
LOWERBOUND = "lowerbound"
UPPERBOUND = "upperbound"
EXACTSCORE = "exactscore"
class AlphaBetaPositionCache:
def __init__(self, key, score, move, depth, alpha, beta, shadow):
self.key = key
self.score = score
self.move = move
self.depth = depth
self.alpha = alpha
self.beta = beta
if score >= beta:
self.flag = LOWERBOUND
elif score <= alpha:
self.flag = UPPERBOUND
else:
self.flag = EXACTSCORE
self.shadow = copy.copy(shadow)
def __str__(self):
return "%s %s %s %s %s %s %s" % (self.key, self.score, self.move, self.depth, self.alpha, self.beta, self.flag)
#def __cmp__(self, other):
# return cmp((self.exact, self.depth), (other.exact, other.depth))
class LambdaPositionCache:
def __init__(self, key, score, move, shadow, n):
self.key = key
self.score = score
self.move = move
self.shadow = copy.copy(shadow)
self.n = n
def __str__(self):
return "%s %s %s %s" % (self.key, self.score, self.move, self.n)