@@ -41,7 +41,7 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
41
41
42
42
tiles_we_can_discard = [x for x in discard_options if x .danger .get_max_danger () <= x .danger .danger_border ]
43
43
if not tiles_we_can_discard :
44
- return self ._chose_first_option_or_safe_tiles ([], discard_options )
44
+ return self ._chose_first_option_or_safe_tiles ([], discard_options , for_open_hand )
45
45
46
46
# our strategy can affect discard options
47
47
if self .ai .current_strategy :
@@ -52,7 +52,7 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
52
52
had_to_be_discarded_tiles = [x for x in tiles_we_can_discard if x .had_to_be_discarded ]
53
53
if had_to_be_discarded_tiles :
54
54
tiles_we_can_discard = sorted (had_to_be_discarded_tiles , key = lambda x : (x .shanten , - x .ukeire , x .valuation ))
55
- return self ._chose_first_option_or_safe_tiles (tiles_we_can_discard , discard_options )
55
+ return self ._chose_first_option_or_safe_tiles (tiles_we_can_discard , discard_options , for_open_hand )
56
56
57
57
# remove needed tiles from discard options
58
58
tiles_we_can_discard = [x for x in tiles_we_can_discard if not x .had_to_be_saved ]
@@ -101,7 +101,7 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
101
101
min_dora = min ([x .count_of_dora for x in possible_options ])
102
102
min_dora_list = [x for x in possible_options if x .count_of_dora == min_dora ]
103
103
return self ._chose_first_option_or_safe_tiles (
104
- sorted (min_dora_list , key = lambda x : - getattr (x , ukeire_field )), discard_options
104
+ sorted (min_dora_list , key = lambda x : - getattr (x , ukeire_field )), discard_options , for_open_hand
105
105
)
106
106
107
107
# only one option - so we choose it
@@ -113,6 +113,7 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
113
113
return self ._chose_first_option_or_safe_tiles (
114
114
sorted (tiles_without_dora , key = lambda x : (- x .second_level_cost , - x .ukeire_second , x .valuation )),
115
115
discard_options ,
116
+ for_open_hand ,
116
117
)
117
118
118
119
if first_option .shanten == 2 or first_option .shanten == 3 :
@@ -139,13 +140,13 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
139
140
if isolated_tiles :
140
141
# let's sort tiles by value and let's choose less valuable tile to discard
141
142
return self ._chose_first_option_or_safe_tiles (
142
- sorted (isolated_tiles , key = lambda x : x .valuation ), discard_options
143
+ sorted (isolated_tiles , key = lambda x : x .valuation ), discard_options , for_open_hand
143
144
)
144
145
145
146
# there are no isolated tiles or we don't care about them
146
147
# let's discard tile with greater ukeire/ukeire2
147
148
filtered_options = sorted (filtered_options , key = lambda x : - getattr (x , ukeire_field ))
148
- first_option = self ._chose_first_option_or_safe_tiles (filtered_options , discard_options )
149
+ first_option = self ._chose_first_option_or_safe_tiles (filtered_options , discard_options , for_open_hand )
149
150
150
151
other_tiles_with_same_ukeire = [
151
152
x for x in filtered_options if getattr (x , ukeire_field ) == getattr (first_option , ukeire_field )
@@ -155,7 +156,7 @@ def choose_tile_to_discard(self, tiles, closed_hand, melds, for_open_hand=False)
155
156
# or in tempai we can have several tiles with same ukeire
156
157
if other_tiles_with_same_ukeire :
157
158
return self ._chose_first_option_or_safe_tiles (
158
- sorted (other_tiles_with_same_ukeire , key = lambda x : x .valuation ), discard_options
159
+ sorted (other_tiles_with_same_ukeire , key = lambda x : x .valuation ), discard_options , for_open_hand
159
160
)
160
161
161
162
# we have only one candidate to discard with greater ukeire
@@ -397,9 +398,15 @@ def calculate_second_level_ukeire(self, discard_option, tiles, melds):
397
398
# restore original state of player hand
398
399
self .player .tiles = player_tiles_original
399
400
400
- def _chose_first_option_or_safe_tiles (self , chosen_candidates , all_discard_options ):
401
+ def _chose_first_option_or_safe_tiles (self , chosen_candidates , all_discard_options , for_open_hand ):
402
+ # it looks like everything is fine
401
403
if len (chosen_candidates ):
402
404
return chosen_candidates [0 ]
405
+ # we don't want to open hand in that case
406
+ elif for_open_hand :
407
+ return None
408
+
409
+ # we can't discard effective tile from the hand, let's fold
403
410
DecisionsLogger .debug (log .DISCARD_SAFE_TILE , "There are only dangerous tiles. Discard safest tile." )
404
411
return sorted (all_discard_options , key = lambda x : x .danger .get_max_danger ())[0 ]
405
412
0 commit comments