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
18 changes: 11 additions & 7 deletions project/game/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ def init_round(self,
def add_called_meld(self, player_seat, meld):
self.meld_was_called = True

# when opponent called meld it is means
# that he discards tile from hand, not from wall
self.count_of_remaining_tiles += 1

# we will decrease count of remaining tiles after called kan
# because we had to complement dead wall
if meld.type == Meld.KAN or meld.type == meld.CHANKAN:
# if meld was called from the other player, then we skip one draw from the wall
if meld.opened:
# but if it's an opened kan, player will get a tile from
# a dead wall, so total number of tiles in the wall is the same
# as if he just draws a tile
if meld.type != Meld.KAN:
self.count_of_remaining_tiles += 1
else:
# can't have a pon or chi from the hand
assert meld.type == Meld.KAN or meld.type == meld.CHANKAN
# player draws additional tile from the wall in case of closed kan or chankan
self.count_of_remaining_tiles -= 1

self.get_player(player_seat).add_called_meld(meld)
Expand Down
31 changes: 28 additions & 3 deletions project/game/tests/tests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_discard_tile(self):
self.assertFalse(tile in client.table.player.tiles)
self.assertEqual(client.table.count_of_remaining_tiles, 69)

def test_call_meld(self):
def test_call_meld_closed_kan(self):
client = Client()

client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
Expand All @@ -41,13 +41,38 @@ def test_call_meld(self):
meld = Meld()
meld.type = Meld.KAN
# closed kan
meld.tiles = [0, 1, 2, 3]
meld.called_tile = None
meld.opened = False
client.table.add_called_meld(0, meld)

self.assertEqual(len(client.player.melds), 2)
# +1 for called meld
# -1 for called kan
# kan was closed, so -1
self.assertEqual(client.table.count_of_remaining_tiles, 70)

def test_call_meld_kan_from_player(self):
client = Client()

client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
self.assertEqual(client.table.count_of_remaining_tiles, 70)

meld = Meld()
client.table.add_called_meld(0, meld)

self.assertEqual(len(client.player.melds), 1)
self.assertEqual(client.table.count_of_remaining_tiles, 71)

client.player.tiles = [0]
meld = Meld()
meld.type = Meld.KAN
# closed kan
meld.tiles = [0, 1, 2, 3]
meld.called_tile = 0
meld.opened = True
client.table.add_called_meld(0, meld)

self.assertEqual(len(client.player.melds), 2)
# kan was called from another player, total number of remaining tiles stays the same
self.assertEqual(client.table.count_of_remaining_tiles, 71)

def test_enemy_discard(self):
Expand Down
4 changes: 3 additions & 1 deletion project/tenhou/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def parse_meld(self, message):

meld = Meld()
meld.who = int(self.get_attribute_content(message, 'who'))
meld.from_who = data & 0x3
# 'from_who' is encoded relative the the 'who', so we want
# to convert it to be relative to our player
meld.from_who = ((data & 0x3) + meld.who) % 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я взял код выше отсюда: https://github.com/NegativeMjark/tenhou-log/blob/master/TenhouDecoder.py#L38

У них же можешь посмотреть на формал мелда: https://github.com/NegativeMjark/tenhou-log#meld-format


if data & 0x4:
self.parse_chi(data, meld)
Expand Down
4 changes: 2 additions & 2 deletions project/tenhou/tests/tests_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_parse_called_opened_kan(self):
meld = decoder.parse_meld('<N who="3" m="13825" />')

self.assertEqual(meld.who, 3)
self.assertEqual(meld.from_who, 1)
self.assertEqual(meld.from_who, 0)
self.assertEqual(meld.type, Meld.KAN)
self.assertEqual(meld.opened, True)
self.assertEqual(meld.tiles, [52, 53, 54, 55])
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_parse_who_called_riichi(self):
def test_reconnection_information(self):
message = '<REINIT seed="0,0,1,4,3,59" ten="250,250,250,240" oya="0" ' \
'hai="1,2,4,13,17,20,46,47,53,71,76,81,85" ' \
'm2="41513" ' \
'm2="41515" ' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

41513 был пример из реального лога, так что я думаю это не стоило менять. Возможно оно работало до этого так как хотела тенха :)

'kawa0="120,28,128,131,18,75,74,27,69,130,64" ' \
'kawa1="117,121,123,129,103,72,83,125,62,84" ' \
'kawa2="33,114,122,107,31,105,78,9,68,73,38" ' \
Expand Down