@konoui/mjimage 0.0.31 → 0.0.32

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.
Files changed (61) hide show
  1. package/dist/index.cjs +30 -0
  2. package/dist/index.d.cts +1386 -0
  3. package/dist/index.d.ts +1386 -0
  4. package/dist/index.js +10953 -0
  5. package/package.json +23 -14
  6. package/dist/mjs/cmd/index.d.ts +0 -1
  7. package/dist/mjs/cmd/index.js +0 -49
  8. package/dist/mjs/index.d.ts +0 -6
  9. package/dist/mjs/index.js +0 -22
  10. package/dist/mjs/lib/calculator/calc.d.ts +0 -275
  11. package/dist/mjs/lib/calculator/calc.js +0 -1397
  12. package/dist/mjs/lib/calculator/efficiency.d.ts +0 -24
  13. package/dist/mjs/lib/calculator/efficiency.js +0 -82
  14. package/dist/mjs/lib/calculator/helper.d.ts +0 -6
  15. package/dist/mjs/lib/calculator/helper.js +0 -21
  16. package/dist/mjs/lib/calculator/index.d.ts +0 -3
  17. package/dist/mjs/lib/calculator/index.js +0 -19
  18. package/dist/mjs/lib/controller/controller.d.ts +0 -168
  19. package/dist/mjs/lib/controller/controller.js +0 -897
  20. package/dist/mjs/lib/controller/events.d.ts +0 -171
  21. package/dist/mjs/lib/controller/events.js +0 -102
  22. package/dist/mjs/lib/controller/game.d.ts +0 -5
  23. package/dist/mjs/lib/controller/game.js +0 -29
  24. package/dist/mjs/lib/controller/index.d.ts +0 -10
  25. package/dist/mjs/lib/controller/index.js +0 -26
  26. package/dist/mjs/lib/controller/managers.d.ts +0 -83
  27. package/dist/mjs/lib/controller/managers.js +0 -194
  28. package/dist/mjs/lib/controller/player-efficiency.d.ts +0 -24
  29. package/dist/mjs/lib/controller/player-efficiency.js +0 -153
  30. package/dist/mjs/lib/controller/player.d.ts +0 -12
  31. package/dist/mjs/lib/controller/player.js +0 -85
  32. package/dist/mjs/lib/controller/replay.d.ts +0 -10
  33. package/dist/mjs/lib/controller/replay.js +0 -31
  34. package/dist/mjs/lib/controller/river.d.ts +0 -19
  35. package/dist/mjs/lib/controller/river.js +0 -52
  36. package/dist/mjs/lib/controller/state-machine.d.ts +0 -67
  37. package/dist/mjs/lib/controller/state-machine.js +0 -771
  38. package/dist/mjs/lib/controller/wall.d.ts +0 -24
  39. package/dist/mjs/lib/controller/wall.js +0 -117
  40. package/dist/mjs/lib/core/constants.d.ts +0 -73
  41. package/dist/mjs/lib/core/constants.js +0 -73
  42. package/dist/mjs/lib/core/index.d.ts +0 -2
  43. package/dist/mjs/lib/core/index.js +0 -18
  44. package/dist/mjs/lib/core/lexer.d.ts +0 -14
  45. package/dist/mjs/lib/core/lexer.js +0 -53
  46. package/dist/mjs/lib/core/parser.d.ts +0 -120
  47. package/dist/mjs/lib/core/parser.js +0 -612
  48. package/dist/mjs/lib/image/image.d.ts +0 -42
  49. package/dist/mjs/lib/image/image.js +0 -361
  50. package/dist/mjs/lib/image/index.d.ts +0 -1
  51. package/dist/mjs/lib/image/index.js +0 -17
  52. package/dist/mjs/lib/measure-text/index.d.ts +0 -19
  53. package/dist/mjs/lib/measure-text/index.js +0 -49
  54. package/dist/mjs/lib/myassert/index.d.ts +0 -1
  55. package/dist/mjs/lib/myassert/index.js +0 -8
  56. package/dist/mjs/lib/table/index.d.ts +0 -2
  57. package/dist/mjs/lib/table/index.js +0 -18
  58. package/dist/mjs/lib/table/table-parser.d.ts +0 -127
  59. package/dist/mjs/lib/table/table-parser.js +0 -105
  60. package/dist/mjs/lib/table/table.d.ts +0 -12
  61. package/dist/mjs/lib/table/table.js +0 -248
