Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit b1e2ceb

Browse files
committed
Calculate verified suji count based on enemy safe tiles, not on all revealed tiles
1 parent dc9195c commit b1e2ceb

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

project/game/ai/defence/enemy_analyzer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from game.ai.helpers.possible_forms import PossibleFormsAnalyzer
88
from mahjong.tile import TilesConverter
99
from mahjong.utils import is_aka_dora, plus_dora
10-
from utils.general import suits_tiles
10+
from utils.general import separate_tiles_by_suits
1111

1212

1313
class EnemyAnalyzer:
@@ -102,8 +102,7 @@ def assumed_hand_cost(self) -> int:
102102
def number_of_unverified_suji(self) -> int:
103103
maximum_number_of_suji = 18
104104
verified_suji = 0
105-
closed_hand_34 = TilesConverter.to_34_array(self.main_player.closed_hand)
106-
suits = suits_tiles(self.main_player, closed_hand_34)
105+
suits = separate_tiles_by_suits(TilesConverter.to_34_array([x * 4 for x in self.enemy.all_safe_tiles]))
107106
for suit in suits:
108107
# indices started from 0
109108
suji_indices = [[0, 3, 6], [1, 4, 7], [2, 5, 8]]

project/game/ai/helpers/kabe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utils.general import suits_tiles
1+
from utils.general import revealed_suits_tiles
22

33

44
class Kabe:
@@ -39,7 +39,7 @@ def find_all_kabe(self, tiles_34):
3939
kabe_tiles_weak = []
4040
kabe_tiles_partial = []
4141

42-
suits = suits_tiles(self.player, tiles_34)
42+
suits = revealed_suits_tiles(self.player, tiles_34)
4343
for x in range(0, 3):
4444
suit = suits[x]
4545

project/game/ai/helpers/possible_forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from game.ai.helpers.defence import TileDanger
22
from mahjong.constants import EAST
33
from mahjong.tile import TilesConverter
4-
from utils.general import suits_tiles
4+
from utils.general import revealed_suits_tiles
55

66

77
class PossibleFormsAnalyzer:
@@ -20,7 +20,7 @@ def calculate_possible_forms(self, safe_tiles):
2020
closed_hand_34 = TilesConverter.to_34_array(self.player.closed_hand)
2121

2222
# first of all let's find suji for suits tiles
23-
suits = suits_tiles(self.player, closed_hand_34)
23+
suits = revealed_suits_tiles(self.player, closed_hand_34)
2424
for x in range(0, 3):
2525
suit = suits[x]
2626

project/utils/general.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,47 @@ def make_random_letters_and_digit_string(length=15):
1010
return "".join(random.choice(random_chars) for _ in range(length))
1111

1212

13-
def suits_tiles(player, tiles_34):
13+
def revealed_suits_tiles(player, tiles_34):
1414
"""
15-
Return tiles separated by suits
15+
Return all reviled tiles separated by suits for provided tiles list
16+
"""
17+
return _suits_tiles_helper(
18+
tiles_34, lambda _tile_34_index, _tiles_34: player.number_of_revealed_tiles(_tile_34_index, _tiles_34)
19+
)
20+
21+
22+
def separate_tiles_by_suits(tiles_34):
23+
"""
24+
Return tiles separated by suits for provided tiles list
25+
"""
26+
return _suits_tiles_helper(tiles_34, lambda _tile_34_index, _tiles_34: _tiles_34[_tile_34_index])
27+
28+
29+
def _suits_tiles_helper(tiles_34, total_tiles_lambda):
30+
"""
31+
Separate tiles by suit
1632
"""
1733
suits = [
1834
[0] * 9,
1935
[0] * 9,
2036
[0] * 9,
2137
]
2238

23-
for tile in range(0, EAST):
24-
total_tiles = player.number_of_revealed_tiles(tile, tiles_34)
39+
for tile_34_index in range(0, EAST):
40+
total_tiles = total_tiles_lambda(tile_34_index, tiles_34)
2541
if not total_tiles:
2642
continue
2743

2844
suit_index = None
29-
simplified_tile = simplify(tile)
45+
simplified_tile = simplify(tile_34_index)
3046

31-
if is_man(tile):
47+
if is_man(tile_34_index):
3248
suit_index = 0
3349

34-
if is_pin(tile):
50+
if is_pin(tile_34_index):
3551
suit_index = 1
3652

37-
if is_sou(tile):
53+
if is_sou(tile_34_index):
3854
suit_index = 2
3955

4056
suits[suit_index][simplified_tile] += total_tiles

0 commit comments

Comments
 (0)