Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from game.ai.defence.yaku_analyzer.yaku_analyzer import YakuAnalyzer 

2from mahjong.utils import is_honor 

3 

4 

5class HonitsuAnalyzerBase(YakuAnalyzer): 

6 chosen_suit = None 

7 

8 def __init__(self, enemy): 

9 self.enemy = enemy 

10 self.chosen_suit = None 

11 

12 def serialize(self): 

13 return {"id": self.id, "chosen_suit": self.chosen_suit and self.chosen_suit.__name__} 

14 

15 def get_tempai_probability_modifier(self): 

16 # if enemy has not yet discarded his suit and there are less than 3 melds, consider tempai less probable 

17 suit_discards = [x for x in self.enemy.discards if self.chosen_suit(x.value // 4)] 

18 

19 if not suit_discards and len(self.enemy.melds) <= 3: 

20 return 0.5 

21 

22 return 1 

23 

24 def _check_discard_order(self, suit, early_position): 

25 # let's check the following considiton: 

26 # if enemy had discarded tiles from that suit or honor and after that he had discarded a tile from a different 

27 # suit from his hand - let's believe it's not honitsu 

28 suit_discards_positions = [ 

29 self.enemy.discards.index(x) for x in self.enemy.discards if suit["function"](x.value // 4) 

30 ] 

31 if suit_discards_positions: 

32 # we consider second discard of chosen suit to be reference point 

33 # first one could have happened when player was not yet sure if he is going to honitsu 

34 # after the second one there should be no discars of other suit from hand 

35 reference_discard = suit_discards_positions[min(1, len(suit_discards_positions) - 1)] 

36 discards_after = self.enemy.discards[reference_discard:] 

37 if discards_after: 

38 has_discarded_other_suit_from_hand = [ 

39 x 

40 for x in discards_after 

41 if (not x.is_tsumogiri and not is_honor(x.value // 4) and not suit["function"](x.value // 4)) 

42 ] 

43 if has_discarded_other_suit_from_hand: 

44 return False 

45 

46 # if we started discards suit tiles early, it's probably not honitsu 

47 if suit_discards_positions[0] <= early_position: 

48 return False 

49 

50 # discard order seems similar to honitsu/chinitsu one 

51 return True