-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcalculator.js
159 lines (144 loc) · 3.57 KB
/
calculator.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const {Pai, decomp} = require('@hakatashi/riichi-core');
const Agari = require('@hakatashi/riichi-core/src/agari');
const tenhou6 = require('@hakatashi/riichi-core/src/tenhou6');
const paiIndices = [
'1z', '2z', '3z', '4z', '7z', '6z', '5z',
'1m', '2m', '3m', '4m', '5m', '6m', '7m', '8m', '9m',
'1s', '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s',
'1p', '2p', '3p', '4p', '5p', '6p', '7p', '8p', '9p',
];
const 牌ToPai = (牌, {no赤牌 = false} = {}) => {
if (!no赤牌) {
if (牌 === '🀋\uFE00') {
return Pai['0m'];
}
if (牌 === '🀔\uFE00') {
return Pai['0s'];
}
if (牌 === '🀝\uFE00') {
return Pai['0p'];
}
}
return Pai[paiIndices[牌.codePointAt(0) - 0x1F000]];
};
module.exports.agari = (牌s, {isHaitei = false, isVirgin = false, isRiichi = false, isDoubleRiichi = false, isIppatsu = false, isRon = false, doraHyouji = [], uraDoraHyouji = [], additionalDora = 0}) => {
const pais = 牌s.map((牌) => 牌ToPai(牌));
const paisWithout赤牌 = 牌s.map((牌) => 牌ToPai(牌, {no赤牌: true}));
const agari = new Agari({
rulevar: {
dora: {
akahai: [1, 2, 1],
kan: {
daiminkan: 0,
kakan: 0,
ankan: 1,
},
ura: true,
kanUra: true,
},
yaku: {
kuitan: true,
kokushiAnkan: false,
},
yakuman: {
max: 14,
daisuushi: 2,
suuankouTanki: 2,
junseichuurenpoutou: 2,
tenhou: 1,
chihou: 2,
kokushi13: 2,
},
riichi: {
kyoutaku: 1000,
minTsumoLeft: 4,
double: true,
ankan: true,
okurikan: false,
},
ron: {
atamahane: false,
honbaAtamahane: true,
double: true,
triple: false,
},
banKuikae: {
moro: true,
suji: true,
pon: false,
},
ryoukyoku: {
kyuushuukyuuhai: true,
nagashimangan: false,
tochuu: {
suufonrenta: true,
suukaikan: true,
suuchariichi: true,
},
},
points: {
initial: 25000,
origin: 30000,
riichi: 1000,
howanpai: 3000,
honba: 100,
},
setup: {
points: {
initial: 25000, origin: 30000,
},
end: {
normal: 2,
overtime: 3,
suddenDeath: true,
oyaALTop: true,
},
},
},
agariPai: pais[pais.length - 1],
juntehai: pais.slice(0, -1),
tenpaiDecomp: decomp.decompTenpai(Pai.binsFromArray(paisWithout赤牌.slice(0, -1))),
fuuro: [],
menzen: true,
riichi: {
accepted: isRiichi,
double: isDoubleRiichi,
ippatsu: isIppatsu,
},
doraHyouji: doraHyouji.map((牌) => 牌ToPai(牌)),
uraDoraHyouji: uraDoraHyouji.map((牌) => 牌ToPai(牌)),
additionalDora,
chancha: 0,
agariPlayer: 0,
houjuuPlayer: isRon ? 1 : null,
honba: 0,
isHaitei,
virgin: isVirgin,
bakaze: 0,
jikaze: 0,
});
agari.yaku = agari.yaku || [];
agari.yakuman = agari.yakuman || [];
const 役s = (() => {
if (!agari.isAgari) {
return null;
}
const raw役s = tenhou6.makeAgari({chancha: 0, bakaze: 0}, agari).slice(4);
const 役sWithoutParens = raw役s.map((string) => string.replace(/\(.+?\)/, ''));
const 役sWithoutドラ = 役sWithoutParens.filter((役) => !役.includes('ドラ'));
if (agari.doraTotal > 0) {
役sWithoutドラ.push(`ドラ${agari.doraTotal}`);
}
return 役sWithoutドラ;
})();
return {
agari,
役s,
};
};
module.exports.tenpai = (牌s) => {
const pais = 牌s.map(牌ToPai);
const tenpaiDecomp = decomp.decompTenpai(Pai.binsFromArray(pais));
return tenpaiDecomp.decomps.length > 0;
};
module.exports.paiIndices = paiIndices;