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

Commit b1da518

Browse files
committed
Add more tests and rename chankan to shouminkan in comments
1 parent 6432fb8 commit b1da518

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

project/game/ai/base/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def should_call_riichi(self):
5858

5959
def should_call_kan(self, tile, is_open_kan, from_riichi=False):
6060
"""
61-
When bot can call kan or chankan this method will be called
61+
When bot can call kan or shouminkan this method will be called
6262
:param tile: 136 tile format
6363
:param is_open_kan: boolean
6464
:param from_riichi: boolean

project/game/ai/first_version/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ def should_call_kan(self, tile, open_kan, from_riichi=False):
248248

249249
# let's check can we upgrade opened pon to the kan
250250
pon_melds = [x for x in self.player.meld_34_tiles if is_pon(x)]
251-
has_chankan_candidate = False
251+
has_shouminkan_candidate = False
252252
for meld in pon_melds:
253253
# tile is equal to our already opened pon
254254
if tile_34 in meld:
255-
has_chankan_candidate = True
255+
has_shouminkan_candidate = True
256256

257257
tiles.append(tile)
258258
closed_hand_tiles.append(tile)
@@ -272,7 +272,7 @@ def should_call_kan(self, tile, open_kan, from_riichi=False):
272272
)
273273
new_waits_count = self.hand_builder.count_tiles(new_waiting, tiles_34)
274274

275-
if not has_chankan_candidate:
275+
if not has_shouminkan_candidate:
276276
# we don't have enough tiles in the hand
277277
if closed_hand_34[tile_34] != 3:
278278
return None
@@ -312,7 +312,7 @@ def should_call_kan(self, tile, open_kan, from_riichi=False):
312312
assert new_waits_count <= previous_waits_count
313313

314314
if new_waits_count == previous_waits_count:
315-
return has_chankan_candidate and Meld.CHANKAN or Meld.KAN
315+
return has_shouminkan_candidate and Meld.CHANKAN or Meld.KAN
316316

317317
return None
318318

project/game/ai/first_version/tests/tests_ai.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def test_using_tiles_of_different_suit_for_chi(self):
395395
meld, _ = player.try_to_call_meld(tile, True)
396396
self.assertIsNotNone(meld)
397397

398-
def test_call_chankan_and_bad_ukeire_after_call(self):
398+
def test_call_upgrade_pon_and_bad_ukeire_after_call(self):
399399
table = Table()
400400
table.count_of_remaining_tiles = 10
401401

@@ -411,9 +411,10 @@ def test_call_chankan_and_bad_ukeire_after_call(self):
411411
self.assertEqual(len(table.player.tiles), 13)
412412
self.assertEqual(table.player.should_call_kan(tile, False), None)
413413

414-
def test_call_chankan_and_bad_ukeire_after_call_second(self):
414+
def test_call_upgrade_pon_and_bad_ukeire_after_call_second_case(self):
415415
table = Table()
416416
table.count_of_remaining_tiles = 10
417+
player = table.player
417418

418419
tiles = self._string_to_136_array(man='3455567', sou='222', honors='666')
419420
table.player.init_hand(tiles)
@@ -424,7 +425,31 @@ def test_call_chankan_and_bad_ukeire_after_call_second(self):
424425

425426
self.assertEqual(table.player.should_call_kan(tile, False), None)
426427

427-
def test_upgrade_opened_pon_to_kan(self):
428+
player.draw_tile(tile)
429+
discarded_tile = player.discard_tile()
430+
431+
self.assertEqual(self._to_string([discarded_tile]), '3m')
432+
433+
def test_call_upgrade_pon_and_bad_ukeire_after_call_third_case(self):
434+
table = Table()
435+
table.count_of_remaining_tiles = 10
436+
player = table.player
437+
438+
tiles = self._string_to_136_array(man='67', pin='6', sou='1344478999')
439+
table.player.init_hand(tiles)
440+
table.player.add_called_meld(self._make_meld(Meld.PON, sou='444'))
441+
442+
tile = self._string_to_136_tile(sou='4')
443+
444+
# we don't want to call shouminkan here
445+
self.assertEqual(table.player.should_call_kan(tile, False), None)
446+
447+
player.draw_tile(tile)
448+
discarded_tile = player.discard_tile()
449+
450+
self.assertEqual(self._to_string([discarded_tile]), '6p')
451+
452+
def test_call_shouminkan(self):
428453
table = Table()
429454
table.count_of_remaining_tiles = 10
430455

@@ -476,8 +501,7 @@ def test_opened_kan(self):
476501
tile = self._string_to_136_tile(sou='1')
477502
self.assertEqual(table.player.should_call_kan(tile, True), None)
478503

479-
# test case 2
480-
504+
def test_opened_kan_second_case(self):
481505
table = Table()
482506
table.count_of_remaining_tiles = 10
483507

@@ -493,7 +517,7 @@ def test_opened_kan(self):
493517
tile = self._string_to_136_tile(sou='1')
494518
self.assertEqual(table.player.should_call_kan(tile, True), Meld.KAN)
495519

496-
# test case 3
520+
def test_opened_kan_third_case(self):
497521
# we are in tempai already and there was a crash on 5s meld suggestion
498522

499523
table = Table()

project/game/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def erase_state(self):
6565
self.round_step = 0
6666

6767
def add_called_meld(self, meld: Meld):
68-
# we already added chankan as a pon set
68+
# we already added shouminkan as a pon set
6969
if meld.type == Meld.CHANKAN:
7070
tile_34 = meld.tiles[0] // 4
7171

7272
pon_set = [x for x in self.melds if x.type == Meld.PON and (x.tiles[0] // 4) == tile_34]
7373

74-
# when we are doing reconnect and we have called chankan set
74+
# when we are doing reconnect and we have called shouminkan set
7575
# we will not have called pon set in the hand
7676
if pon_set:
7777
self.melds.remove(pon_set[0])

project/game/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def add_called_meld(self, player_seat, meld):
108108
else:
109109
# can't have a pon or chi from the hand
110110
assert meld.type == Meld.KAN or meld.type == meld.CHANKAN
111-
# player draws additional tile from the wall in case of closed kan or chankan
111+
# player draws additional tile from the wall in case of closed kan or shouminkan
112112
self.count_of_remaining_tiles -= 1
113113

114114
self.get_player(player_seat).add_called_meld(meld)
@@ -119,7 +119,7 @@ def add_called_meld(self, player_seat, meld):
119119
if meld.called_tile is not None:
120120
tiles.remove(meld.called_tile)
121121

122-
# for chankan we already added 3 tiles
122+
# for shouminkan we already added 3 tiles
123123
if meld.type == meld.CHANKAN:
124124
tiles = [meld.tiles[0]]
125125

project/tenhou/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,13 @@ def start_game(self):
281281

282282
if kan_type == Meld.CHANKAN:
283283
meld_type = 5
284+
logger.info('We upgraded pon to kan!')
284285
else:
285286
meld_type = 4
287+
logger.info('We called a closed kan set!')
286288

287289
self._send_message('<N type="{}" hai="{}" />'.format(meld_type, drawn_tile))
288-
logger.info('We called a closed kan\chankan set!')
290+
289291
continue
290292

291293
if not main_player.in_riichi:
@@ -345,7 +347,7 @@ def start_game(self):
345347
]
346348
# we win by other player's discard
347349
if any(i in message for i in win_suggestions):
348-
# enemy called chankan and we can win there
350+
# enemy called shouminkan and we can win there
349351
if self.decoder.is_opened_set_message(message):
350352
meld = self.decoder.parse_meld(message)
351353
tile = meld.called_tile

0 commit comments

Comments
 (0)