mj-simulator 0.1.0
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/data/honor-table.bin +0 -0
- package/data/suit-table.bin +0 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +278 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/constants.d.ts +13 -0
- package/dist/core/constants.js +19 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/hand.d.ts +37 -0
- package/dist/core/hand.js +105 -0
- package/dist/core/hand.js.map +1 -0
- package/dist/core/remaining.d.ts +12 -0
- package/dist/core/remaining.js +26 -0
- package/dist/core/remaining.js.map +1 -0
- package/dist/core/tile.d.ts +45 -0
- package/dist/core/tile.js +140 -0
- package/dist/core/tile.js.map +1 -0
- package/dist/ev/ev-calculator.d.ts +10 -0
- package/dist/ev/ev-calculator.js +257 -0
- package/dist/ev/ev-calculator.js.map +1 -0
- package/dist/ev/types.d.ts +16 -0
- package/dist/ev/types.js +2 -0
- package/dist/ev/types.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +11 -0
- package/dist/init.js +24 -0
- package/dist/init.js.map +1 -0
- package/dist/mc/simulator.d.ts +18 -0
- package/dist/mc/simulator.js +11 -0
- package/dist/mc/simulator.js.map +1 -0
- package/dist/mc/wasm-bridge.d.ts +30 -0
- package/dist/mc/wasm-bridge.js +56 -0
- package/dist/mc/wasm-bridge.js.map +1 -0
- package/dist/models/danger.d.ts +34 -0
- package/dist/models/danger.js +147 -0
- package/dist/models/danger.js.map +1 -0
- package/dist/models/evaluation.d.ts +31 -0
- package/dist/models/evaluation.js +46 -0
- package/dist/models/evaluation.js.map +1 -0
- package/dist/scoring/decomposer.d.ts +7 -0
- package/dist/scoring/decomposer.js +106 -0
- package/dist/scoring/decomposer.js.map +1 -0
- package/dist/scoring/fu.d.ts +5 -0
- package/dist/scoring/fu.js +47 -0
- package/dist/scoring/fu.js.map +1 -0
- package/dist/scoring/score-calculator.d.ts +11 -0
- package/dist/scoring/score-calculator.js +164 -0
- package/dist/scoring/score-calculator.js.map +1 -0
- package/dist/scoring/types.d.ts +38 -0
- package/dist/scoring/types.js +2 -0
- package/dist/scoring/types.js.map +1 -0
- package/dist/scoring/wait-type.d.ts +11 -0
- package/dist/scoring/wait-type.js +65 -0
- package/dist/scoring/wait-type.js.map +1 -0
- package/dist/scoring/yaku.d.ts +7 -0
- package/dist/scoring/yaku.js +490 -0
- package/dist/scoring/yaku.js.map +1 -0
- package/dist/shanten/init.d.ts +9 -0
- package/dist/shanten/init.js +26 -0
- package/dist/shanten/init.js.map +1 -0
- package/dist/shanten/lookup-table.d.ts +37 -0
- package/dist/shanten/lookup-table.js +228 -0
- package/dist/shanten/lookup-table.js.map +1 -0
- package/dist/shanten/shanten-calculator.d.ts +18 -0
- package/dist/shanten/shanten-calculator.js +101 -0
- package/dist/shanten/shanten-calculator.js.map +1 -0
- package/dist/shanten/ukeire.d.ts +35 -0
- package/dist/shanten/ukeire.js +103 -0
- package/dist/shanten/ukeire.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-client.d.ts +42 -0
- package/dist/worker-client.js +83 -0
- package/dist/worker-client.js.map +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +67 -0
- package/dist/worker.js.map +1 -0
- package/node_modules/mj-mc-wasm/mj_mc_wasm.d.ts +57 -0
- package/node_modules/mj-mc-wasm/mj_mc_wasm.js +235 -0
- package/node_modules/mj-mc-wasm/mj_mc_wasm_bg.wasm +0 -0
- package/node_modules/mj-mc-wasm/package.json +15 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-client.js","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAuBA,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf,MAAM,OAAO,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AAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAA0B,CAAC;IAC7F,CAAC;IAED,gBAAgB;IAChB,SAAS;QACP,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAEO,OAAO,CAAC,IAAY,EAAE,OAAgB;QAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import { init } from "./init.js";
|
|
3
|
+
import { calculateShanten } from "./shanten/shanten-calculator.js";
|
|
4
|
+
import { calculateUkeire13, calculateUkeire14 } from "./shanten/ukeire.js";
|
|
5
|
+
import { calculateEV14 } from "./ev/ev-calculator.js";
|
|
6
|
+
import { simulateDiscards } from "./mc/simulator.js";
|
|
7
|
+
import { evaluateDiscards } from "./models/evaluation.js";
|
|
8
|
+
function reply(type, requestId, payload) {
|
|
9
|
+
self.postMessage({ type, requestId, payload });
|
|
10
|
+
}
|
|
11
|
+
function replyError(requestId, message) {
|
|
12
|
+
self.postMessage({ type: "error", requestId, payload: { message } });
|
|
13
|
+
}
|
|
14
|
+
self.onmessage = async (e) => {
|
|
15
|
+
const { type, requestId, payload } = e.data;
|
|
16
|
+
try {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case "init": {
|
|
19
|
+
await init({
|
|
20
|
+
suitTableUrl: payload.suitTableUrl,
|
|
21
|
+
honorTableUrl: payload.honorTableUrl,
|
|
22
|
+
wasmUrl: payload.wasmUrl,
|
|
23
|
+
});
|
|
24
|
+
reply("ready", requestId, null);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case "shanten": {
|
|
28
|
+
const result = calculateShanten(payload.hand);
|
|
29
|
+
reply("shanten", requestId, result);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "ukeire13": {
|
|
33
|
+
const result = calculateUkeire13(payload.hand, payload.remaining, payload.options);
|
|
34
|
+
reply("ukeire13", requestId, result);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "ukeire14": {
|
|
38
|
+
const result = calculateUkeire14(payload.hand, payload.remaining, payload.options);
|
|
39
|
+
reply("ukeire14", requestId, result);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "ev": {
|
|
43
|
+
const result = calculateEV14(payload.hand, payload.options);
|
|
44
|
+
reply("ev", requestId, result);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "simulate": {
|
|
48
|
+
const result = simulateDiscards(payload.hand, payload.options);
|
|
49
|
+
reply("simulate", requestId, result);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "evaluate": {
|
|
53
|
+
const mcResults = simulateDiscards(payload.hand, payload.mcOptions);
|
|
54
|
+
const evalResults = evaluateDiscards(payload.hand, mcResults, payload.evalOptions);
|
|
55
|
+
reply("evaluate", requestId, evalResults);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
replyError(requestId, `Unknown message type: ${type}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
64
|
+
replyError(requestId, message);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,SAAS,KAAK,CAAC,IAAY,EAAE,SAA6B,EAAE,OAAgB;IAC1E,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,UAAU,CAAC,SAA6B,EAAE,OAAe;IAChE,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,CAAC,SAAS,GAAG,KAAK,EAAE,CAAe,EAAE,EAAE;IACzC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;IAE5C,IAAI,CAAC;QACH,QAAQ,I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BAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC/D,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;gBACrC,MAAM;YACR,CAAC;YAED,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;gBACpE,MAAM,WAAW,GAAG,gBAAgB,CAClC,OAAO,CAAC,IAAI,EACZ,SAAS,EACT,OAAO,CAAC,WAAW,CACpB,CAAC;gBACF,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;gBAC1C,MAAM;YACR,CAAC;YAED;gBACE,UAAU,CAAC,SAAS,EAAE,yBAAyB,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* テーブルを初期化する(JSから1回呼ぶ)
|
|
6
|
+
*/
|
|
7
|
+
export function init_tables(suit_table: Int8Array, honor_table: Int8Array): void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* シャンテン数を計算する
|
|
11
|
+
*/
|
|
12
|
+
export function shanten(hand: Uint8Array): number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* MCシミュレーションを実行する(スコア計算はRust内で完結)
|
|
16
|
+
*/
|
|
17
|
+
export function simulate_discards(hand_arr: Uint8Array, remaining_arr: Uint8Array, turns_left: number, num_sims: number, use_riichi: boolean, seat_wind: number, round_wind: number, dora_indicators: Uint8Array, use_red_dora: boolean, initial_riichi: boolean, ura_dora_count: number): any;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* テーブルが初期化済みかどうか
|
|
21
|
+
*/
|
|
22
|
+
export function tables_ready(): boolean;
|
|
23
|
+
|
|
24
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
25
|
+
|
|
26
|
+
export interface InitOutput {
|
|
27
|
+
readonly memory: WebAssembly.Memory;
|
|
28
|
+
readonly init_tables: (a: number, b: number, c: number, d: number) => void;
|
|
29
|
+
readonly shanten: (a: number, b: number) => number;
|
|
30
|
+
readonly simulate_discards: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => any;
|
|
31
|
+
readonly tables_ready: () => number;
|
|
32
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
33
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
34
|
+
readonly __wbindgen_start: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
41
|
+
* a precompiled `WebAssembly.Module`.
|
|
42
|
+
*
|
|
43
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
44
|
+
*
|
|
45
|
+
* @returns {InitOutput}
|
|
46
|
+
*/
|
|
47
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
51
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
52
|
+
*
|
|
53
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<InitOutput>}
|
|
56
|
+
*/
|
|
57
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/* @ts-self-types="./mj_mc_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* テーブルを初期化する(JSから1回呼ぶ)
|
|
5
|
+
* @param {Int8Array} suit_table
|
|
6
|
+
* @param {Int8Array} honor_table
|
|
7
|
+
*/
|
|
8
|
+
export function init_tables(suit_table, honor_table) {
|
|
9
|
+
const ptr0 = passArray8ToWasm0(suit_table, wasm.__wbindgen_malloc);
|
|
10
|
+
const len0 = WASM_VECTOR_LEN;
|
|
11
|
+
const ptr1 = passArray8ToWasm0(honor_table, wasm.__wbindgen_malloc);
|
|
12
|
+
const len1 = WASM_VECTOR_LEN;
|
|
13
|
+
wasm.init_tables(ptr0, len0, ptr1, len1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* シャンテン数を計算する
|
|
18
|
+
* @param {Uint8Array} hand
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
export function shanten(hand) {
|
|
22
|
+
const ptr0 = passArray8ToWasm0(hand, wasm.__wbindgen_malloc);
|
|
23
|
+
const len0 = WASM_VECTOR_LEN;
|
|
24
|
+
const ret = wasm.shanten(ptr0, len0);
|
|
25
|
+
return ret;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* MCシミュレーションを実行する(スコア計算はRust内で完結)
|
|
30
|
+
* @param {Uint8Array} hand_arr
|
|
31
|
+
* @param {Uint8Array} remaining_arr
|
|
32
|
+
* @param {number} turns_left
|
|
33
|
+
* @param {number} num_sims
|
|
34
|
+
* @param {boolean} use_riichi
|
|
35
|
+
* @param {number} seat_wind
|
|
36
|
+
* @param {number} round_wind
|
|
37
|
+
* @param {Uint8Array} dora_indicators
|
|
38
|
+
* @param {boolean} use_red_dora
|
|
39
|
+
* @param {boolean} initial_riichi
|
|
40
|
+
* @param {number} ura_dora_count
|
|
41
|
+
* @returns {any}
|
|
42
|
+
*/
|
|
43
|
+
export function simulate_discards(hand_arr, remaining_arr, turns_left, num_sims, use_riichi, seat_wind, round_wind, dora_indicators, use_red_dora, initial_riichi, ura_dora_count) {
|
|
44
|
+
const ptr0 = passArray8ToWasm0(hand_arr, wasm.__wbindgen_malloc);
|
|
45
|
+
const len0 = WASM_VECTOR_LEN;
|
|
46
|
+
const ptr1 = passArray8ToWasm0(remaining_arr, wasm.__wbindgen_malloc);
|
|
47
|
+
const len1 = WASM_VECTOR_LEN;
|
|
48
|
+
const ptr2 = passArray8ToWasm0(dora_indicators, wasm.__wbindgen_malloc);
|
|
49
|
+
const len2 = WASM_VECTOR_LEN;
|
|
50
|
+
const ret = wasm.simulate_discards(ptr0, len0, ptr1, len1, turns_left, num_sims, use_riichi, seat_wind, round_wind, ptr2, len2, use_red_dora, initial_riichi, ura_dora_count);
|
|
51
|
+
return ret;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* テーブルが初期化済みかどうか
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
export function tables_ready() {
|
|
59
|
+
const ret = wasm.tables_ready();
|
|
60
|
+
return ret !== 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function __wbg_get_imports() {
|
|
64
|
+
const import0 = {
|
|
65
|
+
__proto__: null,
|
|
66
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
67
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
68
|
+
},
|
|
69
|
+
__wbg_new_361308b2356cecd0: function() {
|
|
70
|
+
const ret = new Object();
|
|
71
|
+
return ret;
|
|
72
|
+
},
|
|
73
|
+
__wbg_new_3eb36ae241fe6f44: function() {
|
|
74
|
+
const ret = new Array();
|
|
75
|
+
return ret;
|
|
76
|
+
},
|
|
77
|
+
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
78
|
+
arg0[arg1] = arg2;
|
|
79
|
+
},
|
|
80
|
+
__wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
|
|
81
|
+
arg0[arg1 >>> 0] = arg2;
|
|
82
|
+
},
|
|
83
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
84
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
85
|
+
const ret = arg0;
|
|
86
|
+
return ret;
|
|
87
|
+
},
|
|
88
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
89
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
90
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
91
|
+
return ret;
|
|
92
|
+
},
|
|
93
|
+
__wbindgen_init_externref_table: function() {
|
|
94
|
+
const table = wasm.__wbindgen_externrefs;
|
|
95
|
+
const offset = table.grow(4);
|
|
96
|
+
table.set(0, undefined);
|
|
97
|
+
table.set(offset + 0, undefined);
|
|
98
|
+
table.set(offset + 1, null);
|
|
99
|
+
table.set(offset + 2, true);
|
|
100
|
+
table.set(offset + 3, false);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
__proto__: null,
|
|
105
|
+
"./mj_mc_wasm_bg.js": import0,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getStringFromWasm0(ptr, len) {
|
|
110
|
+
ptr = ptr >>> 0;
|
|
111
|
+
return decodeText(ptr, len);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let cachedUint8ArrayMemory0 = null;
|
|
115
|
+
function getUint8ArrayMemory0() {
|
|
116
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
117
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
118
|
+
}
|
|
119
|
+
return cachedUint8ArrayMemory0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
123
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
124
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
125
|
+
WASM_VECTOR_LEN = arg.length;
|
|
126
|
+
return ptr;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
130
|
+
cachedTextDecoder.decode();
|
|
131
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
132
|
+
let numBytesDecoded = 0;
|
|
133
|
+
function decodeText(ptr, len) {
|
|
134
|
+
numBytesDecoded += len;
|
|
135
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
136
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
137
|
+
cachedTextDecoder.decode();
|
|
138
|
+
numBytesDecoded = len;
|
|
139
|
+
}
|
|
140
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let WASM_VECTOR_LEN = 0;
|
|
144
|
+
|
|
145
|
+
let wasmModule, wasm;
|
|
146
|
+
function __wbg_finalize_init(instance, module) {
|
|
147
|
+
wasm = instance.exports;
|
|
148
|
+
wasmModule = module;
|
|
149
|
+
cachedUint8ArrayMemory0 = null;
|
|
150
|
+
wasm.__wbindgen_start();
|
|
151
|
+
return wasm;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function __wbg_load(module, imports) {
|
|
155
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
156
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
157
|
+
try {
|
|
158
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
161
|
+
|
|
162
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
163
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
164
|
+
|
|
165
|
+
} else { throw e; }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const bytes = await module.arrayBuffer();
|
|
170
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
171
|
+
} else {
|
|
172
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
173
|
+
|
|
174
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
175
|
+
return { instance, module };
|
|
176
|
+
} else {
|
|
177
|
+
return instance;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function expectedResponseType(type) {
|
|
182
|
+
switch (type) {
|
|
183
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function initSync(module) {
|
|
190
|
+
if (wasm !== undefined) return wasm;
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if (module !== undefined) {
|
|
194
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
195
|
+
({module} = module)
|
|
196
|
+
} else {
|
|
197
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const imports = __wbg_get_imports();
|
|
202
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
203
|
+
module = new WebAssembly.Module(module);
|
|
204
|
+
}
|
|
205
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
206
|
+
return __wbg_finalize_init(instance, module);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function __wbg_init(module_or_path) {
|
|
210
|
+
if (wasm !== undefined) return wasm;
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if (module_or_path !== undefined) {
|
|
214
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
215
|
+
({module_or_path} = module_or_path)
|
|
216
|
+
} else {
|
|
217
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (module_or_path === undefined) {
|
|
222
|
+
module_or_path = new URL('mj_mc_wasm_bg.wasm', import.meta.url);
|
|
223
|
+
}
|
|
224
|
+
const imports = __wbg_get_imports();
|
|
225
|
+
|
|
226
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
227
|
+
module_or_path = fetch(module_or_path);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
231
|
+
|
|
232
|
+
return __wbg_finalize_init(instance, module);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mj-mc-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"files": [
|
|
6
|
+
"mj_mc_wasm_bg.wasm",
|
|
7
|
+
"mj_mc_wasm.js",
|
|
8
|
+
"mj_mc_wasm.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"main": "mj_mc_wasm.js",
|
|
11
|
+
"types": "mj_mc_wasm.d.ts",
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./snippets/*"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mj-simulator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "麻雀シミュレーター - シャンテン数計算・受入解析・MCシミュレーション",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./worker": {
|
|
14
|
+
"types": "./dist/worker.d.ts",
|
|
15
|
+
"default": "./dist/worker.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"data"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build:wasm": "cd crates/mj-mc-wasm && wasm-pack build --target web --release",
|
|
24
|
+
"build": "npm run build:wasm && tsc",
|
|
25
|
+
"build:ts": "tsc",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"dev": "tsx src/cli.ts",
|
|
29
|
+
"generate-tables": "tsx scripts/generate-tables.ts",
|
|
30
|
+
"prepublishOnly": "npm run build:ts"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.2.2",
|
|
34
|
+
"tsx": "^4.19.0",
|
|
35
|
+
"typescript": "^5.7.0",
|
|
36
|
+
"vitest": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"mj-mc-wasm": "file:crates/mj-mc-wasm/pkg"
|
|
40
|
+
},
|
|
41
|
+
"bundleDependencies": [
|
|
42
|
+
"mj-mc-wasm"
|
|
43
|
+
]
|
|
44
|
+
}
|