Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions project/game/ai/first_version/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ def calculate_outs(self, tiles, closed_hand, open_sets_34=None):

def count_tiles(self, waiting, tiles_34):
n = 0
for item in waiting:
n += 4 - self.player.total_tiles(item, tiles_34)
not_suitable_tiles = self.current_strategy and self.current_strategy.not_suitable_tiles or []
for tile_34 in waiting:
if self.player.is_open_hand and tile_34 in not_suitable_tiles:
continue

n += 4 - self.player.total_tiles(tile_34, tiles_34)
return n

def try_to_call_meld(self, tile, is_kamicha_discard):
Expand Down
2 changes: 1 addition & 1 deletion project/game/ai/first_version/strategies/formal_tempai.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def should_activate_strategy(self):
return True

dora_count = sum([plus_dora(x, self.player.table.dora_indicators) for x in self.player.tiles])
dora_count += sum([1 for x in self.player.tiles if is_aka_dora(x, self.player.table.has_open_tanyao)])
dora_count += sum([1 for x in self.player.tiles if is_aka_dora(x, self.player.table.has_aka_dora)])

if self.player.ai.previous_shanten == 2:
if dora_count < 2:
Expand Down
1 change: 1 addition & 0 deletions project/game/ai/first_version/strategies/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BaseStrategy(object):
FORMAL_TEMPAI: 'Formal Tempai'
}

not_suitable_tiles = []
player = None
type = None
# number of shanten where we can start to open hand
Expand Down
57 changes: 56 additions & 1 deletion project/game/ai/first_version/strategies/tanyao.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from mahjong.constants import TERMINAL_INDICES, HONOR_INDICES
from mahjong.tile import TilesConverter
from mahjong.utils import is_tile_strictly_isolated, is_terminal
from mahjong.utils import plus_dora, is_aka_dora
from mahjong.utils import is_honor

from game.ai.first_version.strategies.main import BaseStrategy

Expand All @@ -21,10 +24,15 @@ def should_activate_strategy(self):
return False

tiles = TilesConverter.to_34_array(self.player.tiles)

closed_hand_34 = TilesConverter.to_34_array(self.player.closed_hand)
isolated_tiles = [x // 4 for x in self.player.tiles if is_tile_strictly_isolated(closed_hand_34, x // 4) or is_honor(x // 4)]

count_of_terminal_pon_sets = 0
count_of_terminal_pairs = 0
count_of_valued_pairs = 0
count_of_not_suitable_tiles = 0
count_of_not_suitable_not_isolated_tiles = 0
for x in range(0, 34):
tile = tiles[x]
if not tile:
Expand All @@ -40,7 +48,10 @@ def should_activate_strategy(self):
count_of_valued_pairs += 1

if x in self.not_suitable_tiles:
count_of_not_suitable_tiles += 1
count_of_not_suitable_tiles += tile

if x in self.not_suitable_tiles and x not in isolated_tiles:
count_of_not_suitable_not_isolated_tiles += tile

# we have too much terminals and honors
if count_of_not_suitable_tiles >= 5:
Expand All @@ -61,6 +72,17 @@ def should_activate_strategy(self):
if count_of_terminal_pairs > 1:
return False

# 3 or more not suitable tiles that
# are not isolated is too much
if count_of_not_suitable_not_isolated_tiles >= 3:
return False

# if we are 1 shanten, even 2 tiles
# that are not suitable and not isolated
# is too much
if count_of_not_suitable_not_isolated_tiles >= 2 and self.player.ai.previous_shanten == 1:
return False

# 123 and 789 indices
indices = [
[0, 1, 2], [6, 7, 8],
Expand All @@ -75,6 +97,39 @@ def should_activate_strategy(self):
if first >= 1 and second >= 1 and third >= 1:
return False

dora_count_central = 0
dora_count_not_central = 0
for tile_136 in self.player.tiles:
tile_34 = tile_136 // 4

dora = plus_dora(tile_136, self.player.table.dora_indicators)

if is_aka_dora(tile_136, self.player.table.has_aka_dora):
dora_count_central += 1

if not dora:
continue

if is_honor(tile_34) or is_terminal(tile_34):
dora_count_not_central += 1
else:
dora_count_central += 1

# if we have 2 or more non-central doras
# we don't want to go for tanyao
if dora_count_not_central >= 2:
return False

# if we have less than two central doras
# let's not consider open tanyao
if dora_count_central < 2:
return False

# if we have only two central doras let's
# wait for 5th turn before opening our hand
if dora_count_central == 2 and self.player.round_step < 5:
return False

return True

def determine_what_to_discard(self, closed_hand, outs_results, shanten, for_open_hand, tile_for_open_hand,
Expand Down
2 changes: 1 addition & 1 deletion project/game/ai/first_version/strategies/yakuhai.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def should_activate_strategy(self):
return False

dora_count = sum([plus_dora(x, self.player.table.dora_indicators) for x in self.player.tiles])
dora_count += sum([1 for x in self.player.tiles if is_aka_dora(x, self.player.table.has_open_tanyao)])
dora_count += sum([1 for x in self.player.tiles if is_aka_dora(x, self.player.table.has_aka_dora)])

# let's always open double east
if is_double_east_wind:
Expand Down
Loading