mahjong-seatings-rs-node 2.0.1 → 2.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/README.md CHANGED
@@ -34,7 +34,7 @@ console.log(
34
34
  ],
35
35
  groupsCount: 1,
36
36
  randFactor: 1234455,
37
- windShuffle: 0, // 0 == WindShuffle::Random, 1 == WindShuffle::Balanced
37
+ windShuffle: "random", // other options: 'balanced'
38
38
  }),
39
39
  );
40
40
 
@@ -57,7 +57,7 @@ console.log(
57
57
  ],
58
58
  step: 2,
59
59
  randFactor: 1234455,
60
- windShuffle: 0, // 0 == WindShuffle::Random, 1 == WindShuffle::Balanced
60
+ windShuffle: "random", // other options: 'balanced'
61
61
  }),
62
62
  );
63
63
 
@@ -79,9 +79,37 @@ console.log(
79
79
  [5, 6, 7, 8],
80
80
  ],
81
81
  randFactor: 1234455,
82
- windShuffle: 0, // 0 == WindShuffle::Random, 1 == WindShuffle::Balanced
82
+ windShuffle: "random", // other options: 'balanced'
83
83
  }),
84
84
  );
85
85
  ```
86
86
 
87
87
  Note that returned lists contain player ids and their rating. First four elements are first table, next four are second table, etc.## Riichi-rs-node
88
+
89
+ In case you already have the prepared seating and just want to randomize seatings by wind, you can use `update_wind_placing_only` function:
90
+
91
+ ```javascript
92
+ const { update_wind_placing_only } = require("mahjong-seatings-rs-node");
93
+
94
+ const updatedSeatings = update_wind_placing_only({
95
+ playersMap: {
96
+ 1: 1510,
97
+ 2: 1508,
98
+ 3: 1506,
99
+ 4: 1504,
100
+ 5: 1496,
101
+ 6: 1494,
102
+ 7: 1492,
103
+ 8: 1490,
104
+ },
105
+ previousSeatings: [
106
+ [1, 2, 3, 4],
107
+ [5, 6, 7, 8],
108
+ ],
109
+ windShuffle: "random", // other options: 'balanced', 'prescripted'
110
+ });
111
+
112
+ console.log(updatedSeatings);
113
+ ```
114
+
115
+ Note that `windShuffle: 'prescripted'` option just returns input array as is, considering it being already shuffled manually.
@@ -1,10 +1,6 @@
1
1
  export type PlayersMap = Record<string | number, number>;
2
2
  export type Seating = Array<[number, number]>;
3
- export const enum WindShuffle {
4
- Random = 0,
5
- Balanced = 1,
6
- Prescripted = 2,
7
- }
3
+ export type WindShuffle = "random" | "balanced" | "prescripted";
8
4
 
9
5
  export type ShuffledSeatingInput = {
10
6
  playersMap: PlayersMap;
@@ -29,6 +25,14 @@ export type SwissSeatingInput = {
29
25
  windShuffle: WindShuffle;
30
26
  };
31
27
 
28
+ export type UpdateWindPlacingInput = {
29
+ playersMap: PlayersMap;
30
+ previousSeatings: number[][];
31
+ randFactor: number;
32
+ windShuffle: WindShuffle;
33
+ };
34
+
32
35
  export function make_seating_shuffled(val: ShuffledSeatingInput): Seating;
33
36
  export function make_seating_interval(val: IntervalSeatingInput): Seating;
34
37
  export function make_seating_swiss(val: SwissSeatingInput): Seating;
38
+ export function update_wind_placing_only(val: UpdateWindPlacingInput): Seating;
@@ -27,6 +27,16 @@ function make_seating_swiss(val) {
27
27
  return ret;
28
28
  }
29
29
  exports.make_seating_swiss = make_seating_swiss;
30
+
31
+ /**
32
+ * @param {any} val
33
+ * @returns {any}
34
+ */
35
+ function update_wind_placing_only(val) {
36
+ const ret = wasm.update_wind_placing_only(val);
37
+ return ret;
38
+ }
39
+ exports.update_wind_placing_only = update_wind_placing_only;
30
40
  function __wbg_get_imports() {
31
41
  const import0 = {
32
42
  __proto__: null,
Binary file
@@ -1,5 +1,18 @@
1
1
  const orig = require("./mahjong_seatings_rs.js");
2
2
 
3
+ function _toWindShuffle(val) {
4
+ switch (val) {
5
+ case "random":
6
+ return 0;
7
+ case "balanced":
8
+ return 1;
9
+ case "prescripted":
10
+ return 2;
11
+ default:
12
+ return 0;
13
+ }
14
+ }
15
+
3
16
  module.exports = {
4
17
  make_seating_shuffled: function (val) {
5
18
  const input = {
@@ -10,7 +23,7 @@ module.exports = {
10
23
  previous_seatings: val.previousSeatings,
11
24
  groups_count: val.groupsCount,
12
25
  rand_factor: val.randFactor,
13
- wind_shuffle: val.windShuffle,
26
+ wind_shuffle: _toWindShuffle(val.windShuffle),
14
27
  };
15
28
  return orig.make_seating_shuffled(input).result;
16
29
  },
@@ -24,7 +37,7 @@ module.exports = {
24
37
  previous_seatings: val.previousSeatings,
25
38
  step: val.step,
26
39
  rand_factor: val.randFactor,
27
- wind_shuffle: val.windShuffle,
40
+ wind_shuffle: _toWindShuffle(val.windShuffle),
28
41
  };
29
42
  return orig.make_seating_interval(input).result;
30
43
  },
@@ -37,8 +50,21 @@ module.exports = {
37
50
  ]),
38
51
  previous_seatings: val.previousSeatings,
39
52
  rand_factor: val.randFactor,
40
- wind_shuffle: val.windShuffle,
53
+ wind_shuffle: _toWindShuffle(val.windShuffle),
41
54
  };
42
55
  return orig.make_seating_swiss(input).result;
43
56
  },
57
+
58
+ update_wind_placing_only: function (val) {
59
+ const input = {
60
+ players_map: Object.entries(val.playersMap).map(([k, v]) => [
61
+ parseInt(k.toString(), 10),
62
+ v,
63
+ ]),
64
+ previous_seatings: val.previousSeatings,
65
+ rand_factor: val.randFactor,
66
+ wind_shuffle: _toWindShuffle(val.windShuffle),
67
+ };
68
+ return orig.update_wind_placing_only(input).result;
69
+ },
44
70
  };
@@ -1,5 +1,18 @@
1
1
  import orig from "./mahjong_seatings_rs.js";
2
2
 
3
+ function _toWindShuffle(val) {
4
+ switch (val) {
5
+ case "random":
6
+ return 0;
7
+ case "balanced":
8
+ return 1;
9
+ case "prescripted":
10
+ return 2;
11
+ default:
12
+ return 0;
13
+ }
14
+ }
15
+
3
16
  export function make_seating_shuffled(val) {
4
17
  const input = {
5
18
  players_map: Object.entries(val.playersMap).map(([k, v]) => [
@@ -9,6 +22,7 @@ export function make_seating_shuffled(val) {
9
22
  previous_seatings: val.previousSeatings,
10
23
  groups_count: val.groupsCount,
11
24
  rand_factor: val.randFactor,
25
+ wind_shuffle: _toWindShuffle(val.windShuffle),
12
26
  };
13
27
  return orig.make_seating_shuffled(input).result;
14
28
  }
@@ -19,8 +33,10 @@ export function make_seating_interval(val) {
19
33
  parseInt(k.toString(), 10),
20
34
  v,
21
35
  ]),
36
+ previous_seatings: val.previousSeatings,
22
37
  step: val.step,
23
38
  rand_factor: val.randFactor,
39
+ wind_shuffle: _toWindShuffle(val.windShuffle),
24
40
  };
25
41
  return orig.make_seating_interval(input).result;
26
42
  }
@@ -33,6 +49,20 @@ export function make_seating_swiss(val) {
33
49
  ]),
34
50
  previous_seatings: val.previousSeatings,
35
51
  rand_factor: val.randFactor,
52
+ wind_shuffle: _toWindShuffle(val.windShuffle),
36
53
  };
37
54
  return orig.make_seating_swiss(input).result;
38
55
  }
56
+
57
+ export function update_wind_placing_only(val) {
58
+ const input = {
59
+ players_map: Object.entries(val.playersMap).map(([k, v]) => [
60
+ parseInt(k.toString(), 10),
61
+ v,
62
+ ]),
63
+ previous_seatings: val.previousSeatings,
64
+ rand_factor: val.randFactor,
65
+ wind_shuffle: _toWindShuffle(val.windShuffle),
66
+ };
67
+ return orig.update_wind_placing_only(input).result;
68
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "Oleg Klimenko <me@ctizen.dev>"
5
5
  ],
6
- "version": "2.0.1",
6
+ "version": "2.1.0",
7
7
  "files": [
8
8
  "mahjong_seatings_rs_node.js",
9
9
  "mahjong_seatings_rs_node.mjs",