@konoui/mjimage 0.0.10 → 0.0.12

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.
@@ -17,7 +17,7 @@ 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;
@@ -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): 1 | 8 | 10;
35
+ getArrayLen(k: Type): 2 | 8 | 10;
36
36
  sum(k: Type): number;
37
- get(k: Type, n: number): number;
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;
@@ -25,7 +25,7 @@ var Hand = (function () {
25
25
  _a[constants_1.TYPE.P] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
26
26
  _a[constants_1.TYPE.S] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
27
27
  _a[constants_1.TYPE.Z] = [0, 0, 0, 0, 0, 0, 0, 0],
28
- _a[constants_1.TYPE.BACK] = [0],
28
+ _a[constants_1.TYPE.BACK] = ["untouchable", 0],
29
29
  _a.called = [],
30
30
  _a.reached = false,
31
31
  _a.tsumo = null,
@@ -54,7 +54,7 @@ var Hand = (function () {
54
54
  this.inc(b.tiles);
55
55
  continue;
56
56
  }
57
- if (allowBackBlock) {
57
+ else if (allowBackBlock) {
58
58
  this.inc(b.tiles);
59
59
  continue;
60
60
  }
@@ -66,10 +66,12 @@ var Hand = (function () {
66
66
  var tiles = [];
67
67
  for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
68
68
  var k = _a[_i];
69
- for (var n = 0; n < this.getArrayLen(k); n++) {
69
+ for (var n = 1; n < this.getArrayLen(k); n++) {
70
70
  var count = this.get(k, n);
71
- if (k != constants_1.TYPE.Z && n == 5)
71
+ if (k != constants_1.TYPE.Z && n == 5 && this.get(k, 0) > 0) {
72
72
  count -= this.get(k, 0);
73
+ tiles.push(new parser_1.Tile(k, 0));
74
+ }
73
75
  for (var i = 0; i < count; i++) {
74
76
  tiles.push(new parser_1.Tile(k, n));
75
77
  }
@@ -133,8 +135,10 @@ var Hand = (function () {
133
135
  sum += this.get(k, n);
134
136
  return sum;
135
137
  };
136
- Hand.prototype.get = function (k, n) {
137
- return this.data[k][n];
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];
138
142
  };
139
143
  Hand.prototype.inc = function (tiles) {
140
144
  var backup = [];
@@ -148,7 +152,10 @@ var Hand = (function () {
148
152
  if (!(t.t == constants_1.TYPE.Z || t.t == constants_1.TYPE.BACK) && t.n == 0) {
149
153
  this.data[t.t][5] += 1;
150
154
  }
151
- this.data[t.t][t.n] += 1;
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;
152
159
  if (t.t != constants_1.TYPE.Z &&
153
160
  t.n == 5 &&
154
161
  this.get(t.t, 5) == 4 &&
@@ -164,7 +171,7 @@ var Hand = (function () {
164
171
  Hand.prototype.dec = function (tiles) {
165
172
  if (this.hands.every(function (t) { return t.t == constants_1.TYPE.BACK; })) {
166
173
  var toRemove = tiles.map(function (v) { return new parser_1.Tile(constants_1.TYPE.BACK, 0); });
167
- this.data[constants_1.TYPE.BACK][0] -= tiles.length;
174
+ this.data[constants_1.TYPE.BACK][1] -= tiles.length;
168
175
  return toRemove;
169
176
  }
170
177
  var backup = [];
@@ -178,7 +185,10 @@ var Hand = (function () {
178
185
  if (!(t.t == constants_1.TYPE.Z || t.t == constants_1.TYPE.BACK) && t.n == 0) {
179
186
  this.data[t.t][5] -= 1;
180
187
  }
181
- this.data[t.t][t.n] -= 1;
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;
182
192
  if (t.t != constants_1.TYPE.Z &&
183
193
  t.n == 5 &&
184
194
  this.get(t.t, 5) == 0 &&
@@ -269,11 +279,13 @@ var ShantenCalculator = (function () {
269
279
  var nPairs = 0;
270
280
  var nIsolated = 0;
271
281
  for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
272
- var k = _a[_i];
273
- for (var n = 1; n < this.hand.getArrayLen(k); n++) {
274
- if (this.hand.get(k, n) == 2)
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)
275
287
  nPairs++;
276
- if (this.hand.get(k, n) == 1)
288
+ if (this.hand.get(t, n) == 1)
277
289
  nIsolated++;
278
290
  }
279
291
  }
@@ -319,7 +331,7 @@ var ShantenCalculator = (function () {
319
331
  var b = [0, 0, 0];
320
332
  var bn = _this.hand.get(constants_1.TYPE.BACK, 0);
321
333
  var bb = bn % 3;
322
- b[0] = bn / 3;
334
+ b[0] = Math.floor(bn / 3);
323
335
  if (bb == 2)
324
336
  b[1] = 1;
325
337
  if (bb == 1)
@@ -351,6 +363,8 @@ var ShantenCalculator = (function () {
351
363
  for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
352
364
  var k = _a[_i];
353
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;
354
368
  if (this.hand.get(k, n) >= 2) {
355
369
  var tiles = this.hand.dec([new parser_1.Tile(k, n), new parser_1.Tile(k, n)]);
356
370
  var r = calc(true);
@@ -365,6 +379,8 @@ var ShantenCalculator = (function () {
365
379
  };
366
380
  ShantenCalculator.prototype.commonByType = function (k, n) {
367
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));
368
384
  if (n > 9)
369
385
  return this.groupRemainingTiles(k);
370
386
  var max = this.commonByType(k, n + 1);
@@ -569,6 +585,8 @@ var BlockCalculator = (function () {
569
585
  for (var _i = 0, _a = Object.values(constants_1.TYPE); _i < _a.length; _i++) {
570
586
  var k = _a[_i];
571
587
  var _loop_1 = function (n) {
588
+ if (k == constants_1.TYPE.BACK && this_1.hand.get(k, n) % 3 != 2)
589
+ return "continue";
572
590
  if (this_1.hand.get(k, n) >= 2) {
573
591
  var tiles_3 = this_1.hand.dec([new parser_1.Tile(k, n), new parser_1.Tile(k, n)]);
574
592
  var v = this_1.commonAll()
@@ -606,7 +624,9 @@ var BlockCalculator = (function () {
606
624
  var b = [];
607
625
  var bt = constants_1.TYPE.BACK;
608
626
  var sum = _this.hand.get(bt, 0);
609
- Array(sum / 3)
627
+ if (sum < 3)
628
+ return [];
629
+ Array(Math.floor(sum / 3))
610
630
  .fill(undefined)
611
631
  .map(function (_) {
612
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)]));
@@ -13,6 +13,10 @@ export declare class Efficiency {
13
13
  shanten: number;
14
14
  candidates: Tile[];
15
15
  };
16
+ static partialCandidateTiles(input: string): {
17
+ shanten: number;
18
+ candidates: Tile[];
19
+ };
16
20
  }
17
21
  export interface PlayerCandidate {
18
22
  tile: Tile;
@@ -66,6 +66,13 @@ var Efficiency = (function () {
66
66
  candidates: candidates,
67
67
  };
68
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
+ };
69
76
  return Efficiency;
70
77
  }());
71
78
  exports.Efficiency = Efficiency;
@@ -401,7 +401,7 @@ function detectBlockType(tiles) {
401
401
  return constants_1.BLOCK.UNKNOWN;
402
402
  if (numOfHorizontals == 0 && numOfBackTiles == 0)
403
403
  return constants_1.BLOCK.HAND;
404
- if (tiles.length === 3) {
404
+ if (tiles.length === 3 && numOfBackTiles === 0) {
405
405
  if (sameAll)
406
406
  return constants_1.BLOCK.PON;
407
407
  if (numOfHorizontals == 1 && areConsecutiveTiles(tiles))
@@ -70,12 +70,12 @@ declare const tableInputSchema: z.ZodObject<{
70
70
  front: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, ...z.ZodLiteral<"1w" | "2w" | "3w" | "4w">[]]>>>;
71
71
  }, "strict", z.ZodTypeAny, {
72
72
  round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
73
+ front: "1w" | "2w" | "3w" | "4w";
73
74
  sticks: {
74
75
  reach: number;
75
76
  dead: number;
76
77
  };
77
78
  doras: string[];
78
- front: "1w" | "2w" | "3w" | "4w";
79
79
  }, {
80
80
  round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4" | undefined;
81
81
  sticks?: {
@@ -108,12 +108,12 @@ declare const tableInputSchema: z.ZodObject<{
108
108
  };
109
109
  board: {
110
110
  round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
111
+ front: "1w" | "2w" | "3w" | "4w";
111
112
  sticks: {
112
113
  reach: number;
113
114
  dead: number;
114
115
  };
115
116
  doras: string[];
116
- front: "1w" | "2w" | "3w" | "4w";
117
117
  };
118
118
  }, {
119
119
  board: {
@@ -206,12 +206,12 @@ export declare const parseTableInput: (s: string) => {
206
206
  };
207
207
  board: {
208
208
  round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
209
+ front: "1w" | "2w" | "3w" | "4w";
209
210
  sticks: {
210
211
  reach: number;
211
212
  dead: number;
212
213
  };
213
214
  doras: string[];
214
- front: "1w" | "2w" | "3w" | "4w";
215
215
  };
216
216
  };
217
217
  export declare const convertInput: (i: TableInput) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",
@@ -64,13 +64,13 @@
64
64
  "parcel-reporter-static-files-copy": "^1.5.2",
65
65
  "process": "^0.11.10",
66
66
  "svg-sprite": "^2.0.2",
67
- "svgdom": "^0.1.16",
67
+ "svgdom": "0.1.14",
68
68
  "svgo": "^3.0.2",
69
69
  "ts-jest": "^29.1.1",
70
70
  "typescript": "^5.2.2"
71
71
  },
72
72
  "dependencies": {
73
- "@svgdotjs/svg.js": "^3.2.0",
73
+ "@svgdotjs/svg.js": "^3.2.4",
74
74
  "eventmit": "^2.0.4",
75
75
  "js-yaml": "^4.1.0",
76
76
  "xstate": "^5.7.0",