@konoui/mjimage 0.0.31 → 0.0.33

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 +1389 -0
  3. package/dist/index.d.ts +1389 -0
  4. package/dist/index.js +10971 -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,171 +0,0 @@
1
- import { Wind, Round } from "../core/constants";
2
- import { SerializedBlock } from "../core/parser";
3
- import { SerializedCandidate, SerializedWinResult } from "../calculator";
4
- type Event = CallEvent | "DRAW" | "CHOICE_AFTER_DRAWN" | "CHOICE_AFTER_DISCARDED" | "CHOICE_AFTER_CALLED" | "CHOICE_FOR_CHAN_KAN" | "DISTRIBUTE" | "NEW_DORA" | "END_GAME";
5
- type ChoiceEvent = "PON" | "CHI" | "RON" | "DISCARD" | "TSUMO" | "REACH" | "AN_KAN" | "SHO_KAN" | "DAI_KAN" | "DRAWN_GAME_BY_NINE_TILES";
6
- export interface DistributeEvent {
7
- id: string;
8
- type: Extract<Event, "DISTRIBUTE">;
9
- hands: {
10
- [key in Wind]: string;
11
- };
12
- wind: Wind;
13
- doraMarker: string;
14
- players: string[];
15
- places: {
16
- [key: string]: Wind;
17
- };
18
- sticks: {
19
- reach: number;
20
- dead: number;
21
- };
22
- round: Round;
23
- scores: {
24
- [key: string]: number;
25
- };
26
- }
27
- export interface EndEvent {
28
- id: string;
29
- type: Extract<Event, "END_GAME">;
30
- subType: "WIN_GAME" | "DRAWN_GAME" | "FOUR_KAN" | "FOUR_WIND" | "NINE_TILES";
31
- wind: Wind;
32
- scores: {
33
- [key: string]: number;
34
- };
35
- sticks: {
36
- reach: number;
37
- dead: number;
38
- };
39
- deltas: {
40
- [key in Wind]: number;
41
- };
42
- hands: {
43
- [key in Wind]: string;
44
- };
45
- shouldContinue: boolean;
46
- }
47
- export interface CallEvent {
48
- id: string;
49
- type: Extract<ChoiceEvent, "PON" | "CHI" | "AN_KAN" | "SHO_KAN" | "DAI_KAN">;
50
- iam: Wind;
51
- wind: Wind;
52
- block: SerializedBlock;
53
- }
54
- export interface RonEvent {
55
- id: string;
56
- type: Extract<ChoiceEvent, "RON">;
57
- iam: Wind;
58
- wind: Wind;
59
- ret: SerializedWinResult;
60
- victimInfo: {
61
- wind: Wind;
62
- tile: string;
63
- };
64
- pushBackReachStick: boolean;
65
- }
66
- export interface TsumoEvent {
67
- id: string;
68
- type: Extract<ChoiceEvent, "TSUMO">;
69
- iam: Wind;
70
- wind: Wind;
71
- lastTile: string;
72
- ret: SerializedWinResult;
73
- }
74
- export interface DiscardEvent {
75
- id: string;
76
- type: Extract<ChoiceEvent, "DISCARD">;
77
- iam: Wind;
78
- wind: Wind;
79
- tile: string;
80
- }
81
- export interface DrawEvent {
82
- id: string;
83
- type: Extract<Event, "DRAW">;
84
- subtype?: "kan";
85
- iam: Wind;
86
- wind: Wind;
87
- tile: string;
88
- }
89
- export interface ReachEvent {
90
- id: string;
91
- type: Extract<ChoiceEvent, "REACH">;
92
- tile: string;
93
- iam: Wind;
94
- wind: Wind;
95
- }
96
- export interface NewDoraEvent {
97
- id: string;
98
- type: Extract<Event, "NEW_DORA">;
99
- doraMarker: string;
100
- wind: Wind;
101
- }
102
- export interface ChoiceAfterDrawnEvent {
103
- id: string;
104
- type: Extract<Event, "CHOICE_AFTER_DRAWN">;
105
- wind: Wind;
106
- drawerInfo: {
107
- wind: Wind;
108
- tile: string;
109
- };
110
- choices: DrawnChoice;
111
- }
112
- export interface ChoiceAfterDiscardedEvent {
113
- id: string;
114
- type: Extract<Event, "CHOICE_AFTER_DISCARDED">;
115
- wind: Wind;
116
- discarterInfo: {
117
- wind: Wind;
118
- tile: string;
119
- };
120
- choices: DiscardedChoice;
121
- }
122
- export interface ChoiceAfterCalled {
123
- id: string;
124
- type: Extract<Event, "CHOICE_AFTER_CALLED">;
125
- wind: Wind;
126
- choices: Pick<DrawnChoice, "DISCARD">;
127
- }
128
- export interface ChoiceForChanKan {
129
- id: string;
130
- type: Extract<Event, "CHOICE_FOR_CHAN_KAN">;
131
- wind: Wind;
132
- callerInfo: {
133
- wind: Wind;
134
- tile: string;
135
- };
136
- choices: Pick<DiscardedChoice, "RON">;
137
- }
138
- export type PlayerEvent = DistributeEvent | EndEvent | CallEvent | RonEvent | TsumoEvent | DiscardEvent | DrawEvent | ReachEvent | NewDoraEvent | ChoiceAfterDrawnEvent | ChoiceAfterDiscardedEvent | ChoiceAfterCalled | ChoiceForChanKan;
139
- interface DiscardedChoice {
140
- RON: false | SerializedWinResult;
141
- PON: false | SerializedBlock[];
142
- CHI: false | SerializedBlock[];
143
- DAI_KAN: false | SerializedBlock;
144
- }
145
- interface DrawnChoice {
146
- TSUMO: false | SerializedWinResult;
147
- REACH: false | SerializedCandidate[];
148
- AN_KAN: false | SerializedBlock[];
149
- SHO_KAN: false | SerializedBlock[];
150
- DISCARD: false | string[];
151
- DRAWN_GAME_BY_NINE_TILES: boolean;
152
- }
153
- export declare function prioritizeDiscardedEvents(events: ChoiceAfterDiscardedEvent[]): {
154
- events: ChoiceAfterDiscardedEvent[];
155
- type: boolean | keyof DiscardedChoice;
156
- };
157
- export declare function prioritizeDrawnEvents(events: ChoiceAfterDrawnEvent[]): {
158
- events: ChoiceAfterDrawnEvent[];
159
- type: boolean | keyof DrawnChoice;
160
- };
161
- export interface EventHandler {
162
- emit(e: PlayerEvent): void;
163
- on(handler: EventHandlerFunc): void;
164
- }
165
- export type EventHandlerFunc = (e: PlayerEvent) => void;
166
- export declare const createEventPipe: () => [EventHandler, EventHandler];
167
- export declare const createEventEmitter: () => {
168
- emit: (e: PlayerEvent) => void;
169
- on: (h: EventHandlerFunc) => void;
170
- };
171
- export {};
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEventEmitter = exports.createEventPipe = void 0;
4
- exports.prioritizeDiscardedEvents = prioritizeDiscardedEvents;
5
- exports.prioritizeDrawnEvents = prioritizeDrawnEvents;
6
- var eventmit_1 = require("eventmit");
7
- function prioritizeDiscardedEvents(events) {
8
- var _a;
9
- var order = ["RON", "DAI_KAN", "PON", "CHI"];
10
- var choices = events.map(function (e) { return e.choices; });
11
- var indexes = prioritizeEvents(choices, order);
12
- var selected = indexes.map(function (idx) { return events[idx]; });
13
- return {
14
- events: selected,
15
- type: priorityIndex(order, (_a = selected[0]) === null || _a === void 0 ? void 0 : _a.choices),
16
- };
17
- }
18
- function prioritizeDrawnEvents(events) {
19
- var _a;
20
- var order = [
21
- "TSUMO",
22
- "REACH",
23
- "AN_KAN",
24
- "SHO_KAN",
25
- "DRAWN_GAME_BY_NINE_TILES",
26
- "DISCARD",
27
- ];
28
- var choices = events.map(function (e) { return e.choices; });
29
- var indexes = prioritizeEvents(choices, order);
30
- var selected = indexes.map(function (idx) { return events[idx]; });
31
- return {
32
- events: selected,
33
- type: priorityIndex(order, (_a = selected[0]) === null || _a === void 0 ? void 0 : _a.choices),
34
- };
35
- }
36
- function prioritizeEvents(choices, order) {
37
- var highestPriorityIndices = [];
38
- var highestPriority = Number.POSITIVE_INFINITY;
39
- for (var i = 0; i < choices.length; i++) {
40
- var choice = choices[i];
41
- if (hasChoices(choice, order)) {
42
- var priority = calculatePriority(order, choice);
43
- if (priority < highestPriority) {
44
- highestPriority = priority;
45
- highestPriorityIndices = [i];
46
- }
47
- else if (priority === highestPriority) {
48
- highestPriorityIndices.push(i);
49
- }
50
- }
51
- }
52
- return highestPriorityIndices;
53
- }
54
- function hasChoices(choice, order) {
55
- return order.some(function (v) { return !!choice[v]; });
56
- }
57
- function calculatePriority(order, choice) {
58
- for (var i = 0; i < order.length; i++) {
59
- var key = order[i];
60
- if (!!choice[key])
61
- return i;
62
- }
63
- return Number.POSITIVE_INFINITY;
64
- }
65
- function priorityIndex(order, choice) {
66
- if (choice == null)
67
- return false;
68
- for (var _i = 0, order_1 = order; _i < order_1.length; _i++) {
69
- var key = order_1[_i];
70
- if (!!choice[key])
71
- return key;
72
- }
73
- return false;
74
- }
75
- var createEventPipe = function () {
76
- var e1 = (0, eventmit_1.eventmit)();
77
- var e2 = (0, eventmit_1.eventmit)();
78
- var p1 = {
79
- emit: e1.emit,
80
- on: function (h) { return e2.on(h); },
81
- };
82
- var p2 = {
83
- emit: e2.emit,
84
- on: function (h) { return e1.on(h); },
85
- };
86
- return [p1, p2];
87
- };
88
- exports.createEventPipe = createEventPipe;
89
- var createEventEmitter = function () {
90
- var emitter = (0, eventmit_1.eventmit)();
91
- var emit = function (e) {
92
- emitter.emit(e);
93
- };
94
- var on = function (h) {
95
- emitter.on(h);
96
- };
97
- return {
98
- emit: emit,
99
- on: on,
100
- };
101
- };
102
- exports.createEventEmitter = createEventEmitter;
@@ -1,5 +0,0 @@
1
- import { Controller } from "../controller";
2
- export declare const createLocalGame: (params?: {
3
- playerIDs?: string[];
4
- debug?: boolean;
5
- }) => Controller;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLocalGame = void 0;
4
- var controller_1 = require("../controller");
5
- var createLocalGame = function (params) {
6
- var _a;
7
- var _b = (0, controller_1.createEventPipe)(), ce1 = _b[0], pe1 = _b[1];
8
- var _c = (0, controller_1.createEventPipe)(), ce2 = _c[0], pe2 = _c[1];
9
- var _d = (0, controller_1.createEventPipe)(), ce3 = _d[0], pe3 = _d[1];
10
- var _e = (0, controller_1.createEventPipe)(), ce4 = _e[0], pe4 = _e[1];
11
- var playerIDs = (_a = params === null || params === void 0 ? void 0 : params.playerIDs) !== null && _a !== void 0 ? _a : [
12
- "player-1",
13
- "player-2",
14
- "player-3",
15
- "player-4",
16
- ];
17
- new controller_1.Player(playerIDs[0], pe1);
18
- new controller_1.Player(playerIDs[1], pe2);
19
- new controller_1.Player(playerIDs[2], pe3);
20
- new controller_1.Player(playerIDs[3], pe4);
21
- var players = [
22
- { handler: ce1, id: playerIDs[0] },
23
- { handler: ce2, id: playerIDs[1] },
24
- { handler: ce3, id: playerIDs[2] },
25
- { handler: ce4, id: playerIDs[3] },
26
- ];
27
- return new controller_1.Controller(players, { debug: params === null || params === void 0 ? void 0 : params.debug });
28
- };
29
- exports.createLocalGame = createLocalGame;
@@ -1,10 +0,0 @@
1
- export * from "./events";
2
- export * from "./managers";
3
- export * from "./river";
4
- export * from "./state-machine";
5
- export * from "./wall";
6
- export * from "./controller";
7
- export * from "./player";
8
- export * from "./replay";
9
- export * from "./game";
10
- export * from "./player-efficiency";
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./events"), exports);
18
- __exportStar(require("./managers"), exports);
19
- __exportStar(require("./river"), exports);
20
- __exportStar(require("./state-machine"), exports);
21
- __exportStar(require("./wall"), exports);
22
- __exportStar(require("./controller"), exports);
23
- __exportStar(require("./player"), exports);
24
- __exportStar(require("./replay"), exports);
25
- __exportStar(require("./game"), exports);
26
- __exportStar(require("./player-efficiency"), exports);
@@ -1,83 +0,0 @@
1
- import { Wind, Round } from "../core/constants";
2
- import { Type, Tile } from "../core/parser";
3
- export declare class ScoreManager {
4
- private reachValue;
5
- private m;
6
- constructor(initial: {
7
- [key: string]: number;
8
- });
9
- get summary(): {
10
- [key: string]: number;
11
- };
12
- reach(id: string): void;
13
- restoreReachStick(id: string): void;
14
- update(result: {
15
- "1w": number;
16
- "2w": number;
17
- "3w": number;
18
- "4w": number;
19
- }, windMap: {
20
- [key: string]: Wind;
21
- }): void;
22
- }
23
- export declare class PlaceManager {
24
- private pToW;
25
- private wToP;
26
- round: Round;
27
- sticks: {
28
- reach: number;
29
- dead: number;
30
- };
31
- constructor(initial: {
32
- [key: string]: Wind;
33
- }, params?: {
34
- round: Round;
35
- sticks: {
36
- reach: number;
37
- dead: number;
38
- };
39
- });
40
- private update;
41
- incrementDeadStick(): void;
42
- incrementReachStick(): void;
43
- nextRound(): void;
44
- decrementReachStick(): void;
45
- resetDeadStick(): void;
46
- resetReachStick(): void;
47
- is(r: Round): boolean;
48
- wind(id: string): "1w" | "2w" | "3w" | "4w";
49
- playerID(w: Wind): string;
50
- get playerMap(): {
51
- [key: string]: "1w" | "2w" | "3w" | "4w";
52
- };
53
- }
54
- export declare const nextRound: (r: Round) => Round;
55
- export declare const prevRound: (r: Round) => "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
56
- export declare const nextWind: (w: Wind) => Wind;
57
- export declare const prevWind: (w: Wind) => Wind;
58
- export declare function shuffle<T>(array: T[]): T[];
59
- export declare class Counter {
60
- disable: boolean;
61
- private c;
62
- safeMap: {
63
- "1w": {
64
- [name: string]: boolean;
65
- };
66
- "2w": {
67
- [name: string]: boolean;
68
- };
69
- "3w": {
70
- [name: string]: boolean;
71
- };
72
- "4w": {
73
- [name: string]: boolean;
74
- };
75
- };
76
- constructor(disable?: boolean);
77
- get(t: Tile): number;
78
- dec(...tiles: Tile[]): void;
79
- addTileToSafeMap(t: Tile, targetUser: Wind): void;
80
- isSafeTile(k: Type, n: number, targetUser: Wind): boolean;
81
- private key;
82
- reset(): void;
83
- }
@@ -1,194 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Counter = exports.prevWind = exports.nextWind = exports.prevRound = exports.nextRound = exports.PlaceManager = exports.ScoreManager = void 0;
4
- exports.shuffle = shuffle;
5
- var myassert_1 = require("../myassert");
6
- var constants_1 = require("../core/constants");
7
- var calculator_1 = require("../calculator");
8
- var parser_1 = require("../core/parser");
9
- var ScoreManager = (function () {
10
- function ScoreManager(initial) {
11
- this.reachValue = 1000;
12
- this.m = initial;
13
- }
14
- Object.defineProperty(ScoreManager.prototype, "summary", {
15
- get: function () {
16
- return structuredClone(this.m);
17
- },
18
- enumerable: false,
19
- configurable: true
20
- });
21
- ScoreManager.prototype.reach = function (id) {
22
- this.m[id] -= this.reachValue;
23
- };
24
- ScoreManager.prototype.restoreReachStick = function (id) {
25
- this.m[id] += this.reachValue;
26
- };
27
- ScoreManager.prototype.update = function (result, windMap) {
28
- for (var id in windMap) {
29
- var w = windMap[id];
30
- var point = result[w];
31
- this.m[id] += point;
32
- }
33
- };
34
- return ScoreManager;
35
- }());
36
- exports.ScoreManager = ScoreManager;
37
- var PlaceManager = (function () {
38
- function PlaceManager(initial, params) {
39
- var _a, _b;
40
- this.pToW = {};
41
- this.wToP = (0, calculator_1.createWindMap)("");
42
- this.round = (_a = params === null || params === void 0 ? void 0 : params.round) !== null && _a !== void 0 ? _a : "1w1";
43
- this.sticks = (_b = params === null || params === void 0 ? void 0 : params.sticks) !== null && _b !== void 0 ? _b : { reach: 0, dead: 0 };
44
- this.pToW = initial;
45
- for (var playerID in this.pToW)
46
- this.wToP[this.pToW[playerID]] = playerID;
47
- }
48
- PlaceManager.prototype.update = function () {
49
- for (var playerID in this.pToW) {
50
- var next = (0, exports.nextWind)(this.pToW[playerID]);
51
- this.pToW[playerID] = next;
52
- this.wToP[next] = playerID;
53
- }
54
- };
55
- PlaceManager.prototype.incrementDeadStick = function () {
56
- this.sticks.dead++;
57
- };
58
- PlaceManager.prototype.incrementReachStick = function () {
59
- this.sticks.reach++;
60
- };
61
- PlaceManager.prototype.nextRound = function () {
62
- var next = (0, exports.nextRound)(this.round);
63
- this.round = next;
64
- this.update();
65
- };
66
- PlaceManager.prototype.decrementReachStick = function () {
67
- this.sticks.reach--;
68
- (0, myassert_1.assert)(this.sticks.reach >= 0);
69
- };
70
- PlaceManager.prototype.resetDeadStick = function () {
71
- this.sticks.dead = 0;
72
- };
73
- PlaceManager.prototype.resetReachStick = function () {
74
- this.sticks.reach = 0;
75
- };
76
- PlaceManager.prototype.is = function (r) {
77
- return this.round == r;
78
- };
79
- PlaceManager.prototype.wind = function (id) {
80
- return this.pToW[id];
81
- };
82
- PlaceManager.prototype.playerID = function (w) {
83
- return this.wToP[w];
84
- };
85
- Object.defineProperty(PlaceManager.prototype, "playerMap", {
86
- get: function () {
87
- return structuredClone(this.pToW);
88
- },
89
- enumerable: false,
90
- configurable: true
91
- });
92
- return PlaceManager;
93
- }());
94
- exports.PlaceManager = PlaceManager;
95
- var nextRound = function (r) {
96
- var w = r.substring(0, 2);
97
- var n = Number(r.substring(2, 3));
98
- if (n == 4) {
99
- n = 1;
100
- w = (0, exports.nextWind)(w);
101
- }
102
- else
103
- n++;
104
- return "".concat(w).concat(n);
105
- };
106
- exports.nextRound = nextRound;
107
- var prevRound = function (r) {
108
- return (0, exports.nextRound)((0, exports.nextRound)((0, exports.nextRound)(r)));
109
- };
110
- exports.prevRound = prevRound;
111
- var nextWind = function (w) {
112
- var n = Number(w.toString()[0]);
113
- if (n == 4)
114
- n = 1;
115
- else
116
- n++;
117
- return "".concat(n, "w");
118
- };
119
- exports.nextWind = nextWind;
120
- var prevWind = function (w) {
121
- return (0, exports.nextWind)((0, exports.nextWind)((0, exports.nextWind)(w)));
122
- };
123
- exports.prevWind = prevWind;
124
- function shuffle(array) {
125
- var _a;
126
- for (var i = array.length - 1; i > 0; i--) {
127
- var j = Math.floor(Math.random() * (i + 1));
128
- _a = [array[j], array[i]], array[i] = _a[0], array[j] = _a[1];
129
- }
130
- return array;
131
- }
132
- var Counter = (function () {
133
- function Counter(disable) {
134
- var _a;
135
- if (disable === void 0) { disable = false; }
136
- this.disable = disable;
137
- this.c = (_a = {},
138
- _a[constants_1.TYPE.M] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
139
- _a[constants_1.TYPE.S] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
140
- _a[constants_1.TYPE.P] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
141
- _a[constants_1.TYPE.Z] = [0, 4, 4, 4, 4, 4, 4, 4],
142
- _a);
143
- this.safeMap = (0, calculator_1.createWindMap)({}, true);
144
- }
145
- Counter.prototype.get = function (t) {
146
- if (t.t == constants_1.TYPE.BACK)
147
- return 0;
148
- if ((0, parser_1.isNum0)(t))
149
- return this.c[t.t][5];
150
- return this.c[t.t][t.n];
151
- };
152
- Counter.prototype.dec = function () {
153
- var tiles = [];
154
- for (var _i = 0; _i < arguments.length; _i++) {
155
- tiles[_i] = arguments[_i];
156
- }
157
- if (this.disable)
158
- return;
159
- for (var _a = 0, tiles_1 = tiles; _a < tiles_1.length; _a++) {
160
- var t = tiles_1[_a];
161
- if (t.t == constants_1.TYPE.BACK)
162
- continue;
163
- if (this.get(t) <= 0)
164
- throw new Error("cannot decrease ".concat(t.toString(), " due to zero"));
165
- this.c[t.t][t.n] -= 1;
166
- if ((0, parser_1.isNum0)(t))
167
- this.c[t.t][5] -= 1;
168
- }
169
- };
170
- Counter.prototype.addTileToSafeMap = function (t, targetUser) {
171
- if (this.disable)
172
- return;
173
- this.safeMap[targetUser][this.key(t.t, t.n)] = true;
174
- };
175
- Counter.prototype.isSafeTile = function (k, n, targetUser) {
176
- return this.safeMap[targetUser][this.key(k, n)];
177
- };
178
- Counter.prototype.key = function (k, n) {
179
- if (n == 0)
180
- n = 5;
181
- return "".concat(k).concat(n);
182
- };
183
- Counter.prototype.reset = function () {
184
- var _a;
185
- this.c = (_a = {},
186
- _a[constants_1.TYPE.M] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
187
- _a[constants_1.TYPE.S] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
188
- _a[constants_1.TYPE.P] = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
189
- _a[constants_1.TYPE.Z] = [0, 4, 4, 4, 4, 4, 4, 4],
190
- _a);
191
- };
192
- return Counter;
193
- }());
194
- exports.Counter = Counter;
@@ -1,24 +0,0 @@
1
- import { Wind } from "../core/constants";
2
- import { Tile } from "../core/parser";
3
- import { Candidate } from "../calculator";
4
- import { Counter } from "./managers";
5
- export interface PlayerCandidate {
6
- tile: Tile;
7
- sum: number;
8
- candidates: {
9
- tile: Tile;
10
- n: number;
11
- }[];
12
- shanten: number;
13
- }
14
- export declare class PlayerEfficiency {
15
- static calcPlayerCandidates(counter: Counter, candidates: Candidate[]): PlayerCandidate[];
16
- static selectMinPriority(c: Counter, playerCandidates: PlayerCandidate[], doras: Tile[]): PlayerCandidate;
17
- private static calcPriority;
18
- }
19
- export declare class RiskRank {
20
- static selectTile(c: Counter, targetUsers: Wind[], tiles: Tile[]): Tile;
21
- static rank(c: Counter, targetUsers: Wind[], t: Tile): number;
22
- static rankZ(c: Counter, targetUser: Wind, t: Tile): number;
23
- static rankN(c: Counter, targetUser: Wind, t: Tile): 0 | 3 | 4 | 8 | 5 | 6 | 12;
24
- }