@konoui/mjimage 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,7 +24,7 @@ export interface HandData {
|
|
|
24
24
|
}
|
|
25
25
|
export declare class Hand {
|
|
26
26
|
private data;
|
|
27
|
-
constructor(input: string);
|
|
27
|
+
constructor(input: string, allowBackBlock?: boolean);
|
|
28
28
|
private init;
|
|
29
29
|
get hands(): Tile[];
|
|
30
30
|
toString(): string;
|
|
@@ -42,7 +42,6 @@ export declare class Hand {
|
|
|
42
42
|
reach(): void;
|
|
43
43
|
call(b: BlockPon | BlockChi | BlockDaiKan): void;
|
|
44
44
|
kan(b: BlockAnKan | BlockShoKan): void;
|
|
45
|
-
get canReach(): boolean;
|
|
46
45
|
clone(): Hand;
|
|
47
46
|
}
|
|
48
47
|
export declare class ShantenCalculator {
|
|
@@ -52,19 +51,11 @@ export declare class ShantenCalculator {
|
|
|
52
51
|
sevenPairs(): number;
|
|
53
52
|
thirteenOrphans(): number;
|
|
54
53
|
fourSetsOnePair(): number;
|
|
55
|
-
private
|
|
54
|
+
private commonByType;
|
|
56
55
|
private groupRemainingTiles;
|
|
57
56
|
private calcCommon;
|
|
58
57
|
}
|
|
59
|
-
export declare class
|
|
60
|
-
h: Hand;
|
|
61
|
-
private c;
|
|
62
|
-
constructor(h: Hand);
|
|
63
|
-
menzen(): number;
|
|
64
|
-
yakuhai(): number;
|
|
65
|
-
tanyao(): void;
|
|
66
|
-
}
|
|
67
|
-
export declare class TileCalculator {
|
|
58
|
+
export declare class BlockCalculator {
|
|
68
59
|
hand: Hand;
|
|
69
60
|
constructor(hand: Hand);
|
|
70
61
|
calc(lastTile: Tile): Block[][];
|
|
@@ -74,7 +65,7 @@ export declare class TileCalculator {
|
|
|
74
65
|
nineGates(): Block[][];
|
|
75
66
|
fourSetsOnePair(): Block[][];
|
|
76
67
|
private commonAll;
|
|
77
|
-
private
|
|
68
|
+
private commonByType;
|
|
78
69
|
}
|
|
79
70
|
export interface BoardParams {
|
|
80
71
|
doraMarkers: Tile[];
|
|
@@ -12,13 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.DoubleCalculator = exports.
|
|
15
|
+
exports.DoubleCalculator = exports.BlockCalculator = exports.ShantenCalculator = exports.Hand = void 0;
|
|
16
16
|
var assert_1 = __importDefault(require("assert"));
|
|
17
17
|
var constants_1 = require("../constants");
|
|
18
18
|
var parser_1 = require("../parser");
|
|
19
19
|
var Hand = (function () {
|
|
20
|
-
function Hand(input) {
|
|
20
|
+
function Hand(input, allowBackBlock) {
|
|
21
21
|
var _a;
|
|
22
|
+
if (allowBackBlock === void 0) { allowBackBlock = false; }
|
|
22
23
|
this.data = (_a = {},
|
|
23
24
|
_a[constants_1.TYPE.M] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
24
25
|
_a[constants_1.TYPE.P] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
@@ -29,9 +30,9 @@ var Hand = (function () {
|
|
|
29
30
|
_a.reached = false,
|
|
30
31
|
_a.tsumo = null,
|
|
31
32
|
_a);
|
|
32
|
-
this.init(input);
|
|
33
|
+
this.init(input, allowBackBlock);
|
|
33
34
|
}
|
|
34
|
-
Hand.prototype.init = function (input) {
|
|
35
|
+
Hand.prototype.init = function (input, allowBackBlock) {
|
|
35
36
|
var blocks = new parser_1.Parser(input).parse();
|
|
36
37
|
for (var _i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) {
|
|
37
38
|
var b = blocks_1[_i];
|
|
@@ -53,6 +54,10 @@ var Hand = (function () {
|
|
|
53
54
|
this.inc(b.tiles);
|
|
54
55
|
continue;
|
|
55
56
|
}
|
|
57
|
+
if (allowBackBlock) {
|
|
58
|
+
this.inc(b.tiles);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
56
61
|
throw new Error("unexpected block ".concat(b.type, " ").concat(b.toString()));
|
|
57
62
|
}
|
|
58
63
|
};
|
|
@@ -114,7 +119,7 @@ var Hand = (function () {
|
|
|
114
119
|
});
|
|
115
120
|
Object.defineProperty(Hand.prototype, "menzen", {
|
|
116
121
|
get: function () {
|
|
117
|
-
return this.called.some(function (v) { return !(v instanceof parser_1.BlockAnKan); });
|
|
122
|
+
return !this.called.some(function (v) { return !(v instanceof parser_1.BlockAnKan); });
|
|
118
123
|
},
|
|
119
124
|
enumerable: false,
|
|
120
125
|
configurable: true
|
|
@@ -198,7 +203,7 @@ var Hand = (function () {
|
|
|
198
203
|
return;
|
|
199
204
|
};
|
|
200
205
|
Hand.prototype.reach = function () {
|
|
201
|
-
if (!this.
|
|
206
|
+
if (!this.menzen)
|
|
202
207
|
throw new Error("cannot reach");
|
|
203
208
|
if (this.data.reached)
|
|
204
209
|
throw new Error("already reached");
|
|
@@ -241,13 +246,6 @@ var Hand = (function () {
|
|
|
241
246
|
}
|
|
242
247
|
throw new Error("unexpected input ".concat(b));
|
|
243
248
|
};
|
|
244
|
-
Object.defineProperty(Hand.prototype, "canReach", {
|
|
245
|
-
get: function () {
|
|
246
|
-
return this.called.filter(function (b) { return !(b instanceof parser_1.BlockAnKan); }).length == 0;
|
|
247
|
-
},
|
|
248
|
-
enumerable: false,
|
|
249
|
-
configurable: true
|
|
250
|
-
});
|
|
251
249
|
Hand.prototype.clone = function () {
|
|
252
250
|
var c = new Hand(this.toString());
|
|
253
251
|
c.data.called = this.called.map(function (b) { return b.clone(); });
|
|
@@ -309,19 +307,27 @@ var ShantenCalculator = (function () {
|
|
|
309
307
|
var _this = this;
|
|
310
308
|
var calc = function (hasPair) {
|
|
311
309
|
var z = [0, 0, 0];
|
|
312
|
-
var
|
|
313
|
-
for (var n = 1; n < _this.hand.getArrayLen(
|
|
314
|
-
if (_this.hand.get(
|
|
310
|
+
var zt = constants_1.TYPE.Z;
|
|
311
|
+
for (var n = 1; n < _this.hand.getArrayLen(zt); n++) {
|
|
312
|
+
if (_this.hand.get(zt, n) >= 3)
|
|
315
313
|
z[0]++;
|
|
316
|
-
else if (_this.hand.get(
|
|
314
|
+
else if (_this.hand.get(zt, n) == 2)
|
|
317
315
|
z[1]++;
|
|
318
|
-
else if (_this.hand.get(
|
|
316
|
+
else if (_this.hand.get(zt, n) == 1)
|
|
319
317
|
z[2]++;
|
|
320
318
|
}
|
|
319
|
+
var b = [0, 0, 0];
|
|
320
|
+
var bn = _this.hand.get(constants_1.TYPE.BACK, 0);
|
|
321
|
+
var bb = bn % 3;
|
|
322
|
+
b[0] = bn / 3;
|
|
323
|
+
if (bb == 2)
|
|
324
|
+
b[1] = 1;
|
|
325
|
+
if (bb == 1)
|
|
326
|
+
b[2] = 1;
|
|
321
327
|
var min = 13;
|
|
322
|
-
var mr = _this.
|
|
323
|
-
var pr = _this.
|
|
324
|
-
var sr = _this.
|
|
328
|
+
var mr = _this.commonByType(constants_1.TYPE.M);
|
|
329
|
+
var pr = _this.commonByType(constants_1.TYPE.P);
|
|
330
|
+
var sr = _this.commonByType(constants_1.TYPE.S);
|
|
325
331
|
for (var _i = 0, _a = [mr.patternA, mr.patternB]; _i < _a.length; _i++) {
|
|
326
332
|
var m = _a[_i];
|
|
327
333
|
for (var _b = 0, _c = [pr.patternA, pr.patternB]; _b < _c.length; _b++) {
|
|
@@ -330,7 +336,7 @@ var ShantenCalculator = (function () {
|
|
|
330
336
|
var s = _e[_d];
|
|
331
337
|
var v = [_this.hand.called.length, 0, 0];
|
|
332
338
|
for (var i = 0; i < 3; i++) {
|
|
333
|
-
v[i] += m[i] + p[i] + s[i] + z[i];
|
|
339
|
+
v[i] += m[i] + p[i] + s[i] + z[i] + b[i];
|
|
334
340
|
}
|
|
335
341
|
var r = _this.calcCommon(v[0], v[1], v[2], hasPair);
|
|
336
342
|
if (r < min) {
|
|
@@ -357,11 +363,11 @@ var ShantenCalculator = (function () {
|
|
|
357
363
|
}
|
|
358
364
|
return min;
|
|
359
365
|
};
|
|
360
|
-
ShantenCalculator.prototype.
|
|
366
|
+
ShantenCalculator.prototype.commonByType = function (k, n) {
|
|
361
367
|
if (n === void 0) { n = 1; }
|
|
362
368
|
if (n > 9)
|
|
363
369
|
return this.groupRemainingTiles(k);
|
|
364
|
-
var max = this.
|
|
370
|
+
var max = this.commonByType(k, n + 1);
|
|
365
371
|
if (n <= 7 &&
|
|
366
372
|
this.hand.get(k, n) > 0 &&
|
|
367
373
|
this.hand.get(k, n + 1) > 0 &&
|
|
@@ -371,7 +377,7 @@ var ShantenCalculator = (function () {
|
|
|
371
377
|
new parser_1.Tile(k, n + 1),
|
|
372
378
|
new parser_1.Tile(k, n + 2),
|
|
373
379
|
]);
|
|
374
|
-
var r = this.
|
|
380
|
+
var r = this.commonByType(k, n);
|
|
375
381
|
this.hand.inc(tiles);
|
|
376
382
|
r.patternA[0]++, r.patternB[0]++;
|
|
377
383
|
if (r.patternA[2] < max.patternA[2] ||
|
|
@@ -389,7 +395,7 @@ var ShantenCalculator = (function () {
|
|
|
389
395
|
new parser_1.Tile(k, n),
|
|
390
396
|
new parser_1.Tile(k, n),
|
|
391
397
|
]);
|
|
392
|
-
var r = this.
|
|
398
|
+
var r = this.commonByType(k, n);
|
|
393
399
|
this.hand.inc(tiles);
|
|
394
400
|
r.patternA[0]++, r.patternB[0]++;
|
|
395
401
|
if (r.patternA[2] < max.patternA[2] ||
|
|
@@ -444,55 +450,16 @@ var ShantenCalculator = (function () {
|
|
|
444
450
|
return ShantenCalculator;
|
|
445
451
|
}());
|
|
446
452
|
exports.ShantenCalculator = ShantenCalculator;
|
|
447
|
-
var
|
|
448
|
-
function
|
|
449
|
-
this.h = h;
|
|
450
|
-
this.c = new ShantenCalculator(h);
|
|
451
|
-
}
|
|
452
|
-
ExShantenCalculator.prototype.menzen = function () {
|
|
453
|
-
return this.h.menzen ? this.c.calc() : Number.POSITIVE_INFINITY;
|
|
454
|
-
};
|
|
455
|
-
ExShantenCalculator.prototype.yakuhai = function () {
|
|
456
|
-
var three = 0;
|
|
457
|
-
var vPon = null;
|
|
458
|
-
for (var _i = 0, _a = [1, 2, 3, 4, 5, 6, 7]; _i < _a.length; _i++) {
|
|
459
|
-
var n = _a[_i];
|
|
460
|
-
if (this.h.get(constants_1.TYPE.Z, n) >= 3)
|
|
461
|
-
three++;
|
|
462
|
-
else if (this.h.get(constants_1.TYPE.Z, n) == 2) {
|
|
463
|
-
var t = new parser_1.Tile(constants_1.TYPE.Z, n);
|
|
464
|
-
vPon = new parser_1.BlockPon([t, t.clone(), t.clone()]);
|
|
465
|
-
}
|
|
466
|
-
else
|
|
467
|
-
for (var _b = 0, _c = this.h.called; _b < _c.length; _b++) {
|
|
468
|
-
var b = _c[_b];
|
|
469
|
-
if (b.tiles[0].t == constants_1.TYPE.Z && b.tiles[0].n == n)
|
|
470
|
-
three++;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if (three > 0)
|
|
474
|
-
return this.c.calc();
|
|
475
|
-
if (vPon) {
|
|
476
|
-
var cloned = this.h.clone();
|
|
477
|
-
cloned.call(vPon);
|
|
478
|
-
return new ShantenCalculator(cloned).calc() + 1;
|
|
479
|
-
}
|
|
480
|
-
return Number.POSITIVE_INFINITY;
|
|
481
|
-
};
|
|
482
|
-
ExShantenCalculator.prototype.tanyao = function () { };
|
|
483
|
-
return ExShantenCalculator;
|
|
484
|
-
}());
|
|
485
|
-
exports.ExShantenCalculator = ExShantenCalculator;
|
|
486
|
-
var TileCalculator = (function () {
|
|
487
|
-
function TileCalculator(hand) {
|
|
453
|
+
var BlockCalculator = (function () {
|
|
454
|
+
function BlockCalculator(hand) {
|
|
488
455
|
this.hand = hand;
|
|
489
456
|
}
|
|
490
|
-
|
|
457
|
+
BlockCalculator.prototype.calc = function (lastTile) {
|
|
491
458
|
if (this.hand.drawn != null)
|
|
492
459
|
lastTile = this.hand.drawn;
|
|
493
460
|
return this.markDrawn(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], this.sevenPairs(), true), this.thirteenOrphans(), true), this.nineGates(), true), this.fourSetsOnePair(), true), lastTile);
|
|
494
461
|
};
|
|
495
|
-
|
|
462
|
+
BlockCalculator.prototype.markDrawn = function (hands, lastTile) {
|
|
496
463
|
if (hands.length == 0)
|
|
497
464
|
return [];
|
|
498
465
|
var op = this.hand.drawn != null
|
|
@@ -530,7 +497,7 @@ var TileCalculator = (function () {
|
|
|
530
497
|
}
|
|
531
498
|
return newHands;
|
|
532
499
|
};
|
|
533
|
-
|
|
500
|
+
BlockCalculator.prototype.sevenPairs = function () {
|
|
534
501
|
if (this.hand.called.length > 0)
|
|
535
502
|
return [];
|
|
536
503
|
var ret = [];
|
|
@@ -550,7 +517,7 @@ var TileCalculator = (function () {
|
|
|
550
517
|
}
|
|
551
518
|
return [ret];
|
|
552
519
|
};
|
|
553
|
-
|
|
520
|
+
BlockCalculator.prototype.thirteenOrphans = function () {
|
|
554
521
|
var ret = [];
|
|
555
522
|
var pairs = "";
|
|
556
523
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
@@ -570,7 +537,7 @@ var TileCalculator = (function () {
|
|
|
570
537
|
}
|
|
571
538
|
return [ret];
|
|
572
539
|
};
|
|
573
|
-
|
|
540
|
+
BlockCalculator.prototype.nineGates = function () {
|
|
574
541
|
var _this = this;
|
|
575
542
|
var cond = function (k, n, want) {
|
|
576
543
|
return want.includes(_this.hand.get(k, n));
|
|
@@ -597,12 +564,10 @@ var TileCalculator = (function () {
|
|
|
597
564
|
}
|
|
598
565
|
return [];
|
|
599
566
|
};
|
|
600
|
-
|
|
567
|
+
BlockCalculator.prototype.fourSetsOnePair = function () {
|
|
601
568
|
var ret = [];
|
|
602
569
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
603
570
|
var k = _a[_i];
|
|
604
|
-
if (k == constants_1.TYPE.BACK)
|
|
605
|
-
continue;
|
|
606
571
|
var _loop_1 = function (n) {
|
|
607
572
|
if (this_1.hand.get(k, n) >= 2) {
|
|
608
573
|
var tiles_3 = this_1.hand.dec([new parser_1.Tile(k, n), new parser_1.Tile(k, n)]);
|
|
@@ -623,25 +588,37 @@ var TileCalculator = (function () {
|
|
|
623
588
|
}
|
|
624
589
|
return ret;
|
|
625
590
|
};
|
|
626
|
-
|
|
591
|
+
BlockCalculator.prototype.commonAll = function () {
|
|
627
592
|
var _this = this;
|
|
628
593
|
var handleZ = function () {
|
|
629
594
|
var z = [];
|
|
630
|
-
var
|
|
631
|
-
for (var n = 1; n < _this.hand.getArrayLen(
|
|
632
|
-
if (_this.hand.get(
|
|
595
|
+
var zt = constants_1.TYPE.Z;
|
|
596
|
+
for (var n = 1; n < _this.hand.getArrayLen(zt); n++) {
|
|
597
|
+
if (_this.hand.get(zt, n) == 0)
|
|
633
598
|
continue;
|
|
634
|
-
else if (_this.hand.get(
|
|
599
|
+
else if (_this.hand.get(zt, n) != 3)
|
|
635
600
|
return [];
|
|
636
|
-
z.push(new parser_1.BlockThree([new parser_1.Tile(
|
|
601
|
+
z.push(new parser_1.BlockThree([new parser_1.Tile(zt, n), new parser_1.Tile(zt, n), new parser_1.Tile(zt, n)]));
|
|
637
602
|
}
|
|
638
603
|
return z.length == 0 ? [] : [z];
|
|
639
604
|
};
|
|
605
|
+
var handleBack = function () {
|
|
606
|
+
var b = [];
|
|
607
|
+
var bt = constants_1.TYPE.BACK;
|
|
608
|
+
var sum = _this.hand.get(bt, 0);
|
|
609
|
+
Array(sum / 3)
|
|
610
|
+
.fill(undefined)
|
|
611
|
+
.map(function (_) {
|
|
612
|
+
b.push(new parser_1.BlockThree([new parser_1.Tile(bt, 0), new parser_1.Tile(bt, 0), new parser_1.Tile(bt, 0)]));
|
|
613
|
+
});
|
|
614
|
+
return b.length == 0 ? [] : [b];
|
|
615
|
+
};
|
|
640
616
|
var vvv = [
|
|
641
|
-
this.
|
|
642
|
-
this.
|
|
643
|
-
this.
|
|
617
|
+
this.commonByType(constants_1.TYPE.M),
|
|
618
|
+
this.commonByType(constants_1.TYPE.P),
|
|
619
|
+
this.commonByType(constants_1.TYPE.S),
|
|
644
620
|
handleZ(),
|
|
621
|
+
handleBack(),
|
|
645
622
|
[this.hand.called],
|
|
646
623
|
].sort(function (a, b) { return b.length - a.length; });
|
|
647
624
|
var ret = vvv[0].concat();
|
|
@@ -655,23 +632,23 @@ var TileCalculator = (function () {
|
|
|
655
632
|
}
|
|
656
633
|
return ret;
|
|
657
634
|
};
|
|
658
|
-
|
|
635
|
+
BlockCalculator.prototype.commonByType = function (t, n) {
|
|
659
636
|
if (n === void 0) { n = 1; }
|
|
660
637
|
if (n > 9)
|
|
661
638
|
return [];
|
|
662
|
-
if (this.hand.get(
|
|
663
|
-
return this.
|
|
639
|
+
if (this.hand.get(t, n) == 0)
|
|
640
|
+
return this.commonByType(t, n + 1);
|
|
664
641
|
var ret = [];
|
|
665
642
|
if (n <= 7 &&
|
|
666
|
-
this.hand.get(
|
|
667
|
-
this.hand.get(
|
|
668
|
-
this.hand.get(
|
|
643
|
+
this.hand.get(t, n) > 0 &&
|
|
644
|
+
this.hand.get(t, n + 1) > 0 &&
|
|
645
|
+
this.hand.get(t, n + 2) > 0) {
|
|
669
646
|
var tiles = this.hand.dec([
|
|
670
|
-
new parser_1.Tile(
|
|
671
|
-
new parser_1.Tile(
|
|
672
|
-
new parser_1.Tile(
|
|
647
|
+
new parser_1.Tile(t, n),
|
|
648
|
+
new parser_1.Tile(t, n + 1),
|
|
649
|
+
new parser_1.Tile(t, n + 2),
|
|
673
650
|
]);
|
|
674
|
-
var nested = this.
|
|
651
|
+
var nested = this.commonByType(t, n);
|
|
675
652
|
this.hand.inc(tiles);
|
|
676
653
|
if (nested.length == 0)
|
|
677
654
|
nested.push([]);
|
|
@@ -681,13 +658,13 @@ var TileCalculator = (function () {
|
|
|
681
658
|
ret.push(arr);
|
|
682
659
|
}
|
|
683
660
|
}
|
|
684
|
-
if (this.hand.get(
|
|
661
|
+
if (this.hand.get(t, n) == 3) {
|
|
685
662
|
var tiles = this.hand.dec([
|
|
686
|
-
new parser_1.Tile(
|
|
687
|
-
new parser_1.Tile(
|
|
688
|
-
new parser_1.Tile(
|
|
663
|
+
new parser_1.Tile(t, n),
|
|
664
|
+
new parser_1.Tile(t, n),
|
|
665
|
+
new parser_1.Tile(t, n),
|
|
689
666
|
]);
|
|
690
|
-
var nested = this.
|
|
667
|
+
var nested = this.commonByType(t, n);
|
|
691
668
|
this.hand.inc(tiles);
|
|
692
669
|
if (nested.length == 0)
|
|
693
670
|
nested.push([]);
|
|
@@ -699,9 +676,9 @@ var TileCalculator = (function () {
|
|
|
699
676
|
}
|
|
700
677
|
return ret;
|
|
701
678
|
};
|
|
702
|
-
return
|
|
679
|
+
return BlockCalculator;
|
|
703
680
|
}());
|
|
704
|
-
exports.
|
|
681
|
+
exports.BlockCalculator = BlockCalculator;
|
|
705
682
|
var DoubleCalculator = (function () {
|
|
706
683
|
function DoubleCalculator(hand, params) {
|
|
707
684
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -863,7 +840,7 @@ var DoubleCalculator = (function () {
|
|
|
863
840
|
return ret;
|
|
864
841
|
};
|
|
865
842
|
DoubleCalculator.prototype.minus = function () {
|
|
866
|
-
return this.hand.
|
|
843
|
+
return this.hand.menzen ? 0 : 1;
|
|
867
844
|
};
|
|
868
845
|
DoubleCalculator.prototype.dA1 = function (h) {
|
|
869
846
|
if (this.cfg.reached == 1)
|
|
@@ -914,13 +891,13 @@ var DoubleCalculator = (function () {
|
|
|
914
891
|
if (tile.t == constants_1.TYPE.Z) {
|
|
915
892
|
if (tile.equals(_this.cfg.myWind))
|
|
916
893
|
ret.push({ name: "自風", double: 1 });
|
|
917
|
-
if (tile.equals(_this.cfg.roundWind))
|
|
894
|
+
else if (tile.equals(_this.cfg.roundWind))
|
|
918
895
|
ret.push({ name: "場風", double: 1 });
|
|
919
|
-
if (tile.n == 5)
|
|
896
|
+
else if (tile.n == 5)
|
|
920
897
|
ret.push({ name: "白", double: 1 });
|
|
921
|
-
if (tile.n == 6)
|
|
898
|
+
else if (tile.n == 6)
|
|
922
899
|
ret.push({ name: "發", double: 1 });
|
|
923
|
-
if (tile.n == 7)
|
|
900
|
+
else if (tile.n == 7)
|
|
924
901
|
ret.push({ name: "中", double: 1 });
|
|
925
902
|
}
|
|
926
903
|
});
|
|
@@ -985,13 +962,13 @@ var DoubleCalculator = (function () {
|
|
|
985
962
|
var tile = block.minTile();
|
|
986
963
|
if (tile.t == constants_1.TYPE.Z)
|
|
987
964
|
return "continue";
|
|
988
|
-
var
|
|
965
|
+
var filteredTypes = [constants_1.TYPE.M, constants_1.TYPE.P, constants_1.TYPE.S].filter(function (v) { return v != tile.t; });
|
|
989
966
|
var cond1 = h.some(function (b) {
|
|
990
|
-
var newTile = new parser_1.Tile(
|
|
967
|
+
var newTile = new parser_1.Tile(filteredTypes[0], tile.n);
|
|
991
968
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
992
969
|
});
|
|
993
970
|
var cond2 = h.some(function (b) {
|
|
994
|
-
var newTile = new parser_1.Tile(
|
|
971
|
+
var newTile = new parser_1.Tile(filteredTypes[1], tile.n);
|
|
995
972
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
996
973
|
});
|
|
997
974
|
if (cond1 && cond2)
|
|
@@ -1050,13 +1027,13 @@ var DoubleCalculator = (function () {
|
|
|
1050
1027
|
var tile = block.minTile();
|
|
1051
1028
|
if (tile.t == constants_1.TYPE.Z)
|
|
1052
1029
|
return "continue";
|
|
1053
|
-
var
|
|
1030
|
+
var filteredTypes = [constants_1.TYPE.M, constants_1.TYPE.P, constants_1.TYPE.S].filter(function (v) { return v != tile.t; });
|
|
1054
1031
|
var cond1 = h.some(function (b) {
|
|
1055
|
-
var newTile = new parser_1.Tile(
|
|
1032
|
+
var newTile = new parser_1.Tile(filteredTypes[0], tile.n);
|
|
1056
1033
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
1057
1034
|
});
|
|
1058
1035
|
var cond2 = h.some(function (b) {
|
|
1059
|
-
var newTile = new parser_1.Tile(
|
|
1036
|
+
var newTile = new parser_1.Tile(filteredTypes[1], tile.n);
|
|
1060
1037
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
1061
1038
|
});
|
|
1062
1039
|
if (cond1 && cond2)
|
|
@@ -1085,7 +1062,9 @@ var DoubleCalculator = (function () {
|
|
|
1085
1062
|
return cond ? [{ name: "混老頭", double: 2 }] : [];
|
|
1086
1063
|
};
|
|
1087
1064
|
DoubleCalculator.prototype.dI2 = function (h) {
|
|
1088
|
-
if (
|
|
1065
|
+
if (h.length == 7)
|
|
1066
|
+
return [];
|
|
1067
|
+
if (!h.some(function (b) { return b instanceof parser_1.BlockRun || b instanceof parser_1.BlockChi; }))
|
|
1089
1068
|
return [];
|
|
1090
1069
|
if (!h.some(function (b) { return b.tiles[0].t == constants_1.TYPE.Z; }))
|
|
1091
1070
|
return [];
|
|
@@ -1146,13 +1125,14 @@ var DoubleCalculator = (function () {
|
|
|
1146
1125
|
return [];
|
|
1147
1126
|
};
|
|
1148
1127
|
DoubleCalculator.prototype.dB3 = function (h) {
|
|
1149
|
-
if (
|
|
1128
|
+
if (h.length == 7)
|
|
1129
|
+
return [];
|
|
1130
|
+
if (!h.some(function (b) { return b instanceof parser_1.BlockRun || b instanceof parser_1.BlockChi; }))
|
|
1150
1131
|
return [];
|
|
1151
1132
|
if (h.some(function (b) { return b.tiles[0].t == constants_1.TYPE.Z; }))
|
|
1152
1133
|
return [];
|
|
1153
1134
|
var cond = h.every(function (b) {
|
|
1154
|
-
|
|
1155
|
-
return b.tiles.some(function (t) { return values.includes(t.n); });
|
|
1135
|
+
return b.tiles.some(function (t) { return [1, 9].includes(t.n); });
|
|
1156
1136
|
});
|
|
1157
1137
|
return cond ? [{ name: "純全帯么九色", double: 3 - this.minus() }] : [];
|
|
1158
1138
|
};
|
|
@@ -340,7 +340,7 @@ var Controller = (function () {
|
|
|
340
340
|
env.replacementWin = params === null || params === void 0 ? void 0 : params.replacementWin;
|
|
341
341
|
}
|
|
342
342
|
env.oneShotWin = params === null || params === void 0 ? void 0 : params.oneShot;
|
|
343
|
-
var tc = new calculator_1.
|
|
343
|
+
var tc = new calculator_1.BlockCalculator(hand);
|
|
344
344
|
var dc = new calculator_1.DoubleCalculator(hand, env);
|
|
345
345
|
var hands = tc.calc(t);
|
|
346
346
|
var ret = dc.calc(hands);
|
|
@@ -479,7 +479,7 @@ var Controller = (function () {
|
|
|
479
479
|
var hand = this.hand(w);
|
|
480
480
|
if (hand.reached)
|
|
481
481
|
return false;
|
|
482
|
-
if (!hand.
|
|
482
|
+
if (!hand.menzen)
|
|
483
483
|
return false;
|
|
484
484
|
var s = new calculator_1.ShantenCalculator(hand).calc();
|
|
485
485
|
if (s > 0)
|
|
@@ -41,6 +41,7 @@ var Efficiency = (function () {
|
|
|
41
41
|
Efficiency.candidateTiles = function (hand) {
|
|
42
42
|
var r = Number.POSITIVE_INFINITY;
|
|
43
43
|
var candidates = [];
|
|
44
|
+
var sc = new calculator_1.ShantenCalculator(hand);
|
|
44
45
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
45
46
|
var k = _a[_i];
|
|
46
47
|
if (k == constants_1.TYPE.BACK)
|
|
@@ -50,7 +51,7 @@ var Efficiency = (function () {
|
|
|
50
51
|
continue;
|
|
51
52
|
var t = new parser_1.Tile(k, n);
|
|
52
53
|
var tiles = hand.inc([t]);
|
|
53
|
-
var s =
|
|
54
|
+
var s = sc.calc();
|
|
54
55
|
hand.dec(tiles);
|
|
55
56
|
if (s < r) {
|
|
56
57
|
r = s;
|
|
@@ -179,7 +180,7 @@ var RiskRank = (function () {
|
|
|
179
180
|
};
|
|
180
181
|
RiskRank.rankZ = function (c, targetUser, t) {
|
|
181
182
|
if (t.t != constants_1.TYPE.Z)
|
|
182
|
-
throw new Error("expected
|
|
183
|
+
throw new Error("expected TYPE.Z but ".concat(t.toString()));
|
|
183
184
|
if (c.isSafeTile(t.t, t.n, targetUser))
|
|
184
185
|
return 0;
|
|
185
186
|
var remaining = c.get(t);
|
|
@@ -187,7 +188,7 @@ var RiskRank = (function () {
|
|
|
187
188
|
};
|
|
188
189
|
RiskRank.rankN = function (c, targetUser, t) {
|
|
189
190
|
if (!t.isNum())
|
|
190
|
-
throw new Error("expected
|
|
191
|
+
throw new Error("expected TYPE.NUMBER but ".concat(t.toString()));
|
|
191
192
|
var n = t.n;
|
|
192
193
|
var type = t.t;
|
|
193
194
|
if (c.isSafeTile(type, n, targetUser))
|
package/dist/mjs/lib/parser.js
CHANGED
|
@@ -123,6 +123,8 @@ var Block = (function () {
|
|
|
123
123
|
}, [true, this.tiles[0]]), sameAll = _a[0], _ = _a[1];
|
|
124
124
|
var ret = "";
|
|
125
125
|
if (sameAll) {
|
|
126
|
+
if (this.tiles[0].t == constants_1.TYPE.BACK)
|
|
127
|
+
return this.tiles.join("");
|
|
126
128
|
for (var _i = 0, _b = this.tiles; _i < _b.length; _i++) {
|
|
127
129
|
var v = _b[_i];
|
|
128
130
|
ret += v.toString().slice(0, -1);
|