Coverage for project/game/ai/strategies/formal_tempai.py : 60%

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.strategies.main import BaseStrategy
4class FormalTempaiStrategy(BaseStrategy):
5 def should_activate_strategy(self, tiles_136, meld_tile=None):
6 """
7 When we get closer to the end of the round, we start to consider
8 going for formal tempai.
9 """
11 result = super(FormalTempaiStrategy, self).should_activate_strategy(tiles_136)
12 if not result:
13 return False
15 # if we already in tempai, we don't need this strategy
16 if self.player.in_tempai:
17 return False
19 # it's too early to go for formal tempai before 11th turn
20 if self.player.round_step < 11:
21 return False
23 # it's 11th turn or later and we still have 3 shanten or more,
24 # let's try to go for formal tempai at least
25 if self.player.ai.shanten >= 3:
26 return True
28 if self.player.ai.shanten == 2:
29 if self.dora_count_total < 2:
30 # having 0 or 1 dora and 2 shanten, let's go for formal tempai
31 # starting from 11th turn
32 return True
33 # having 2 or more doras and 2 shanten, let's go for formal
34 # tempai starting from 12th turn
35 return self.player.round_step >= 12
37 # for 1 shanten we check number of doras and ukeire to determine
38 # correct time to go for formal tempai
39 if self.player.ai.shanten == 1:
40 if self.dora_count_total == 0:
41 if self.player.ai.ukeire <= 16:
42 return True
44 if self.player.ai.ukeire <= 28:
45 return self.player.round_step >= 12
47 return self.player.round_step >= 13
49 if self.dora_count_total == 1:
50 if self.player.ai.ukeire <= 16:
51 return self.player.round_step >= 12
53 if self.player.ai.ukeire <= 28:
54 return self.player.round_step >= 13
56 return self.player.round_step >= 14
58 if self.player.ai.ukeire <= 16:
59 return self.player.round_step >= 13
61 return self.player.round_step >= 14
63 # we actually never reach here
64 return False
66 def is_tile_suitable(self, tile):
67 """
68 All tiles are suitable for formal tempai.
69 :param tile: 136 tiles format
70 :return: True
71 """
72 return True