File size: 8,849 Bytes
dc15a10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def Translate(data):
    for msg in data:
        return msg

tiles_tenhou: dict[str, int] = {
    '1m': 0, '2m': 1, '3m': 2, '4m': 3, '5m': 4, '5mr': 34, '6m': 5, '7m': 6, '8m': 7, '9m': 8,
    '1p': 9, '2p': 10, '3p': 11, '4p': 12, '5p': 13, '5pr': 35, '6p': 14, '7p': 15, '8p': 16, '9p': 17,
    '1s': 18, '2s': 19, '3s': 20, '4s': 21, '5s': 22, '5sr': 36, '6s': 23, '7s': 24, '8s': 25, '9s': 26,
    'E': 27, 'S': 28, 'W': 29, 'N': 30, 'P': 31, 'F': 32, 'C': 33
}

def TileName(tile_id):
    if tile_id not in tiles_tenhou:
        return tile_id
    return [
        '1m', '2m', '3m', '4m', '5m', '6m', '7m', '8m', '9m',
        '1p', '2p', '3p', '4p', '5p', '6p', '7p', '8p', '9p',
        '1s', '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s',
        # '东', '南', '西', '北', '白', '发', '中',
        '1z', '2z', '3z', '4z', '5z', '6z', '7z',
        '0m', '0p', '0s'
    ][tiles_tenhou[tile_id]]

def Dir(who, seat=0):
    if who == seat:
        return '自家'
    if who == (seat + 1) % 4:
        return '下家'
    if who == (seat + 2) % 4:
        return '对家'
    return '上家'

NUKI_CN = {'chi': '吃', 'pon': '碰',
           'kakan': '杠', 'ankan': '杠',
           'daiminkan': '杠'}

NUKI_JP = {'chi': 'チー', 'pon': 'ポン',
           'kakan': 'カン', 'ankan': 'カン',
           'daiminkan': 'カン'}

def ScoreList(msg, seat=0, is3p=False):
    return ','.join(Dir(i, seat) + ' ' + str(x) for i, x in enumerate(msg['scores'][0:3 if is3p else 4]))

def TranslateSingle(msg, seat=0):
    action = msg['type']
    if action == 'start_kyoku':
        bakaze = msg['bakaze']
        return ('东南西北'['ESWN'.index(bakaze)] +
                ' ' + str(msg['kyoku']) + ' 局' +
                ' ' + str(msg['honba']) + ' 本场,宝牌指示牌 ' +
                TileName(msg['dora_marker']) + '\n' +
                ScoreList(msg, seat))
    elif action == 'nukidora':
        return Dir(msg['actor'], seat) + '拔北'
    elif action == 'tsumo':
        return Dir(msg['actor'], seat) + '摸牌 ' + TileName(msg['pai'])
    elif action == 'dahai':
        return Dir(msg['actor'], seat) + ('摸切' if msg['tsumogiri'] else '手切') + ' ' + TileName(msg['pai'])
    elif action in NUKI_CN:
        return (Dir(msg['actor'], seat) + NUKI_CN[action]
        + ('' if action not in ('chi', 'peng') else ' ' + (' '.join([TileName(x) for x in msg['consumed']]))))
    elif action == 'reach':
        return Dir(msg['actor'], seat) + '宣告立直'
    elif action == 'reach_accepted':
        return Dir(msg['actor'], seat) + '立直成功'
    elif action == 'dora':
        return '新宝牌指示牌:' + TileName(msg['dora_marker'])
    elif action == 'hora':
        return '和牌' #,新分数列表:' + ScoreList(msg, seat)
    elif action == 'ryukyoku':
        return '流局'
    elif action == 'none':
        return '跳过'
    else:
        return str(msg)