@@ -1,771 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createControllerMachine = void 0;
4
- exports.incrementalIDGenerator = incrementalIDGenerator;
5
- var constants_1 = require("../core/constants");
6
- var parser_1 = require("../core/parser");
7
- var calculator_1 = require("./../calculator");
8
- var managers_1 = require("./managers");
9
- var xstate_1 = require("xstate");
10
- var serializeBlocksOrFalse = function (b) {
11
- if (b === false)
12
- return false;
13
- return b.map(function (v) { return v.serialize(); });
14
- };
15
- var serializeBlockOrFalse = function (b) {
16
- if (b === false)
17
- return false;
18
- return b.serialize();
19
- };
20
- var serializeCandidate = function (cs) {
21
- if (cs === false)
22
- return false;
23
- return cs.map(function (c) {
24
- return {
25
- tile: c.tile.toString(),
26
- candidates: c.candidates.map(function (v) { return v.toString(); }),
27
- shanten: c.shanten,
28
- };
29
- });
30
- };
31
- var serializeWinResult = function (ret) {
32
- var v = JSON.parse(JSON.stringify(ret));
33
- return v;
34
- };
35
- var serializeWinResultOrFalse = function (ret) {
36
- if (ret === false)
37
- return false;
38
- return serializeWinResult(ret);
39
- };
40
- var createControllerMachine = function (c) {
41
- return (0, xstate_1.createMachine)({
42
- id: "Untitled",
43
- initial: "distribute",
44
- context: {
45
- currentWind: "1w",
46
- oneShotMap: (0, calculator_1.createWindMap)(false),
47
- missingMap: (0, calculator_1.createWindMap)(false),
48
- controller: c,
49
- genEventID: incrementalIDGenerator(),
50
- },
51
- states: {
52
- distribute: {
53
- on: {
54
- NEXT: {
55
- target: "drawn",
56
- },
57
- },
58
- entry: {
59
- type: "notify_distribution",
60
- },
61
- },
62
- drawn: {
63
- entry: {
64
- type: "notify_draw",
65
- },
66
- on: {
67
- NEXT: {
68
- target: "waiting_user_event_after_drawn",
69
- actions: {
70
- type: "notify_choice_after_drawn",
71
- },
72
- description: "可能なアクションとその詳細を通知\\\nDISCARD の場合は捨てられる牌の一覧",
73
- },
74
- },
75
- },
76
- waiting_user_event_after_drawn: {
77
- description: "ツモった1ユーザからのレスポンス待ち",
78
- on: {
79
- TSUMO: {
80
- target: "tsumo",
81
- guard: "canWin",
82
- },
83
- REACH: {
84
- target: "discarded",
85
- guard: "canReach",
86
- actions: {
87
- type: "notify_reach",
88
- },
89
- description: "入力に牌が必要\\\n立直直後のロンは立直棒が点数にならないので\\\n別途状態を保つ必要がある",
90
- },
91
- SHO_KAN: {
92
- target: "an_sho_kaned",
93
- },
94
- AN_KAN: {
95
- target: "an_sho_kaned",
96
- },
97
- DISCARD: {
98
- target: "discarded",
99
- description: "入力に牌が必須",
100
- actions: {
101
- type: "disable_one_shot_for_me",
102
- },
103
- },
104
- DRAWN_GAME_BY_NINE_TILES: {
105
- target: "drawn_game",
106
- },
107
- },
108
- },
109
- discarded: {
110
- entry: {
111
- type: "notify_discard",
112
- },
113
- on: {
114
- NEXT: {
115
- target: "waiting_user_event_after_discarded",
116
- actions: {
117
- type: "notify_choice_after_discarded",
118
- },
119
- description: "可能なアクションとその詳細を通知\\\nCHI/PON の場合は鳴ける組み合わせの一覧",
120
- },
121
- },
122
- },
123
- tsumo: {
124
- exit: [
125
- {
126
- type: "notify_tsumo",
127
- },
128
- {
129
- type: "notify_end",
130
- },
131
- ],
132
- type: "final",
133
- },
134
- waiting_user_event_after_discarded: {
135
- description: "最大 4人から choice に対するレスポンスを待つ\\\nユーザからではなく、controller が優先順位を考慮して遷移させる必要がある\\\n通知する choice がない場合、controller が\\*で遷移させる",
136
- on: {
137
- RON: {
138
- target: "roned",
139
- guard: "canWin",
140
- },
141
- PON: {
142
- target: "poned",
143
- guard: "canPon",
144
- },
145
- CHI: {
146
- target: "chied",
147
- guard: "canChi",
148
- },
149
- DAI_KAN: {
150
- target: "dai_kaned",
151
- },
152
- "*": {
153
- target: "wildcard_after_discarded",
154
- },
155
- },
156
- },
157
- roned: {
158
- exit: [
159
- {
160
- type: "notify_ron",
161
- },
162
- {
163
- type: "notify_end",
164
- },
165
- ],
166
- type: "final",
167
- },
168
- poned: {
169
- on: {
170
- NEXT: {
171
- target: "waiting_discard_event",
172
- actions: {
173
- type: "notify_choice_after_called",
174
- },
175
- },
176
- },
177
- entry: [
178
- {
179
- type: "notify_call",
180
- },
181
- {
182
- type: "disable_none_shot",
183
- },
184
- ],
185
- },
186
- chied: {
187
- on: {
188
- NEXT: {
189
- target: "waiting_discard_event",
190
- actions: {
191
- type: "notify_choice_after_called",
192
- params: { action: "chi" },
193
- },
194
- },
195
- },
196
- entry: [
197
- {
198
- type: "notify_call",
199
- },
200
- {
201
- type: "disable_one_shot",
202
- },
203
- ],
204
- },
205
- wildcard_after_discarded: {
206
- exit: [],
207
- always: [
208
- {
209
- target: "drawn_game",
210
- guard: "cannotContinue",
211
- },
212
- {
213
- target: "drawn",
214
- actions: [
215
- {
216
- type: "updateNextWind",
217
- },
218
- ],
219
- },
220
- ],
221
- },
222
- waiting_discard_event: {
223
- description: "鳴いたユーザからの DISCARD イベントを待つ",
224
- on: {
225
- DISCARD: {
226
- target: "discarded",
227
- },
228
- },
229
- },
230
- dai_kaned: {
231
- on: {
232
- NEXT: {
233
- target: "waiting_user_event_after_drawn",
234
- actions: [
235
- {
236
- type: "notify_draw",
237
- params: { action: "kan" },
238
- },
239
- {
240
- type: "notify_choice_after_drawn",
241
- params: { replacementWin: true },
242
- },
243
- ],
244
- },
245
- },
246
- entry: [
247
- {
248
- type: "notify_call",
249
- },
250
- {
251
- type: "disable_one_shot",
252
- },
253
- ],
254
- },
255
- an_sho_kaned: {
256
- on: {
257
- NEXT: {
258
- target: "waiting_chankan_event",
259
- },
260
- },
261
- entry: [
262
- {
263
- type: "notify_call",
264
- },
265
- {
266
- type: "disable_one_shot",
267
- },
268
- {
269
- type: "notify_new_dora_if_needed",
270
- },
271
- {
272
- type: "notify_choice_for_chankan",
273
- },
274
- ],
275
- },
276
- waiting_chankan_event: {
277
- description: "チャンカンを待つ",
278
- exit: [
279
- {
280
- type: "notify_draw",
281
- params: { action: "kan" },
282
- },
283
- {
284
- type: "notify_choice_after_drawn",
285
- params: { replacementWin: true },
286
- },
287
- ],
288
- on: {
289
- RON: {
290
- target: "roned",
291
- guard: "canWin",
292
- },
293
- "*": {
294
- target: "waiting_user_event_after_drawn",
295
- },
296
- },
297
- },
298
- drawn_game: {
299
- exit: {
300
- type: "notify_end",
301
- params: {},
302
- },
303
- type: "final",
304
- },
305
- },
306
- types: {
307
- events: {},
308
- context: {},
309
- },
310
- }, {
311
- actions: {
312
- updateNextWind: function (_a) {
313
- var context = _a.context, event = _a.event;
314
- var cur = context.currentWind;
315
- context.currentWind = (0, managers_1.nextWind)(cur);
316
- },
317
- notify_distribution: function (_a) {
318
- var context = _a.context, event = _a.event;
319
- var id = context.genEventID();
320
- var initHands = context.controller.initialHands();
321
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
322
- var w = _b[_i];
323
- var hands = (0, calculator_1.createWindMap)("_____________");
324
- hands[w] = initHands[w].toString();
325
- var e = {
326
- id: id,
327
- type: "DISTRIBUTE",
328
- hands: hands,
329
- wind: w,
330
- doraMarker: context.controller.wall.doraMarkers[0].toString(),
331
- sticks: context.controller.placeManager.sticks,
332
- round: context.controller.placeManager.round,
333
- players: context.controller.playerIDs,
334
- places: context.controller.placeManager.playerMap,
335
- scores: context.controller.scoreManager.summary,
336
- };
337
- context.controller.emit(e);
338
- }
339
- context.controller.next();
340
- },
341
- notify_choice_after_drawn: function (_a, params) {
342
- var context = _a.context, event = _a.event;
343
- var w = context.currentWind;
344
- var drawn = context.controller.hand(w).drawn;
345
- var id = context.genEventID();
346
- var e = {
347
- id: id,
348
- type: "CHOICE_AFTER_DRAWN",
349
- wind: w,
350
- drawerInfo: { wind: w, tile: drawn.toString() },
351
- choices: {
352
- TSUMO: serializeWinResultOrFalse(context.controller.doWin(w, drawn, {
353
- oneShot: context.oneShotMap[w],
354
- replacementWin: params === null || params === void 0 ? void 0 : params.replacementWin,
355
- })),
356
- REACH: serializeCandidate(context.controller.doReach(w)),
357
- AN_KAN: serializeBlocksOrFalse(context.controller.doAnKan(w)),
358
- SHO_KAN: serializeBlocksOrFalse(context.controller.doShoKan(w)),
359
- DISCARD: context.controller.doDiscard(w).map(function (v) { return v.toString(); }),
360
- DRAWN_GAME_BY_NINE_TILES: context.controller.canDrawnGame(w),
361
- },
362
- };
363
- context.controller.emit(e);
364
- context.controller.pollReplies(id, [w]);
365
- },
366
- notify_choice_after_discarded: function (_a) {
367
- var context = _a.context, event = _a.event;
368
- var id = context.genEventID();
369
- var discarded = context.controller.river.lastTile;
370
- var ltile = discarded.t.clone({ add: constants_1.OPERATOR.HORIZONTAL });
371
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
372
- var w = _b[_i];
373
- var e = {
374
- id: id,
375
- type: "CHOICE_AFTER_DISCARDED",
376
- wind: w,
377
- discarterInfo: {
378
- wind: discarded.w,
379
- tile: discarded.t.toString(),
380
- },
381
- choices: {
382
- RON: serializeWinResultOrFalse(context.controller.doWin(w, ltile, {
383
- whoDiscarded: discarded.w,
384
- oneShot: context.oneShotMap[w],
385
- missingRon: context.missingMap[w],
386
- })),
387
- PON: serializeBlocksOrFalse(context.controller.doPon(w, discarded.w, ltile)),
388
- CHI: serializeBlocksOrFalse(context.controller.doChi(w, discarded.w, ltile)),
389
- DAI_KAN: serializeBlockOrFalse(context.controller.doDaiKan(w, discarded.w, ltile)),
390
- },
391
- };
392
- if (e.choices.RON)
393
- context.missingMap[w] = true;
394
- context.controller.emit(e);
395
- }
396
- context.controller.pollReplies(id, Object.values(constants_1.WIND));
397
- },
398
- notify_choice_after_called: function (_a, params) {
399
- var context = _a.context, event = _a.event;
400
- var id = context.genEventID();
401
- var w = context.currentWind;
402
- var discard = context.controller.doDiscard(w);
403
- var called = context.controller
404
- .hand(context.currentWind)
405
- .called.at(-1);
406
- if (called instanceof parser_1.BlockChi || called instanceof parser_1.BlockPon)
407
- discard = context.controller.doDiscard(w, called);
408
- var e = {
409
- id: id,
410
- type: "CHOICE_AFTER_CALLED",
411
- wind: w,
412
- choices: {
413
- DISCARD: discard.map(function (v) { return v.toString(); }),
414
- },
415
- };
416
- context.controller.emit(e);
417
- context.controller.pollReplies(id, [w]);
418
- },
419
- notify_choice_for_chankan: function (_a) {
420
- var context = _a.context, event = _a.event;
421
- if (event.type != "SHO_KAN" && event.type != "AN_KAN")
422
- throw new Error("unexpected event ".concat(event.type));
423
- var id = context.genEventID();
424
- var t = event.block.tiles[0].clone({ remove: constants_1.OPERATOR.HORIZONTAL });
425
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
426
- var w = _b[_i];
427
- var ron = context.controller.doWin(w, event.block.tiles[0].clone({ remove: constants_1.OPERATOR.HORIZONTAL }), {
428
- whoDiscarded: event.iam,
429
- quadWin: true,
430
- oneShot: context.oneShotMap[w],
431
- missingRon: context.missingMap[event.iam],
432
- });
433
- var e = {
434
- id: id,
435
- type: "CHOICE_FOR_CHAN_KAN",
436
- wind: w,
437
- callerInfo: { wind: event.iam, tile: t.toString() },
438
- choices: {
439
- RON: event.type == "SHO_KAN"
440
- ? serializeWinResultOrFalse(ron)
441
- : false,
442
- },
443
- };
444
- if (e.choices.RON)
445
- context.missingMap[w] = true;
446
- context.controller.emit(e);
447
- }
448
- context.controller.pollReplies(id, Object.values(constants_1.WIND));
449
- },
450
- notify_call: function (_a) {
451
- var context = _a.context, event = _a.event;
452
- if (!(event.type == "CHI" ||
453
- event.type == "PON" ||
454
- event.type == "DAI_KAN" ||
455
- event.type == "AN_KAN" ||
456
- event.type == "SHO_KAN"))
457
- throw new Error("unexpected event ".concat(event.type));
458
- var id = context.genEventID();
459
- var iam = event.iam;
460
- context.currentWind = iam;
461
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
462
- var w = _b[_i];
463
- var e = {
464
- id: id,
465
- type: event.type,
466
- iam: iam,
467
- wind: w,
468
- block: event.block.serialize(),
469
- };
470
- context.controller.emit(e);
471
- }
472
- context.controller.next();
473
- },
474
- notify_discard: function (_a) {
475
- var context = _a.context, event = _a.event;
476
- if (event.type != "DISCARD" && event.type != "REACH")
477
- throw new Error("unexpected event ".concat(event.type));
478
- var id = context.genEventID();
479
- var iam = context.currentWind;
480
- var t = event.tile;
481
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
482
- var w = _b[_i];
483
- var e = {
484
- id: id,
485
- type: "DISCARD",
486
- iam: iam,
487
- wind: w,
488
- tile: t.toString(),
489
- };
490
- context.controller.emit(e);
491
- }
492
- context.controller.next();
493
- },
494
- notify_draw: function (_a, params) {
495
- var context = _a.context, event = _a.event;
496
- var id = context.genEventID();
497
- var action = params === null || params === void 0 ? void 0 : params.action;
498
- var drawn = undefined;
499
- if (action == "kan")
500
- drawn = context.controller.wall.kan();
501
- else
502
- drawn = context.controller.wall.draw();
503
- var iam = context.currentWind;
504
- if (!context.controller.hand(iam).reached)
505
- context.missingMap[iam] = false;
506
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
507
- var w = _b[_i];
508
- var t = new parser_1.Tile(constants_1.TYPE.BACK, 0, [constants_1.OPERATOR.TSUMO]);
509
- if (w == iam)
510
- t = drawn;
511
- var e = {
512
- id: id,
513
- type: "DRAW",
514
- subType: action,
515
- iam: iam,
516
- wind: w,
517
- tile: t.toString(),
518
- };
519
- context.controller.emit(e);
520
- }
521
- context.controller.next();
522
- },
523
- notify_ron: function (_a) {
524
- var context = _a.context, event = _a.event;
525
- var id = context.genEventID();
526
- if (event.type == "RON") {
527
- var ronWind = event.targetInfo.wind;
528
- var cur = context.currentWind;
529
- var pushBackReachStick = ronWind == cur && context.oneShotMap[cur] == true;
530
- var iam = event.iam;
531
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
532
- var w = _b[_i];
533
- var e = {
534
- id: id,
535
- type: event.type,
536
- iam: iam,
537
- wind: w,
538
- victimInfo: {
539
- wind: event.targetInfo.wind,
540
- tile: event.targetInfo.tile.toString(),
541
- },
542
- ret: serializeWinResult(event.ret),
543
- pushBackReachStick: pushBackReachStick,
544
- };
545
- context.controller.emit(e);
546
- }
547
- }
548
- },
549
- notify_tsumo: function (_a) {
550
- var context = _a.context, event = _a.event;
551
- if (event.type != "TSUMO")
552
- throw new Error("unexpected event ".concat(event.type));
553
- var id = context.genEventID();
554
- var iam = context.currentWind;
555
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
556
- var w = _b[_i];
557
- var e = {
558
- id: id,
559
- type: event.type,
560
- iam: iam,
561
- wind: w,
562
- lastTile: context.controller.hand(iam).drawn.toString(),
563
- ret: serializeWinResult(event.ret),
564
- };
565
- context.controller.emit(e);
566
- }
567
- },
568
- notify_reach: function (_a) {
569
- var context = _a.context, event = _a.event;
570
- if (event.type != "REACH")
571
- throw new Error("unexpected event ".concat(event.type));
572
- var id = context.genEventID();
573
- var iam = event.iam;
574
- var t = event.tile.clone({ add: constants_1.OPERATOR.HORIZONTAL });
575
- context.oneShotMap[iam] = true;
576
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
577
- var w = _b[_i];
578
- var e = {
579
- id: id,
580
- type: event.type,
581
- iam: iam,
582
- wind: w,
583
- tile: t.toString(),
584
- };
585
- context.controller.emit(e);
586
- }
587
- },
588
- notify_new_dora_if_needed: function (_a) {
589
- var context = _a.context, event = _a.event;
590
- var id = context.genEventID();
591
- if (event.type == "AN_KAN") {
592
- var tile = context.controller.wall.openDoraMarker();
593
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
594
- var w = _b[_i];
595
- var e = {
596
- id: id,
597
- type: "NEW_DORA",
598
- wind: w,
599
- doraMarker: tile.toString(),
600
- };
601
- context.controller.emit(e);
602
- }
603
- }
604
- if (event.type == "SHO_KAN") {
605
- }
606
- },
607
- disable_one_shot: function (_a) {
608
- var context = _a.context, event = _a.event;
609
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
610
- var w = _b[_i];
611
- context.oneShotMap[w] = false;
612
- }
613
- },
614
- disable_one_shot_for_me: function (_a) {
615
- var context = _a.context, event = _a.event;
616
- context.oneShotMap[context.currentWind] = false;
617
- },
618
- notify_end: function (_a) {
619
- var context = _a.context, event = _a.event;
620
- var id = context.genEventID();
621
- var hands = (0, calculator_1.createWindMap)("");
622
- if (event.type == "DRAWN_GAME_BY_NINE_TILES") {
623
- hands[event.iam] = context.controller.hand(event.iam).toString();
624
- for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
625
- var w = _b[_i];
626
- var e = {
627
- id: id,
628
- type: "END_GAME",
629
- subType: "NINE_TILES",
630
- wind: w,
631
- shouldContinue: true,
632
- sticks: context.controller.placeManager.sticks,
633
- scores: context.controller.scoreManager.summary,
634
- deltas: (0, calculator_1.createWindMap)(0),
635
- hands: hands,
636
- };
637
- context.controller.emit(e);
638
- }
639
- }
640
- else if (event.type == "RON" || event.type == "TSUMO") {
641
- var shouldContinue = event.iam == "1w";
642
- var finalResults = context.controller.finalResult(event.ret, event.iam);
643
- for (var _c = 0, _d = Object.values(constants_1.WIND); _c < _d.length; _c++) {
644
- var w = _d[_c];
645
- hands[event.iam] = context.controller.hand(event.iam).toString();
646
- var e = {
647
- id: id,
648
- type: "END_GAME",
649
- subType: "WIN_GAME",
650
- wind: w,
651
- shouldContinue: shouldContinue,
652
- sticks: { reach: 0, dead: 0 },
653
- scores: context.controller.scoreManager.summary,
654
- deltas: finalResults.deltas,
655
- hands: hands,
656
- };
657
- context.controller.emit(e);
658
- }
659
- }
660
- else if (!context.controller.wall.canKan ||
661
- context.controller.river.cannotContinue()) {
662
- var subType = !context.controller.wall.canKan
663
- ? "FOUR_KAN"
664
- : "FOUR_WIND";
665
- for (var _e = 0, _f = Object.values(constants_1.WIND); _e < _f.length; _e++) {
666
- var w = _f[_e];
667
- var e = {
668
- id: id,
669
- type: "END_GAME",
670
- subType: subType,
671
- wind: w,
672
- shouldContinue: true,
673
- sticks: context.controller.placeManager.sticks,
674
- scores: context.controller.scoreManager.summary,
675
- deltas: (0, calculator_1.createWindMap)(0),
676
- hands: (0, calculator_1.createWindMap)(""),
677
- };
678
- context.controller.emit(e);
679
- }
680
- }
681
- else if (!context.controller.wall.canDraw) {
682
- var wind = [];
683
- for (var _g = 0, _h = Object.values(constants_1.WIND); _g < _h.length; _g++) {
684
- var w = _h[_g];
685
- var hand = context.controller.hand(w);
686
- var shan = new calculator_1.ShantenCalculator(hand).calc();
687
- if (shan == 0) {
688
- wind.push(w);
689
- hands[w] = hand.toString();
690
- }
691
- }
692
- var nothing = wind.length == 0 || wind.length == 4;
693
- var deltas = (0, calculator_1.createWindMap)(0);
694
- for (var _j = 0, _k = Object.values(constants_1.WIND); _j < _k.length; _j++) {
695
- var w = _k[_j];
696
- if (wind.includes(w))
697
- deltas[w] += nothing ? 0 : 3000 / wind.length;
698
- else
699
- deltas[w] -= nothing ? 0 : 3000 / (4 - wind.length);
700
- }
701
- var shouldContinue = wind.length == 4 || deltas["1w"] > 0;
702
- for (var _l = 0, _m = Object.values(constants_1.WIND); _l < _m.length; _l++) {
703
- var w = _m[_l];
704
- var e = {
705
- id: id,
706
- type: "END_GAME",
707
- subType: "DRAWN_GAME",
708
- wind: w,
709
- shouldContinue: shouldContinue,
710
- sticks: context.controller.placeManager.sticks,
711
- scores: context.controller.scoreManager.summary,
712
- deltas: deltas,
713
- hands: hands,
714
- };
715
- context.controller.emit(e);
716
- }
717
- }
718
- else
719
- throw new Error("unexpected event ".concat(event.type));
720
- },
721
- },
722
- actors: {},
723
- guards: {
724
- canChi: function (_a, params) {
725
- var context = _a.context, event = _a.event;
726
- if (event.type == "CHI")
727
- return !!context.controller.doChi(event.iam, context.controller.river.lastTile.w, context.controller.river.lastTile.t);
728
- console.error("guards.canChi receive ".concat(event.type));
729
- return false;
730
- },
731
- canPon: function (_a, params) {
732
- var context = _a.context, event = _a.event;
733
- if (event.type == "PON")
734
- return !!context.controller.doPon(event.iam, context.controller.river.lastTile.w, context.controller.river.lastTile.t);
735
- console.error("guards.canPon receive ".concat(event.type));
736
- return false;
737
- },
738
- canWin: function (_a, params) {
739
- var context = _a.context, event = _a.event;
740
- if (event.type == "TSUMO" || event.type == "RON") {
741
- return true;
742
- }
743
- console.error("guards.canWin receive ".concat(event.type));
744
- return false;
745
- },
746
- canReach: function (_a, params) {
747
- var context = _a.context, event = _a.event;
748
- if (event.type == "REACH") {
749
- return !!context.controller.doReach(event.iam);
750
- }
751
- console.error("guards.canReach receive ".concat(event.type));
752
- return false;
753
- },
754
- cannotContinue: function (_a, params) {
755
- var context = _a.context, event = _a.event;
756
- return (!context.controller.wall.canDraw ||
757
- !context.controller.wall.canKan ||
758
- context.controller.river.cannotContinue());
759
- },
760
- },
761
- delays: {},
762
- });
763
- };
764
- exports.createControllerMachine = createControllerMachine;
765
- function incrementalIDGenerator(start) {
766
- if (start === void 0) { start = 0; }
767
- var idx = start;
768
- return function () {
769
- return (idx++).toString();
770
- };
771
- }