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

Commit 4f8afea

Browse files
committed
Issue #32. Fix an issue with crash after called kan set
1 parent d0eccdd commit 4f8afea

File tree

6 files changed

+84
-5
lines changed

6 files changed

+84
-5
lines changed

project/mahjong/ai/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class MainAI(BaseAI):
24-
version = '0.2.5'
24+
version = '0.2.7'
2525

2626
agari = None
2727
shanten = None

project/mahjong/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def enemy_called_riichi(self):
209209
self.ai.in_defence = True
210210

211211
def add_called_meld(self, meld: Meld):
212-
# we had to remove tile from the hand for the kan set
213-
if meld.type == Meld.KAN or meld.type == Meld.CHANKAN and meld.called_tile in self.tiles:
212+
# we had to remove tile from the hand for closed kan set
213+
if (meld.type == Meld.KAN or meld.type == Meld.CHANKAN) and not meld.opened:
214214
self.tiles.remove(meld.called_tile)
215215

216216
super().add_called_meld(meld)

project/reproducer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,13 @@ class SocketMock(object):
206206
Reproduce tenhou <-> bot communication
207207
"""
208208

209-
def __init__(self, log_path):
209+
def __init__(self, log_path, log_content=''):
210210
self.log_path = log_path
211211
self.commands = []
212-
self.text = self._load_text()
212+
if not log_content:
213+
self.text = self._load_text()
214+
else:
215+
self.text = log_content
213216
self._parse_text()
214217

215218
def connect(self, _):

project/tenhou/tests/__init__.py

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- coding: utf-8 -*-
2+
import unittest
3+
4+
from reproducer import TenhouLogReproducer, SocketMock
5+
from tenhou.client import TenhouClient
6+
from tenhou.decoder import TenhouDecoder, Meld
7+
8+
9+
class TenhouClientTestCase(unittest.TestCase):
10+
11+
def test_fixed_crash_after_called_kan(self):
12+
log = """
13+
Get: <HELO uname="Name" auth="20170415-1111111" />
14+
Get: <LN/>
15+
Get: <GO type="137" lobby="0" gpid=""/> <UN n0="1" n1="2" n2="3" n3="4" dan="11,12,13,11" rate="1500,1500,1500,1500" sx="M,M,M,M"/> <TAIKYOKU oya="3" log="123"/>
16+
Get: <INIT seed="6,2,2,5,0,37" ten="203,96,474,207" oya="1" hai="90,83,14,33,132,119,129,117,26,52,121,134,29"/> <U/>
17+
Get: <E32/> <V/>
18+
Get: <F108/> <W/>
19+
Get: <G55/> <T89/>
20+
Get: <D52/> <U/>
21+
Get: <E109/> <V/>
22+
Get: <F124/> <W/>
23+
Get: <G92/>
24+
Get: <T77/>
25+
Get: <D121/> <U/>
26+
Get: <E125/> <V/>
27+
Get: <f123/> <W/>
28+
Get: <G10/> <T38/>
29+
Get: <D129/> <U/>
30+
Get: <e0/> <V/>
31+
Get: <F130/> <W/>
32+
Get: <G15/> <T42/>
33+
Get: <D14/> <U/>
34+
Get: <E64/>
35+
Get: <V/>
36+
Get: <f115/>
37+
Get: <N who="3" m="44075" />
38+
Get: <G8/> <T5/>
39+
Get: <D5/> <U/>
40+
Get: <E70/>
41+
Get: <V/>
42+
Get: <f80/> <W/>
43+
Get: <g111/> <T68/>
44+
Get: <D68/> <U/>
45+
Get: <E113/> <V/>
46+
Get: <F21/> <W/>
47+
Get: <G128/> <T78/>
48+
Get: <D38/> <U/>
49+
Get: <E82/> <V/>
50+
Get: <f81/> <W/>
51+
Get: <g6/> <T116/>
52+
Get: <D42/>
53+
Get: <N who="1" m="15915" />
54+
Get: <E50/> <V/>
55+
Get: <F3/> <W/>
56+
Get: <G135 t="1"/>
57+
Get: <N who="0" m="51755" />
58+
Get: <D77/> <U/>
59+
Get: <E103/>
60+
Get: <V/>
61+
Get: <f76/> <W/>
62+
Get: <G118 t="3"/>
63+
Get: <N who="0" m="30211" /> <T39/>
64+
"""
65+
66+
client = TenhouClient(SocketMock(None, log))
67+
with self.assertRaises(KeyboardInterrupt) as context:
68+
client.connect()
69+
client.authenticate()
70+
client.start_game()
71+
72+
# close all threads
73+
client.end_game()
74+
75+
# end of commands is correct way to end log reproducing
76+
self.assertTrue('End of commands' in str(context.exception))
File renamed without changes.

0 commit comments

Comments
 (0)