forked from Zecknol/lietxia.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fupractice.html
630 lines (565 loc) · 20.5 KB
/
fupractice.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>算符練習</title>
</head>
<style>
@font-face {
font-family: "MJ";
src: url("./res/mj.eot");
/* IE9 Compat Modes */
src: url("./res/mj.eot?#iefix") format("embedded-opentype"),
/* IE6-IE8 */
url("./res/mj.otf") format("opentype"),
/* Open Type Font */
url("./res/mj.svg") format("svg"),
/* Legacy iOS */
url("./res/mj.ttf") format("truetype"),
/* Safari, Android, iOS */
url("./res/mj.woff") format("woff"),
/* Modern Browsers */
url("./res/mj.woff2") format("woff2");
/* Modern Browsers */
font-weight: normal;
font-style: normal;
}
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #eed;
}
.describe {
color: #1a1;
font-size: 2.5vw;
}
table {
border-collapse: collapse;
text-align: right;
margin: 10px auto;
}
#handInfo tr,
#handInfo td,
{ border: none;
padding: 5px 10px;}
#fieldInfo td {
font-size: 7vw;
text-align: center;
}
.lastTile {
background-color: #f80;
}
.correct {
background-color: #2e2;
}
.incorrect {
background-color: #c44;
}
.button {
border: 3px solid red;
color: green;
cursor: pointer;
}
.button:hover {
background-color: #ada;
}
#fu {
width: 2.5em;
font-size: 1em;
}
.hand {
font-family: "MJ";
border: none;
font-size: 7vw;
}
.hidden {
visibility: hidden;
}
.nodraw {
display: none;
}
table td {
padding: 0;
border: 1px solid #333;
}
table th {
background-color: #000;
border: 1px solid #f80;
color: #fff;
}
#hintTableH {
white-space: nowrap;
}
#hintH {
overflow-x: scroll;
}
</style>
<body>
<noscript>
Please enable Javascript on this page to render
<br> 畫畫面需要用到Javascript, 讓我用嘛OAO...
</noscript>
<div id="hintH">
<table id="hintTableH" cellspacing="0" cellpadding="0">
<tr>
<th colspan="2">和牌符</th>
<th colspan="2">听牌符</th>
<th colspan="4">面子符(中张=2到8)</th>
<th colspan="2">雀头符</th>
<th colspan="2">其他规定(定为XX的无视其他规则)</th>
</tr>
<tr>
<td>副底(和牌就有)</td>
<td>20符</td>
<td>单骑和牌</td>
<td>2符</td>
<td>中张明刻</td>
<td>2符</td>
<td>幺九明刻</td>
<td>4符</td>
<td>役牌雀头</td>
<td>2符</td>
<td colspan="2">合计后,符个位不是0时:个位变0 十位+1</td>
</tr>
<tr>
<td>门前清荣和</td>
<td>10符</td>
<td>边张和牌</td>
<td>2符</td>
<td>中张暗刻</td>
<td>4符</td>
<td>幺九暗刻</td>
<td>8符</td>
<td>连风雀头</td>
<td>2或4</td>
<td>七对子荣和\自摸</td>
<td>定为25符</td>
</tr>
<tr>
<td>自摸和牌</td>
<td>2符</td>
<td>嵌张和牌</td>
<td>2符</td>
<td>中张明杠</td>
<td>8符</td>
<td>幺九明杠</td>
<td>16符</td>
<td colspan="2" rowspan="2">※天凤连风雀头4符</td>
<td>平和+自摸</td>
<td>定为20符</td>
</tr>
<tr>
<td>荣和(非门前清)</td>
<td>0符</td>
<td>两面/双碰</td>
<td>0符</td>
<td>中张暗杠</td>
<td>16符</td>
<td>幺九暗杠</td>
<td>32符</td>
<td>吃牌后,合计20符时</td>
<td>定为30符</td>
</tr>
</table>
</div>
<div id="box">
<div id="problemSection">
<div>
<table id="fieldInfo">
<tr>
<td id="fieldWind"></td>
<td id="selfWind"></td>
<td id="winType"></td>
</tr>
<tr>
<td>
<input id="fu" type="number" value="30" max="170" min="20" step="10" onfocus="this.select()" />符</td>
<td>
<div id="chkAns" class="button" onclick="showAnswer()">作答</div>
<div id="correct" class="correct nodraw">正確</div>
<div id="incorrect" class="incorrect nodraw">錯誤</div>
</td>
<td>
<div id="nextQuestion" class="button hidden" onclick="generateProblem()">下一題</div>
</td>
</tr>
</table>
</div>
<div>
<table id="handInfo">
<tr>
<td id="hand0" class="hand"></td>
<td id="hand1" class="hand"></td>
<td id="hand2" class="hand"></td>
<td id="hand3" class="hand"></td>
<td id="hand4" class="hand"></td>
</tr>
<tr>
<td id="info0" class="describe">1</td>
<td id="info1" class="describe">2</td>
<td id="info2" class="describe">3</td>
<td id="info3" class="describe">4</td>
<td id="info4" class="describe">5</td>
</tr>
<tr>
<td id="infob" colspan="5" class="describe">1</td>
</tr>
<tr>
<td id="extra" colspan="5" class="describe"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
<script>
var $ = function (e) { return document.getElementById(e) };
var f = function (e) { return Math.floor(e) };
var rnd = function () { return Math.random() };
if (!String.prototype.includes) {
String.prototype.includes = function () {
'use strict';
return String.prototype.indexOf.apply(this, arguments) !== -1;
};
};
if (!String.prototype.replaceAt) {
String.prototype.replaceAt = function (index, character) {
return this.substr(0, index) + character + this.substr(index + character.length);
}
};
var setVisibility = function (t, stats) {
if (stats === "hide") {
if (!t.classList.contains("hidden")) {
t.classList.add("hidden");
}
}
else { //show
if (t.classList.contains("hidden")) {
t.classList.remove("hidden");
}
}
};
var showElement = function (e) {
setVisibility(e, "show");
};
var hideElement = function (e) {
setVisibility(e, "hide");
};
var modifyElement = function (t, stats) {
if (stats === "remove") {
if (!t.classList.contains("nodraw")) {
t.classList.add("nodraw");
}
}
else { //show
if (t.classList.contains("nodraw")) {
t.classList.remove("nodraw");
}
}
}
var removeElement = function (e) {
modifyElement(e, "remove");
};
var addElement = function (e) {
modifyElement(e, "add");
};
//門清自摸平和固定20 七對固定25 其他進位至十位數 不滿30以30計
var callAmount = 0;
var lastTileFrom = 0;
var fieldWind = ["東風圈", "南風圈"];
var selfWind = ["東家", "南家", "西家", "北家"];
var winningStyle = ["自摸", "榮和"];
var fieldSeed = 0;
var selfSeed = 0;
var field = "";
var self = "";
var winBy = "";
var takenTiles = [];
var hand = [];
var t;
var shuntsuAmount = 0;
var answer = []; //副底 0 1 2 3 4 特殊
var answerInNumber = 20;
var yakuTile = [];
var winds = "zxcv";
var detailParts = [$("info0"), $("info1"), $("info2"), $("info3"), $("info4"), $("infob"), $("extra"), $("nextQuestion")];
var hideAnswer = function () {
addElement($("chkAns"));
for (var i = 0; i < detailParts.length; i++) {
hideElement(detailParts[i]);
}
};
var showAnswer = function () {
removeElement($("chkAns"));
if ($("fu").valueAsNumber === answerInNumber) addElement($("correct"));
else addElement($("incorrect"));
for (var i = 0; i < detailParts.length; i++) {
showElement(detailParts[i]);
}
};
var tiles = "123456789qwertyuioasdfghjklzxcvbnm";
var rotatedTiles = "!@#$%^&*(QWERTYUIOASDFGHJKLZXCVBNM";
var generateProblem = function () {
hideAnswer();
removeElement($("correct"));
removeElement($("incorrect"));
$('fu').value = 30;
callAmount = f(rnd() * 5);
fieldSeed = f(rnd() * 2);
selfSeed = f(rnd() * 4);
field = fieldWind[fieldSeed];
self = selfWind[selfSeed];
shuntsuAmount = 0;
hand = [];
answer = [];
answerInNumber = 20;
yakuTile = "bnm" + winds[fieldSeed] + winds[selfSeed];
takenTiles = [];
for (var i = 0; i < 34; i++) takenTiles.push(0);
//pair
t = f(rnd() * 34);
takenTiles[t] = 2;
hand.push(tiles[t] + tiles[t]);
//hand
for (var i = 1; i <= 4; i++) {
var type = f(rnd() * 3);
if (type === 0) { //順
t = f(rnd() * 21);
t = f(t / 7) * 9 + t % 7;
while (takenTiles[t] > 3 || takenTiles[t + 1] > 3 || takenTiles[t + 2] > 3) {
t = f(rnd() * 21);
t = f(t / 7) * 9 + t % 7;
}
takenTiles[t]++;
takenTiles[t + 1]++;
takenTiles[t + 2]++;
hand.push(tiles[t] + tiles[t + 1] + tiles[t + 2]);
shuntsuAmount++;
}
else if (type === 1) { // 碰
t = f(rnd() * 34);
while (takenTiles[t] > 1) t = f(rnd() * 34);
takenTiles[t] += 3;
hand.push(tiles[t] + tiles[t] + tiles[t]);
}
else if (type === 2) { // 槓
t = f(rnd() * 34);
while (takenTiles[t] > 0) t = f(rnd() * 34);
takenTiles[t] += 4;
hand.push(tiles[t] + tiles[t] + tiles[t] + tiles[t]);
}
else (console.log("Error: type = " + type));
if (i === 4) {
//把槓全換到最後面去
var ptr = 4;
for (var j = 1; j < ptr; j++) {
if (hand[j].length === 4) {
var tmp = hand[j];
hand[j] = hand[ptr];
hand[ptr] = tmp;
j--;
ptr--;
}
}
}
}
lastTileFrom = f(rnd() * (5 - callAmount));
while (hand[lastTileFrom].length > 3) lastTileFrom = f(rnd() * (5 - callAmount));
lastTile = f(rnd() * hand[lastTileFrom].length);
winBy = winningStyle[f(rnd() * 2)];
if (callAmount === 0 && shuntsuAmount >= 4 && !yakuTile.includes(hand[0][0]) && lastTileFrom > 0 && lastTile != 1) {
//平和
answer = ["副底 +20", "-", "-", "-", "-", "-"];
if (winBy === "榮和") {
answer[0] += "<br>門清榮和 +10";
answer.push("<hr>平和榮和固定30符");
answerInNumber = 30;
}
else {
answer.push("<hr>平和自摸固定20符(不計自摸2符)");
answerInNumber = 20;
}
var i = lastTileFrom;
if (!"19qoal".includes(hand[i][2])) {
hand[i] = "<span class='lastTile'>" + hand[i][0] + "</span>" + hand[i][1] + hand[i][2];
}
else {
hand[i] = hand[i][0] + hand[i][1] + "<span class='lastTile'>" + hand[i][2] + "</span>";
}
}
else {
answer = ["副底 +20", "", "", "", "", ""];
answerInNumber = 20;
if (winBy === "自摸") {
answer[0] += "<br>自摸 +2";
answerInNumber += 2;
}
if (winBy === "榮和" && callAmount === 0) {
answer[0] += "<br>門清榮和 +10";
answerInNumber += 10;
}
if ("bnm".includes(hand[0][0])) {
if (answer[1] != "") answer[1] += "<br>";
answer[1] += "役牌雀頭 +2";
answerInNumber += 2;
}
if (winds[fieldSeed] === hand[0][0]) {
if (answer[1] != "") answer[1] += "<br>";
answer[1] += "場風雀頭 +2";
answerInNumber += 2;
}
if (winds[selfSeed] === hand[0][0]) {
if (answer[1] != "") answer[1] += "<br>";
answer[1] += "自風雀頭 +2";
answerInNumber += 2;
}
if (answer[1] === "") answer[1] += "一般雀頭 +0";
for (var i = 1; i <= 4; i++) {
if (hand[i].length === 4) {
if (answer[i + 1] != "") answer[i + 1] += "<br>";
if ("1qa9olzxcvbnm".includes(hand[i][0])) { //么九
if (i > 4 - callAmount) {
answer[i + 1] += "么九明槓 +16";
var rndNum = f(rnd() * 3);
if (rndNum > 0) rndNum++;
hand[i] = hand[i].replaceAt(rndNum, rotatedTiles[tiles.indexOf(hand[i][rndNum])]);
answerInNumber += 16;
}
else {
answer[i + 1] += "么九暗槓 +32";
hand[i] = "`" + hand[i][1] + hand[i][2] + "`";
answerInNumber += 32;
}
}
else {
if (i > 4 - callAmount) {
answer[i + 1] += "中張明槓 +8";
var rndNum = f(rnd() * 3);
if (rndNum > 0) rndNum++;
hand[i] = hand[i].replaceAt(rndNum, rotatedTiles[tiles.indexOf(hand[i][rndNum])]);
answerInNumber += 8;
}
else {
answer[i + 1] += "中張暗槓 +16";
hand[i] = "`" + hand[i][1] + hand[i][2] + "`";
answerInNumber += 16;
}
}
}
else if (hand[i][0] === hand[i][1]) { //刻
if ("1qa9olzxcvbnm".includes(hand[i][0])) { //么九
if (i > 4 - callAmount) {
answer[i + 1] += "么九明刻 +4";
var rndNum = f(rnd() * 3);
hand[i] = hand[i].replaceAt(rndNum, rotatedTiles[tiles.indexOf(hand[i][rndNum])]);
answerInNumber += 4;
}
else {
answer[i + 1] += "么九暗刻 +8";
answerInNumber += 8;
}
}
else {
if (i > 4 - callAmount) {
answer[i + 1] += "中張明刻 +2";
var rndNum = f(rnd() * 3);
hand[i] = hand[i].replaceAt(rndNum, rotatedTiles[tiles.indexOf(hand[i][rndNum])]);
answerInNumber += 2;
}
else {
answer[i + 1] += "中張暗刻 +4";
answerInNumber += 4;
}
}
}
else {
answer[i + 1] += "順子 +0";
if (i > 4 - callAmount) {
hand[i] = hand[i].replaceAt(0, rotatedTiles[tiles.indexOf(hand[i][0])]);
}
}
}
if (lastTileFrom === 0) {
answer[1] += "<br>聽單騎 +2";
hand[0] = hand[0][0] + "<span class='lastTile'>" + hand[0][1] + "</span>";
answerInNumber += 2;
}
else {
var i = lastTileFrom;
if (hand[i][0] === hand[i][1]) {
if (winBy === "榮和") {
if ("19qoalzxcvbnm".includes(hand[i][0])) {
answerInNumber -= 4; //邊張暗刻->邊張明刻
answer[i + 1] = "么九明刻 +4";
}
else {
answerInNumber -= 2;
answer[i + 1] = "中張明刻 +2";
}
}
answer[i + 1] += "<br>聽雙碰 +0";
hand[i] = hand[i][0] + hand[i][1] + "<span class='lastTile'>" + hand[i][2] + "</span>";
}
else {
var rndNum = f(rnd() * 3);
if (rndNum === 1) {
answer[i + 1] += "<br>聽嵌張 +2";
answerInNumber += 2;
hand[i] = hand[i][0] + "<span class='lastTile'>" + hand[i][1] + "</span>" + hand[i][2];
}
else if (rndNum === 0) {
if ("19qoal".includes(hand[i][2])) {
answer[i + 1] += "<br>聽邊張 +2";
answerInNumber += 2;
}
else answer[i + 1] += "<br>聽兩面 +0";
hand[i] = "<span class='lastTile'>" + hand[i][0] + "</span>" + hand[i][1] + hand[i][2];
}
else { //2
if ("19qoal".includes(hand[i][0])) {
answer[i + 1] += "<br>聽邊張 +2";
answerInNumber += 2;
}
else answer[i + 1] += "<br>聽兩面 +0";
hand[i] = hand[i][0] + hand[i][1] + "<span class='lastTile'>" + hand[i][2] + "</span>";
}
}
}
}
if (answer[6] == undefined) {
answer[6] = "共" + answerInNumber + "符, 進位至十位數計";
answerInNumber = answerInNumber % 10 === 0 ? answerInNumber : f(answerInNumber / 10) * 10 + 10;
answer[6] += answerInNumber + "符";
}
if (callAmount > 0 && shuntsuAmount >= 4 && answerInNumber < 30) {
answer[6] += "<br>非平和情況下, 若進位後仍不足30符, 以30符計算";
answerInNumber = 30;
}
$("hand0").innerHTML = hand[0];
$("hand1").innerHTML = hand[1];
$("hand2").innerHTML = hand[2];
$("hand3").innerHTML = hand[3];
$("hand4").innerHTML = hand[4];
$("fieldWind").innerHTML = field;
$("selfWind").innerHTML = self;
$("winType").innerHTML = " " + winBy + " ";
setAnswer();
};
var setAnswer = function () {
$("infob").innerHTML = answer[0];
$("info0").innerHTML = answer[1];
$("info1").innerHTML = answer[2];
$("info2").innerHTML = answer[3];
$("info3").innerHTML = answer[4];
$("info4").innerHTML = answer[5];
$("extra").innerHTML = answer[6];
};
generateProblem();
</script>
</html>