Skip to content

Commit

Permalink
Merge pull request #24 from canuse/master
Browse files Browse the repository at this point in the history
Add fin_game line in paifu
  • Loading branch information
Ledenel authored Nov 27, 2019
2 parents 7b35dc9 + 0363d48 commit 90f0020
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 9 additions & 1 deletion mahjong/record/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __repr__(self):
def to_paifu(self):
paifu_data = []
prevailing, game_index = self.game_index()
game_str = "{0}-{1}-{2}".format("東南西北"[prevailing], game_index + 1, self.sub_game_index())
game_str = "{0}-{1}-{2}".format("ESWN"[prevailing], game_index + 1, self.sub_game_index())
for i in self.events:
paifu_data.extend(i.to_paifu())
for i in paifu_data:
Expand Down Expand Up @@ -168,6 +168,14 @@ def to_paifu(self):
paifu_data = []
for i in self.game_list:
paifu_data.extend(i.to_paifu())
fin1 = {'event_type': 'FIN1', 'player': '0', 'score': str(self.end_score[0] * 100)}
fin2 = {'event_type': 'FIN2', 'player': '1', 'score': str(self.end_score[1] * 100)}
fin3 = {'event_type': 'FIN3', 'player': '2', 'score': str(self.end_score[2] * 100)}
if len(self.players) == 4:
fin4 = {'event_type': 'FIN4', 'player': '3', 'score': str(self.end_score[3] * 100)}
paifu_data.extend([fin1, fin2, fin3, fin4])
else:
paifu_data.extend([fin1, fin2, fin3])
return paifu_data


Expand Down
21 changes: 17 additions & 4 deletions tests/test_paifu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def test_to_paifu(self):
retlen += len(ret)
assert retlen == 50

assert len(a.to_paifu()) == retlen

def test_init_to_paifu_sanma(self):
a = from_file("tests/2009060321gm-00b9-0000-75b25bcf.xml")
assert len(a.game_list[0].events[0].to_paifu()) == 5
Expand All @@ -28,8 +26,23 @@ def test_init_to_paifu_sima(self):
def test_pd(self):
a = from_file("tests/2009060321gm-00b9-0000-75b25bcf.xml")
pd_frame = pd.DataFrame(a.to_paifu())
assert len(pd_frame) == 50
assert len(pd_frame) == 53

a = from_file("tests/2009100718gm-00e1-0000-470654d3.xml")
pd_frame = pd.DataFrame(a.to_paifu())
assert len(pd_frame) == 71
assert len(pd_frame) == 75

def test_fin_game(self):
a = from_file("tests/2009060321gm-00b9-0000-75b25bcf.xml")
tr = len(a.to_paifu())
tg = 0
for i in a.game_list:
tg += len(i.to_paifu())
assert tr - tg == 3

a = from_file("tests/2009100718gm-00e1-0000-470654d3.xml")
tr = len(a.to_paifu())
tg = 0
for i in a.game_list:
tg += len(i.to_paifu())
assert tr - tg == 4

0 comments on commit 90f0020

Please sign in to comment.