@konoui/mjimage 0.0.8 → 0.0.11
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.
- package/dist/mjs/lib/calculator/index.d.ts +7 -16
- package/dist/mjs/lib/calculator/index.js +128 -128
- package/dist/mjs/lib/controller/controller.js +2 -2
- package/dist/mjs/lib/controller/efficiency.d.ts +4 -0
- package/dist/mjs/lib/controller/efficiency.js +11 -3
- package/dist/mjs/lib/parser.js +3 -1
- package/package.json +1 -1
|
@@ -17,14 +17,14 @@ export interface HandData {
|
|
|
17
17
|
[TYPE.S]: FixedNumber;
|
|
18
18
|
[TYPE.P]: FixedNumber;
|
|
19
19
|
[TYPE.Z]: [number, number, number, number, number, number, number, number];
|
|
20
|
-
[TYPE.BACK]: [number];
|
|
20
|
+
[TYPE.BACK]: [string, number];
|
|
21
21
|
called: (BlockChi | BlockPon | BlockAnKan | BlockDaiKan | BlockShoKan)[];
|
|
22
22
|
tsumo: Tile | null;
|
|
23
23
|
reached: boolean;
|
|
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;
|
|
@@ -32,9 +32,9 @@ export declare class Hand {
|
|
|
32
32
|
get reached(): boolean;
|
|
33
33
|
get drawn(): Tile | null;
|
|
34
34
|
get menzen(): boolean;
|
|
35
|
-
getArrayLen(k: Type):
|
|
35
|
+
getArrayLen(k: Type): 2 | 8 | 10;
|
|
36
36
|
sum(k: Type): number;
|
|
37
|
-
get(
|
|
37
|
+
get(t: Type, n: number): number;
|
|
38
38
|
inc(tiles: Tile[]): Tile[];
|
|
39
39
|
dec(tiles: Tile[]): Tile[];
|
|
40
40
|
draw(t: Tile): void;
|
|
@@ -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,26 +12,27 @@ 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],
|
|
25
26
|
_a[constants_1.TYPE.S] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
26
27
|
_a[constants_1.TYPE.Z] = [0, 0, 0, 0, 0, 0, 0, 0],
|
|
27
|
-
_a[constants_1.TYPE.BACK] = [0],
|
|
28
|
+
_a[constants_1.TYPE.BACK] = ["untouchable", 0],
|
|
28
29
|
_a.called = [],
|
|
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
|
+
else 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
|
};
|
|
@@ -61,10 +66,12 @@ var Hand = (function () {
|
|
|
61
66
|
var tiles = [];
|
|
62
67
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
63
68
|
var k = _a[_i];
|
|
64
|
-
for (var n =
|
|
69
|
+
for (var n = 1; n < this.getArrayLen(k); n++) {
|
|
65
70
|
var count = this.get(k, n);
|
|
66
|
-
if (k != constants_1.TYPE.Z && n == 5)
|
|
71
|
+
if (k != constants_1.TYPE.Z && n == 5 && this.get(k, 0) > 0) {
|
|
67
72
|
count -= this.get(k, 0);
|
|
73
|
+
tiles.push(new parser_1.Tile(k, 0));
|
|
74
|
+
}
|
|
68
75
|
for (var i = 0; i < count; i++) {
|
|
69
76
|
tiles.push(new parser_1.Tile(k, n));
|
|
70
77
|
}
|
|
@@ -114,7 +121,7 @@ var Hand = (function () {
|
|
|
114
121
|
});
|
|
115
122
|
Object.defineProperty(Hand.prototype, "menzen", {
|
|
116
123
|
get: function () {
|
|
117
|
-
return this.called.some(function (v) { return !(v instanceof parser_1.BlockAnKan); });
|
|
124
|
+
return !this.called.some(function (v) { return !(v instanceof parser_1.BlockAnKan); });
|
|
118
125
|
},
|
|
119
126
|
enumerable: false,
|
|
120
127
|
configurable: true
|
|
@@ -128,8 +135,10 @@ var Hand = (function () {
|
|
|
128
135
|
sum += this.get(k, n);
|
|
129
136
|
return sum;
|
|
130
137
|
};
|
|
131
|
-
Hand.prototype.get = function (
|
|
132
|
-
|
|
138
|
+
Hand.prototype.get = function (t, n) {
|
|
139
|
+
if (t == constants_1.TYPE.BACK)
|
|
140
|
+
return this.data[t][1];
|
|
141
|
+
return this.data[t][n];
|
|
133
142
|
};
|
|
134
143
|
Hand.prototype.inc = function (tiles) {
|
|
135
144
|
var backup = [];
|
|
@@ -143,7 +152,10 @@ var Hand = (function () {
|
|
|
143
152
|
if (!(t.t == constants_1.TYPE.Z || t.t == constants_1.TYPE.BACK) && t.n == 0) {
|
|
144
153
|
this.data[t.t][5] += 1;
|
|
145
154
|
}
|
|
146
|
-
|
|
155
|
+
if (t.t == constants_1.TYPE.BACK)
|
|
156
|
+
this.data[t.t][1] += 1;
|
|
157
|
+
else
|
|
158
|
+
this.data[t.t][t.n] += 1;
|
|
147
159
|
if (t.t != constants_1.TYPE.Z &&
|
|
148
160
|
t.n == 5 &&
|
|
149
161
|
this.get(t.t, 5) == 4 &&
|
|
@@ -159,7 +171,7 @@ var Hand = (function () {
|
|
|
159
171
|
Hand.prototype.dec = function (tiles) {
|
|
160
172
|
if (this.hands.every(function (t) { return t.t == constants_1.TYPE.BACK; })) {
|
|
161
173
|
var toRemove = tiles.map(function (v) { return new parser_1.Tile(constants_1.TYPE.BACK, 0); });
|
|
162
|
-
this.data[constants_1.TYPE.BACK][
|
|
174
|
+
this.data[constants_1.TYPE.BACK][1] -= tiles.length;
|
|
163
175
|
return toRemove;
|
|
164
176
|
}
|
|
165
177
|
var backup = [];
|
|
@@ -173,7 +185,10 @@ var Hand = (function () {
|
|
|
173
185
|
if (!(t.t == constants_1.TYPE.Z || t.t == constants_1.TYPE.BACK) && t.n == 0) {
|
|
174
186
|
this.data[t.t][5] -= 1;
|
|
175
187
|
}
|
|
176
|
-
|
|
188
|
+
if (t.t == constants_1.TYPE.BACK)
|
|
189
|
+
this.data[t.t][1] -= 1;
|
|
190
|
+
else
|
|
191
|
+
this.data[t.t][t.n] -= 1;
|
|
177
192
|
if (t.t != constants_1.TYPE.Z &&
|
|
178
193
|
t.n == 5 &&
|
|
179
194
|
this.get(t.t, 5) == 0 &&
|
|
@@ -198,7 +213,7 @@ var Hand = (function () {
|
|
|
198
213
|
return;
|
|
199
214
|
};
|
|
200
215
|
Hand.prototype.reach = function () {
|
|
201
|
-
if (!this.
|
|
216
|
+
if (!this.menzen)
|
|
202
217
|
throw new Error("cannot reach");
|
|
203
218
|
if (this.data.reached)
|
|
204
219
|
throw new Error("already reached");
|
|
@@ -241,13 +256,6 @@ var Hand = (function () {
|
|
|
241
256
|
}
|
|
242
257
|
throw new Error("unexpected input ".concat(b));
|
|
243
258
|
};
|
|
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
259
|
Hand.prototype.clone = function () {
|
|
252
260
|
var c = new Hand(this.toString());
|
|
253
261
|
c.data.called = this.called.map(function (b) { return b.clone(); });
|
|
@@ -271,11 +279,13 @@ var ShantenCalculator = (function () {
|
|
|
271
279
|
var nPairs = 0;
|
|
272
280
|
var nIsolated = 0;
|
|
273
281
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
var t = _a[_i];
|
|
283
|
+
if (t == constants_1.TYPE.BACK)
|
|
284
|
+
continue;
|
|
285
|
+
for (var n = 1; n < this.hand.getArrayLen(t); n++) {
|
|
286
|
+
if (this.hand.get(t, n) == 2)
|
|
277
287
|
nPairs++;
|
|
278
|
-
if (this.hand.get(
|
|
288
|
+
if (this.hand.get(t, n) == 1)
|
|
279
289
|
nIsolated++;
|
|
280
290
|
}
|
|
281
291
|
}
|
|
@@ -309,19 +319,27 @@ var ShantenCalculator = (function () {
|
|
|
309
319
|
var _this = this;
|
|
310
320
|
var calc = function (hasPair) {
|
|
311
321
|
var z = [0, 0, 0];
|
|
312
|
-
var
|
|
313
|
-
for (var n = 1; n < _this.hand.getArrayLen(
|
|
314
|
-
if (_this.hand.get(
|
|
322
|
+
var zt = constants_1.TYPE.Z;
|
|
323
|
+
for (var n = 1; n < _this.hand.getArrayLen(zt); n++) {
|
|
324
|
+
if (_this.hand.get(zt, n) >= 3)
|
|
315
325
|
z[0]++;
|
|
316
|
-
else if (_this.hand.get(
|
|
326
|
+
else if (_this.hand.get(zt, n) == 2)
|
|
317
327
|
z[1]++;
|
|
318
|
-
else if (_this.hand.get(
|
|
328
|
+
else if (_this.hand.get(zt, n) == 1)
|
|
319
329
|
z[2]++;
|
|
320
330
|
}
|
|
331
|
+
var b = [0, 0, 0];
|
|
332
|
+
var bn = _this.hand.get(constants_1.TYPE.BACK, 0);
|
|
333
|
+
var bb = bn % 3;
|
|
334
|
+
b[0] = Math.floor(bn / 3);
|
|
335
|
+
if (bb == 2)
|
|
336
|
+
b[1] = 1;
|
|
337
|
+
if (bb == 1)
|
|
338
|
+
b[2] = 1;
|
|
321
339
|
var min = 13;
|
|
322
|
-
var mr = _this.
|
|
323
|
-
var pr = _this.
|
|
324
|
-
var sr = _this.
|
|
340
|
+
var mr = _this.commonByType(constants_1.TYPE.M);
|
|
341
|
+
var pr = _this.commonByType(constants_1.TYPE.P);
|
|
342
|
+
var sr = _this.commonByType(constants_1.TYPE.S);
|
|
325
343
|
for (var _i = 0, _a = [mr.patternA, mr.patternB]; _i < _a.length; _i++) {
|
|
326
344
|
var m = _a[_i];
|
|
327
345
|
for (var _b = 0, _c = [pr.patternA, pr.patternB]; _b < _c.length; _b++) {
|
|
@@ -330,7 +348,7 @@ var ShantenCalculator = (function () {
|
|
|
330
348
|
var s = _e[_d];
|
|
331
349
|
var v = [_this.hand.called.length, 0, 0];
|
|
332
350
|
for (var i = 0; i < 3; i++) {
|
|
333
|
-
v[i] += m[i] + p[i] + s[i] + z[i];
|
|
351
|
+
v[i] += m[i] + p[i] + s[i] + z[i] + b[i];
|
|
334
352
|
}
|
|
335
353
|
var r = _this.calcCommon(v[0], v[1], v[2], hasPair);
|
|
336
354
|
if (r < min) {
|
|
@@ -345,6 +363,8 @@ var ShantenCalculator = (function () {
|
|
|
345
363
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
346
364
|
var k = _a[_i];
|
|
347
365
|
for (var n = 1; n < this.hand.getArrayLen(k); n++) {
|
|
366
|
+
if (k == constants_1.TYPE.BACK && this.hand.get(k, n) % 3 != 2)
|
|
367
|
+
continue;
|
|
348
368
|
if (this.hand.get(k, n) >= 2) {
|
|
349
369
|
var tiles = this.hand.dec([new parser_1.Tile(k, n), new parser_1.Tile(k, n)]);
|
|
350
370
|
var r = calc(true);
|
|
@@ -357,11 +377,13 @@ var ShantenCalculator = (function () {
|
|
|
357
377
|
}
|
|
358
378
|
return min;
|
|
359
379
|
};
|
|
360
|
-
ShantenCalculator.prototype.
|
|
380
|
+
ShantenCalculator.prototype.commonByType = function (k, n) {
|
|
361
381
|
if (n === void 0) { n = 1; }
|
|
382
|
+
if (k == constants_1.TYPE.BACK || k == constants_1.TYPE.Z)
|
|
383
|
+
throw new Error("expect number type but ".concat(k));
|
|
362
384
|
if (n > 9)
|
|
363
385
|
return this.groupRemainingTiles(k);
|
|
364
|
-
var max = this.
|
|
386
|
+
var max = this.commonByType(k, n + 1);
|
|
365
387
|
if (n <= 7 &&
|
|
366
388
|
this.hand.get(k, n) > 0 &&
|
|
367
389
|
this.hand.get(k, n + 1) > 0 &&
|
|
@@ -371,7 +393,7 @@ var ShantenCalculator = (function () {
|
|
|
371
393
|
new parser_1.Tile(k, n + 1),
|
|
372
394
|
new parser_1.Tile(k, n + 2),
|
|
373
395
|
]);
|
|
374
|
-
var r = this.
|
|
396
|
+
var r = this.commonByType(k, n);
|
|
375
397
|
this.hand.inc(tiles);
|
|
376
398
|
r.patternA[0]++, r.patternB[0]++;
|
|
377
399
|
if (r.patternA[2] < max.patternA[2] ||
|
|
@@ -389,7 +411,7 @@ var ShantenCalculator = (function () {
|
|
|
389
411
|
new parser_1.Tile(k, n),
|
|
390
412
|
new parser_1.Tile(k, n),
|
|
391
413
|
]);
|
|
392
|
-
var r = this.
|
|
414
|
+
var r = this.commonByType(k, n);
|
|
393
415
|
this.hand.inc(tiles);
|
|
394
416
|
r.patternA[0]++, r.patternB[0]++;
|
|
395
417
|
if (r.patternA[2] < max.patternA[2] ||
|
|
@@ -444,55 +466,16 @@ var ShantenCalculator = (function () {
|
|
|
444
466
|
return ShantenCalculator;
|
|
445
467
|
}());
|
|
446
468
|
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) {
|
|
469
|
+
var BlockCalculator = (function () {
|
|
470
|
+
function BlockCalculator(hand) {
|
|
488
471
|
this.hand = hand;
|
|
489
472
|
}
|
|
490
|
-
|
|
473
|
+
BlockCalculator.prototype.calc = function (lastTile) {
|
|
491
474
|
if (this.hand.drawn != null)
|
|
492
475
|
lastTile = this.hand.drawn;
|
|
493
476
|
return this.markDrawn(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], this.sevenPairs(), true), this.thirteenOrphans(), true), this.nineGates(), true), this.fourSetsOnePair(), true), lastTile);
|
|
494
477
|
};
|
|
495
|
-
|
|
478
|
+
BlockCalculator.prototype.markDrawn = function (hands, lastTile) {
|
|
496
479
|
if (hands.length == 0)
|
|
497
480
|
return [];
|
|
498
481
|
var op = this.hand.drawn != null
|
|
@@ -530,7 +513,7 @@ var TileCalculator = (function () {
|
|
|
530
513
|
}
|
|
531
514
|
return newHands;
|
|
532
515
|
};
|
|
533
|
-
|
|
516
|
+
BlockCalculator.prototype.sevenPairs = function () {
|
|
534
517
|
if (this.hand.called.length > 0)
|
|
535
518
|
return [];
|
|
536
519
|
var ret = [];
|
|
@@ -550,7 +533,7 @@ var TileCalculator = (function () {
|
|
|
550
533
|
}
|
|
551
534
|
return [ret];
|
|
552
535
|
};
|
|
553
|
-
|
|
536
|
+
BlockCalculator.prototype.thirteenOrphans = function () {
|
|
554
537
|
var ret = [];
|
|
555
538
|
var pairs = "";
|
|
556
539
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
@@ -570,7 +553,7 @@ var TileCalculator = (function () {
|
|
|
570
553
|
}
|
|
571
554
|
return [ret];
|
|
572
555
|
};
|
|
573
|
-
|
|
556
|
+
BlockCalculator.prototype.nineGates = function () {
|
|
574
557
|
var _this = this;
|
|
575
558
|
var cond = function (k, n, want) {
|
|
576
559
|
return want.includes(_this.hand.get(k, n));
|
|
@@ -597,13 +580,13 @@ var TileCalculator = (function () {
|
|
|
597
580
|
}
|
|
598
581
|
return [];
|
|
599
582
|
};
|
|
600
|
-
|
|
583
|
+
BlockCalculator.prototype.fourSetsOnePair = function () {
|
|
601
584
|
var ret = [];
|
|
602
585
|
for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
|
|
603
586
|
var k = _a[_i];
|
|
604
|
-
if (k == constants_1.TYPE.BACK)
|
|
605
|
-
continue;
|
|
606
587
|
var _loop_1 = function (n) {
|
|
588
|
+
if (k == constants_1.TYPE.BACK && this_1.hand.get(k, n) % 3 != 2)
|
|
589
|
+
return "continue";
|
|
607
590
|
if (this_1.hand.get(k, n) >= 2) {
|
|
608
591
|
var tiles_3 = this_1.hand.dec([new parser_1.Tile(k, n), new parser_1.Tile(k, n)]);
|
|
609
592
|
var v = this_1.commonAll()
|
|
@@ -623,25 +606,39 @@ var TileCalculator = (function () {
|
|
|
623
606
|
}
|
|
624
607
|
return ret;
|
|
625
608
|
};
|
|
626
|
-
|
|
609
|
+
BlockCalculator.prototype.commonAll = function () {
|
|
627
610
|
var _this = this;
|
|
628
611
|
var handleZ = function () {
|
|
629
612
|
var z = [];
|
|
630
|
-
var
|
|
631
|
-
for (var n = 1; n < _this.hand.getArrayLen(
|
|
632
|
-
if (_this.hand.get(
|
|
613
|
+
var zt = constants_1.TYPE.Z;
|
|
614
|
+
for (var n = 1; n < _this.hand.getArrayLen(zt); n++) {
|
|
615
|
+
if (_this.hand.get(zt, n) == 0)
|
|
633
616
|
continue;
|
|
634
|
-
else if (_this.hand.get(
|
|
617
|
+
else if (_this.hand.get(zt, n) != 3)
|
|
635
618
|
return [];
|
|
636
|
-
z.push(new parser_1.BlockThree([new parser_1.Tile(
|
|
619
|
+
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
620
|
}
|
|
638
621
|
return z.length == 0 ? [] : [z];
|
|
639
622
|
};
|
|
623
|
+
var handleBack = function () {
|
|
624
|
+
var b = [];
|
|
625
|
+
var bt = constants_1.TYPE.BACK;
|
|
626
|
+
var sum = _this.hand.get(bt, 0);
|
|
627
|
+
if (sum < 3)
|
|
628
|
+
return [];
|
|
629
|
+
Array(Math.floor(sum / 3))
|
|
630
|
+
.fill(undefined)
|
|
631
|
+
.map(function (_) {
|
|
632
|
+
b.push(new parser_1.BlockThree([new parser_1.Tile(bt, 0), new parser_1.Tile(bt, 0), new parser_1.Tile(bt, 0)]));
|
|
633
|
+
});
|
|
634
|
+
return b.length == 0 ? [] : [b];
|
|
635
|
+
};
|
|
640
636
|
var vvv = [
|
|
641
|
-
this.
|
|
642
|
-
this.
|
|
643
|
-
this.
|
|
637
|
+
this.commonByType(constants_1.TYPE.M),
|
|
638
|
+
this.commonByType(constants_1.TYPE.P),
|
|
639
|
+
this.commonByType(constants_1.TYPE.S),
|
|
644
640
|
handleZ(),
|
|
641
|
+
handleBack(),
|
|
645
642
|
[this.hand.called],
|
|
646
643
|
].sort(function (a, b) { return b.length - a.length; });
|
|
647
644
|
var ret = vvv[0].concat();
|
|
@@ -655,23 +652,23 @@ var TileCalculator = (function () {
|
|
|
655
652
|
}
|
|
656
653
|
return ret;
|
|
657
654
|
};
|
|
658
|
-
|
|
655
|
+
BlockCalculator.prototype.commonByType = function (t, n) {
|
|
659
656
|
if (n === void 0) { n = 1; }
|
|
660
657
|
if (n > 9)
|
|
661
658
|
return [];
|
|
662
|
-
if (this.hand.get(
|
|
663
|
-
return this.
|
|
659
|
+
if (this.hand.get(t, n) == 0)
|
|
660
|
+
return this.commonByType(t, n + 1);
|
|
664
661
|
var ret = [];
|
|
665
662
|
if (n <= 7 &&
|
|
666
|
-
this.hand.get(
|
|
667
|
-
this.hand.get(
|
|
668
|
-
this.hand.get(
|
|
663
|
+
this.hand.get(t, n) > 0 &&
|
|
664
|
+
this.hand.get(t, n + 1) > 0 &&
|
|
665
|
+
this.hand.get(t, n + 2) > 0) {
|
|
669
666
|
var tiles = this.hand.dec([
|
|
670
|
-
new parser_1.Tile(
|
|
671
|
-
new parser_1.Tile(
|
|
672
|
-
new parser_1.Tile(
|
|
667
|
+
new parser_1.Tile(t, n),
|
|
668
|
+
new parser_1.Tile(t, n + 1),
|
|
669
|
+
new parser_1.Tile(t, n + 2),
|
|
673
670
|
]);
|
|
674
|
-
var nested = this.
|
|
671
|
+
var nested = this.commonByType(t, n);
|
|
675
672
|
this.hand.inc(tiles);
|
|
676
673
|
if (nested.length == 0)
|
|
677
674
|
nested.push([]);
|
|
@@ -681,13 +678,13 @@ var TileCalculator = (function () {
|
|
|
681
678
|
ret.push(arr);
|
|
682
679
|
}
|
|
683
680
|
}
|
|
684
|
-
if (this.hand.get(
|
|
681
|
+
if (this.hand.get(t, n) == 3) {
|
|
685
682
|
var tiles = this.hand.dec([
|
|
686
|
-
new parser_1.Tile(
|
|
687
|
-
new parser_1.Tile(
|
|
688
|
-
new parser_1.Tile(
|
|
683
|
+
new parser_1.Tile(t, n),
|
|
684
|
+
new parser_1.Tile(t, n),
|
|
685
|
+
new parser_1.Tile(t, n),
|
|
689
686
|
]);
|
|
690
|
-
var nested = this.
|
|
687
|
+
var nested = this.commonByType(t, n);
|
|
691
688
|
this.hand.inc(tiles);
|
|
692
689
|
if (nested.length == 0)
|
|
693
690
|
nested.push([]);
|
|
@@ -699,9 +696,9 @@ var TileCalculator = (function () {
|
|
|
699
696
|
}
|
|
700
697
|
return ret;
|
|
701
698
|
};
|
|
702
|
-
return
|
|
699
|
+
return BlockCalculator;
|
|
703
700
|
}());
|
|
704
|
-
exports.
|
|
701
|
+
exports.BlockCalculator = BlockCalculator;
|
|
705
702
|
var DoubleCalculator = (function () {
|
|
706
703
|
function DoubleCalculator(hand, params) {
|
|
707
704
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -863,7 +860,7 @@ var DoubleCalculator = (function () {
|
|
|
863
860
|
return ret;
|
|
864
861
|
};
|
|
865
862
|
DoubleCalculator.prototype.minus = function () {
|
|
866
|
-
return this.hand.
|
|
863
|
+
return this.hand.menzen ? 0 : 1;
|
|
867
864
|
};
|
|
868
865
|
DoubleCalculator.prototype.dA1 = function (h) {
|
|
869
866
|
if (this.cfg.reached == 1)
|
|
@@ -914,13 +911,13 @@ var DoubleCalculator = (function () {
|
|
|
914
911
|
if (tile.t == constants_1.TYPE.Z) {
|
|
915
912
|
if (tile.equals(_this.cfg.myWind))
|
|
916
913
|
ret.push({ name: "自風", double: 1 });
|
|
917
|
-
if (tile.equals(_this.cfg.roundWind))
|
|
914
|
+
else if (tile.equals(_this.cfg.roundWind))
|
|
918
915
|
ret.push({ name: "場風", double: 1 });
|
|
919
|
-
if (tile.n == 5)
|
|
916
|
+
else if (tile.n == 5)
|
|
920
917
|
ret.push({ name: "白", double: 1 });
|
|
921
|
-
if (tile.n == 6)
|
|
918
|
+
else if (tile.n == 6)
|
|
922
919
|
ret.push({ name: "發", double: 1 });
|
|
923
|
-
if (tile.n == 7)
|
|
920
|
+
else if (tile.n == 7)
|
|
924
921
|
ret.push({ name: "中", double: 1 });
|
|
925
922
|
}
|
|
926
923
|
});
|
|
@@ -985,13 +982,13 @@ var DoubleCalculator = (function () {
|
|
|
985
982
|
var tile = block.minTile();
|
|
986
983
|
if (tile.t == constants_1.TYPE.Z)
|
|
987
984
|
return "continue";
|
|
988
|
-
var
|
|
985
|
+
var filteredTypes = [constants_1.TYPE.M, constants_1.TYPE.P, constants_1.TYPE.S].filter(function (v) { return v != tile.t; });
|
|
989
986
|
var cond1 = h.some(function (b) {
|
|
990
|
-
var newTile = new parser_1.Tile(
|
|
987
|
+
var newTile = new parser_1.Tile(filteredTypes[0], tile.n);
|
|
991
988
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
992
989
|
});
|
|
993
990
|
var cond2 = h.some(function (b) {
|
|
994
|
-
var newTile = new parser_1.Tile(
|
|
991
|
+
var newTile = new parser_1.Tile(filteredTypes[1], tile.n);
|
|
995
992
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
996
993
|
});
|
|
997
994
|
if (cond1 && cond2)
|
|
@@ -1050,13 +1047,13 @@ var DoubleCalculator = (function () {
|
|
|
1050
1047
|
var tile = block.minTile();
|
|
1051
1048
|
if (tile.t == constants_1.TYPE.Z)
|
|
1052
1049
|
return "continue";
|
|
1053
|
-
var
|
|
1050
|
+
var filteredTypes = [constants_1.TYPE.M, constants_1.TYPE.P, constants_1.TYPE.S].filter(function (v) { return v != tile.t; });
|
|
1054
1051
|
var cond1 = h.some(function (b) {
|
|
1055
|
-
var newTile = new parser_1.Tile(
|
|
1052
|
+
var newTile = new parser_1.Tile(filteredTypes[0], tile.n);
|
|
1056
1053
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
1057
1054
|
});
|
|
1058
1055
|
var cond2 = h.some(function (b) {
|
|
1059
|
-
var newTile = new parser_1.Tile(
|
|
1056
|
+
var newTile = new parser_1.Tile(filteredTypes[1], tile.n);
|
|
1060
1057
|
return check(b) && newTile.equals(b.minTile(), true);
|
|
1061
1058
|
});
|
|
1062
1059
|
if (cond1 && cond2)
|
|
@@ -1085,7 +1082,9 @@ var DoubleCalculator = (function () {
|
|
|
1085
1082
|
return cond ? [{ name: "混老頭", double: 2 }] : [];
|
|
1086
1083
|
};
|
|
1087
1084
|
DoubleCalculator.prototype.dI2 = function (h) {
|
|
1088
|
-
if (
|
|
1085
|
+
if (h.length == 7)
|
|
1086
|
+
return [];
|
|
1087
|
+
if (!h.some(function (b) { return b instanceof parser_1.BlockRun || b instanceof parser_1.BlockChi; }))
|
|
1089
1088
|
return [];
|
|
1090
1089
|
if (!h.some(function (b) { return b.tiles[0].t == constants_1.TYPE.Z; }))
|
|
1091
1090
|
return [];
|
|
@@ -1146,13 +1145,14 @@ var DoubleCalculator = (function () {
|
|
|
1146
1145
|
return [];
|
|
1147
1146
|
};
|
|
1148
1147
|
DoubleCalculator.prototype.dB3 = function (h) {
|
|
1149
|
-
if (
|
|
1148
|
+
if (h.length == 7)
|
|
1149
|
+
return [];
|
|
1150
|
+
if (!h.some(function (b) { return b instanceof parser_1.BlockRun || b instanceof parser_1.BlockChi; }))
|
|
1150
1151
|
return [];
|
|
1151
1152
|
if (h.some(function (b) { return b.tiles[0].t == constants_1.TYPE.Z; }))
|
|
1152
1153
|
return [];
|
|
1153
1154
|
var cond = h.every(function (b) {
|
|
1154
|
-
|
|
1155
|
-
return b.tiles.some(function (t) { return values.includes(t.n); });
|
|
1155
|
+
return b.tiles.some(function (t) { return [1, 9].includes(t.n); });
|
|
1156
1156
|
});
|
|
1157
1157
|
return cond ? [{ name: "純全帯么九色", double: 3 - this.minus() }] : [];
|
|
1158
1158
|
};
|
|
@@ -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;
|
|
@@ -65,6 +66,13 @@ var Efficiency = (function () {
|
|
|
65
66
|
candidates: candidates,
|
|
66
67
|
};
|
|
67
68
|
};
|
|
69
|
+
Efficiency.partialCandidateTiles = function (input) {
|
|
70
|
+
var h = new calculator_1.Hand(input, true);
|
|
71
|
+
Array(13 - h.hands.length)
|
|
72
|
+
.fill(undefined)
|
|
73
|
+
.map(function () { return h.inc([new parser_1.Tile(constants_1.TYPE.BACK, 0)]); });
|
|
74
|
+
return Efficiency.candidateTiles(h);
|
|
75
|
+
};
|
|
68
76
|
return Efficiency;
|
|
69
77
|
}());
|
|
70
78
|
exports.Efficiency = Efficiency;
|
|
@@ -179,7 +187,7 @@ var RiskRank = (function () {
|
|
|
179
187
|
};
|
|
180
188
|
RiskRank.rankZ = function (c, targetUser, t) {
|
|
181
189
|
if (t.t != constants_1.TYPE.Z)
|
|
182
|
-
throw new Error("expected
|
|
190
|
+
throw new Error("expected TYPE.Z but ".concat(t.toString()));
|
|
183
191
|
if (c.isSafeTile(t.t, t.n, targetUser))
|
|
184
192
|
return 0;
|
|
185
193
|
var remaining = c.get(t);
|
|
@@ -187,7 +195,7 @@ var RiskRank = (function () {
|
|
|
187
195
|
};
|
|
188
196
|
RiskRank.rankN = function (c, targetUser, t) {
|
|
189
197
|
if (!t.isNum())
|
|
190
|
-
throw new Error("expected
|
|
198
|
+
throw new Error("expected TYPE.NUMBER but ".concat(t.toString()));
|
|
191
199
|
var n = t.n;
|
|
192
200
|
var type = t.t;
|
|
193
201
|
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);
|
|
@@ -399,7 +401,7 @@ function detectBlockType(tiles) {
|
|
|
399
401
|
return constants_1.BLOCK.UNKNOWN;
|
|
400
402
|
if (numOfHorizontals == 0 && numOfBackTiles == 0)
|
|
401
403
|
return constants_1.BLOCK.HAND;
|
|
402
|
-
if (tiles.length === 3) {
|
|
404
|
+
if (tiles.length === 3 && numOfBackTiles === 0) {
|
|
403
405
|
if (sameAll)
|
|
404
406
|
return constants_1.BLOCK.PON;
|
|
405
407
|
if (numOfHorizontals == 1 && areConsecutiveTiles(tiles))
|