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
|
def cutoff(score, cutoff_point=32, cutoff_rate=0.1):
sign = 1 if score > 0 else -1
score = abs(score)
if score > cutoff_point:
score -= cutoff_point
score *= cutoff_rate
score += cutoff_point
return score * sign
def get_opponents(butler, player):
table = butler.table
if player in [table.openE, table.openW]:
return [table.openN, table.openS]
if player in [table.openN, table.openS]:
return [table.openE, table.openW]
if player in [table.closeE, table.closeW]:
return [table.closeN, table.closeS]
if player in [table.closeN, table.closeS]:
return [table.closeE, table.closeW]
def get_room(butler, player):
table = butler.table
if player in [table.openE, table.openW, table.openN, table.openS]:
return 'open'
if player in [table.closeE, table.closeW, table.closeN, table.closeS]:
return 'closed'
def get_line(butler, player):
table = butler.table
room = get_room(butler, player).upper()
direction = 'NS' if player in [
table.openN, table.openS, table.closeN, table.closeS
] else 'EW'
return '%s_%s' % (room, direction)
def normalize(butler, opp_factor=0.5):
if butler.board_count == 0:
return 0.0
return (
butler.cut_score / butler.board_count +
butler.opp_score * opp_factor
) * butler.board_count
|