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 mahjong.utils import is_man, is_pin, is_sou, simplify 

2 

3 

4class Suji: 

5 # 1-4-7 

6 FIRST_SUJI = 1 

7 # 2-5-8 

8 SECOND_SUJI = 2 

9 # 3-6-9 

10 THIRD_SUJI = 3 

11 

12 def __init__(self, player): 

13 self.player = player 

14 

15 def find_suji(self, tiles_136): 

16 tiles_34 = list(set([x // 4 for x in tiles_136])) 

17 

18 suji = [] 

19 suits = [[], [], []] 

20 

21 # let's cast each tile to 0-8 presentation 

22 for tile in tiles_34: 

23 if is_man(tile): 

24 suits[0].append(simplify(tile)) 

25 

26 if is_pin(tile): 

27 suits[1].append(simplify(tile)) 

28 

29 if is_sou(tile): 

30 suits[2].append(simplify(tile)) 

31 

32 for x in range(0, 3): 

33 simplified_tiles = suits[x] 

34 base = x * 9 

35 

36 # 1-4-7 

37 if 3 in simplified_tiles: 

38 suji.append(self.FIRST_SUJI + base) 

39 

40 # double 1-4-7 

41 if 0 in simplified_tiles and 6 in simplified_tiles: 

42 suji.append(self.FIRST_SUJI + base) 

43 

44 # 2-5-8 

45 if 4 in simplified_tiles: 

46 suji.append(self.SECOND_SUJI + base) 

47 

48 # double 2-5-8 

49 if 1 in simplified_tiles and 7 in simplified_tiles: 

50 suji.append(self.SECOND_SUJI + base) 

51 

52 # 3-6-9 

53 if 5 in simplified_tiles: 

54 suji.append(self.THIRD_SUJI + base) 

55 

56 # double 3-6-9 

57 if 2 in simplified_tiles and 8 in simplified_tiles: 

58 suji.append(self.THIRD_SUJI + base) 

59 

60 all_suji = list(set(suji)) 

61 result = [] 

62 for suji in all_suji: 

63 suji_temp = suji % 9 

64 base = suji - suji_temp - 1 

65 

66 if suji_temp == self.FIRST_SUJI: 

67 result += [base + 1, base + 4, base + 7] 

68 

69 if suji_temp == self.SECOND_SUJI: 

70 result += [base + 2, base + 5, base + 8] 

71 

72 if suji_temp == self.THIRD_SUJI: 

73 result += [base + 3, base + 6, base + 9] 

74 

75 return result