def TranslateSingleRaw(msg, seat=0, is3p=False):
    action = msg['type']
    if action == 'start_kyoku':
        bakaze = msg['bakaze']
        return ('东南西北'['ESWN'.index(bakaze)] +
                ' ' + str(msg['kyoku']) + ' 局' +
                ' ' + str(msg['honba']) + ' 本场,' + ScoreList(msg, seat, is3p))
    elif action == 'nukidora':
        return Dir(msg['actor'], seat) + '拔北'
    elif action == 'tsumo':
        return Dir(msg['actor'], seat) + '自摸|' + TileName(msg['pai'])
    elif action == 'dahai':
        return Dir(msg['actor'], seat) + '打|' + TileName(msg['pai'])
    elif action in NUKI_CN:
        return (Dir(msg['actor'], seat) + NUKI_CN[action] +
            '|' + TileName(msg['pai'])
            + ('' if action not in ('chi', 'peng') else '|' + ('|'.join([TileName(x) for x in msg['consumed']]))))
    elif action == 'reach':
        return Dir(msg['actor'], seat) + '立直'
    elif action == 'reach_accepted':
        return Dir(msg['actor'], seat) + '宣告立直'
    elif action == 'dora':
        return '新宝牌指示牌:' + TileName(msg['dora_marker'])
    elif action == 'hora':
        return '和'
    elif action == 'ryukyoku':
        return '流局'
    elif action == 'none':
        return '跳过'
    else:
        return str(msg)

if __name__ == '__main__':
    true = True
    false = False
    data = [{"type": "start_kyoku", "bakaze": "E", "kyoku": 3, "honba": 0, "kyotaku": 0, "oya": 2, "dora_marker": "9m", "scores": [37000, 19000, 49000, 0], "tehais": [["4p", "9m", "E", "1m", "2s", "P", "4p", "W", "9s", "5s", "1m", "8p", "1m"], ["?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"], ["?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"], ["?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"]]}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "9m", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "N"}, {"type": "nukidora", "actor": 0, "pai": "N"}, {"type": "tsumo", "actor": 0, "pai": "9s"}, {"type": "dahai", "actor": 0, "pai": "9m", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "4s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "W", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "2p"}, {"type": "dahai", "actor": 0, "pai": "W", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "6s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "C", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "9m"}, {"type": "dahai", "actor": 0, "pai": "9m", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "9s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "7s", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "9s"}, {"type": "dahai", "actor": 0, "pai": "E", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "9p", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "7s", "tsumogiri": false}, {"type": "tsumo", "actor": 0, "pai": "1p"}, {"type": "dahai", "actor": 0, "pai": "P", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "4s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "8s", "tsumogiri": false}, {"type": "tsumo", "actor": 0, "pai": "8s"}, {"type": "dahai", "actor": 0, "pai": "8s", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "4p", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "E", "tsumogiri": false}, {"type": "tsumo", "actor": 0, "pai": "N"}, {"type": "nukidora", "actor": 0, "pai": "N"}, {"type": "tsumo", "actor": 0, "pai": "3s"}, {"type": "dahai", "actor": 0, "pai": "5s", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "E", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "1m", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "8p"}, {"type": "dahai", "actor": 0, "pai": "1p", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "1s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "5p", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "6p"}, {"type": "dahai", "actor": 0, "pai": "2p", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "6s", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "9p", "tsumogiri": true}, {"type": "tsumo", "actor": 0, "pai": "8p"}, {"type": "reach", "actor": 0}, {"type": "dahai", "actor": 0, "pai": "6p", "tsumogiri": true}, {"type": "reach_accepted", "actor": 0, "deltas": [-1000, 0, 0, 0], "scores": [36000, 19000, 49000, 0]}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "7p", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "C", "tsumogiri": false}, {"type": "tsumo", "actor": 0, "pai": "C"}, {"type": "dahai", "actor": 0, "pai": "C", "tsumogiri": true}, {"type": "tsumo", "actor": 1, "pai": "?"}, {"type": "dahai", "actor": 1, "pai": "6p", "tsumogiri": false}, {"type": "tsumo", "actor": 2, "pai": "?"}, {"type": "dahai", "actor": 2, "pai": "1s", "tsumogiri": true}]

    for x in data:
        print(TranslateSingle(x))