-
Notifications
You must be signed in to change notification settings - Fork 15
/
TenhouYaku.py
45 lines (37 loc) · 1.46 KB
/
TenhouYaku.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/python3
import TenhouDecoder
import collections
from Data import Data
YakuHanCounter = collections.namedtuple('YakuHanCounter', 'yaku han')
class YakuCounter(Data):
def __init__(self):
self.hands = collections.Counter()
self.closed = YakuHanCounter(collections.Counter(), collections.Counter())
self.opened = YakuHanCounter(collections.Counter(), collections.Counter())
self.all = YakuHanCounter(collections.Counter(), collections.Counter())
def addGame(self, game):
for round in game.rounds:
self.addRound(round)
def addRound(self, round):
for agari in round.agari:
self.addAgari(agari)
def addAgari(self, agari):
counterYaku, counterHan = self.closed if agari.closed else self.opened
allCounterYaku, allCounterHan = self.all
self.hands["closed" if agari.closed else "opened"] += 1
if hasattr(agari, 'yaku'):
for yaku, han in agari.yaku.items():
counterYaku[yaku] += 1
counterHan[yaku] += han
allCounterYaku[yaku] += 1
allCounterHan[yaku] += han
if __name__ == '__main__':
import sys
import yaml
counter = YakuCounter()
for path in sys.argv[1:]:
game = TenhouDecoder.Game()
print(path)
game.decode(open(path))
counter.addGame(game)
yaml.dump(counter.asdata(), sys.stdout, default_flow_style=False, allow_unicode=True)