@gamepark/rules-api 7.0.0-beta.0 → 7.0.0-beta.2

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 (249) hide show
  1. package/dist/Action.js +1 -2
  2. package/dist/Bot.js +15 -37
  3. package/dist/Bot.js.map +1 -1
  4. package/dist/Competitive.js +3 -8
  5. package/dist/Competitive.js.map +1 -1
  6. package/dist/Eliminations.js +2 -5
  7. package/dist/Eliminations.js.map +1 -1
  8. package/dist/GameSetup.js +1 -2
  9. package/dist/HiddenInformation.js +2 -5
  10. package/dist/HiddenInformation.js.map +1 -1
  11. package/dist/LocalMovePreview.js +1 -4
  12. package/dist/LocalMovePreview.js.map +1 -1
  13. package/dist/RandomMove.js +1 -2
  14. package/dist/Rules.js +49 -56
  15. package/dist/Rules.js.map +1 -1
  16. package/dist/SecretInformation.js +2 -5
  17. package/dist/SecretInformation.js.map +1 -1
  18. package/dist/TimeLimit.js +1 -4
  19. package/dist/TimeLimit.js.map +1 -1
  20. package/dist/Undo.js +2 -5
  21. package/dist/Undo.js.map +1 -1
  22. package/dist/UnpredictableMove.js +1 -5
  23. package/dist/UnpredictableMove.js.map +1 -1
  24. package/dist/index.js +16 -32
  25. package/dist/index.js.map +1 -1
  26. package/dist/material/HiddenMaterialRules.js +125 -180
  27. package/dist/material/HiddenMaterialRules.js.map +1 -1
  28. package/dist/material/MaterialGame.js +1 -2
  29. package/dist/material/MaterialGameSetup.js +52 -70
  30. package/dist/material/MaterialGameSetup.js.map +1 -1
  31. package/dist/material/MaterialRules.js +186 -250
  32. package/dist/material/MaterialRules.js.map +1 -1
  33. package/dist/material/SecretMaterialRules.js +9 -35
  34. package/dist/material/SecretMaterialRules.js.map +1 -1
  35. package/dist/material/index.js +11 -27
  36. package/dist/material/index.js.map +1 -1
  37. package/dist/material/items/Material.js +177 -262
  38. package/dist/material/items/Material.js.map +1 -1
  39. package/dist/material/items/MaterialDeck.js +10 -36
  40. package/dist/material/items/MaterialDeck.js.map +1 -1
  41. package/dist/material/items/MaterialItem.js +1 -2
  42. package/dist/material/items/MaterialMoney.js +89 -141
  43. package/dist/material/items/MaterialMoney.js.map +1 -1
  44. package/dist/material/items/MaterialMutator.js +108 -145
  45. package/dist/material/items/MaterialMutator.js.map +1 -1
  46. package/dist/material/items/index.js +5 -21
  47. package/dist/material/items/index.js.map +1 -1
  48. package/dist/material/location/Location.js +1 -14
  49. package/dist/material/location/Location.js.map +1 -1
  50. package/dist/material/location/LocationBuilder.js +26 -41
  51. package/dist/material/location/LocationBuilder.js.map +1 -1
  52. package/dist/material/location/index.js +3 -19
  53. package/dist/material/location/index.js.map +1 -1
  54. package/dist/material/location/strategy/FillGapStrategy.js +9 -16
  55. package/dist/material/location/strategy/FillGapStrategy.js.map +1 -1
  56. package/dist/material/location/strategy/LocationStrategy.js +1 -2
  57. package/dist/material/location/strategy/PositiveSequenceStrategy.js +26 -35
  58. package/dist/material/location/strategy/PositiveSequenceStrategy.js.map +1 -1
  59. package/dist/material/location/strategy/StackingStrategy.js +15 -22
  60. package/dist/material/location/strategy/StackingStrategy.js.map +1 -1
  61. package/dist/material/location/strategy/index.js +5 -23
  62. package/dist/material/location/strategy/index.js.map +1 -1
  63. package/dist/material/memory/GameMemory.js +10 -14
  64. package/dist/material/memory/GameMemory.js.map +1 -1
  65. package/dist/material/memory/PlayerMemory.js +13 -18
  66. package/dist/material/memory/PlayerMemory.js.map +1 -1
  67. package/dist/material/memory/index.js +2 -18
  68. package/dist/material/memory/index.js.map +1 -1
  69. package/dist/material/moves/CustomMove.js +4 -9
  70. package/dist/material/moves/CustomMove.js.map +1 -1
  71. package/dist/material/moves/MaterialMove.js +1 -2
  72. package/dist/material/moves/MaterialMoveBuilder.js +16 -32
  73. package/dist/material/moves/MaterialMoveBuilder.js.map +1 -1
  74. package/dist/material/moves/MoveKind.js +2 -5
  75. package/dist/material/moves/MoveKind.js.map +1 -1
  76. package/dist/material/moves/index.js +7 -23
  77. package/dist/material/moves/index.js.map +1 -1
  78. package/dist/material/moves/items/CreateItem.js +6 -12
  79. package/dist/material/moves/items/CreateItem.js.map +1 -1
  80. package/dist/material/moves/items/CreateItemsAtOnce.js +6 -12
  81. package/dist/material/moves/items/CreateItemsAtOnce.js.map +1 -1
  82. package/dist/material/moves/items/DeleteItem.js +6 -12
  83. package/dist/material/moves/items/DeleteItem.js.map +1 -1
  84. package/dist/material/moves/items/DeleteItemsAtOnce.js +6 -12
  85. package/dist/material/moves/items/DeleteItemsAtOnce.js.map +1 -1
  86. package/dist/material/moves/items/ItemMove.js +1 -2
  87. package/dist/material/moves/items/ItemMoveType.js +2 -5
  88. package/dist/material/moves/items/ItemMoveType.js.map +1 -1
  89. package/dist/material/moves/items/MoveItem.js +6 -12
  90. package/dist/material/moves/items/MoveItem.js.map +1 -1
  91. package/dist/material/moves/items/MoveItemsAtOnce.js +6 -12
  92. package/dist/material/moves/items/MoveItemsAtOnce.js.map +1 -1
  93. package/dist/material/moves/items/RollItem.js +6 -12
  94. package/dist/material/moves/items/RollItem.js.map +1 -1
  95. package/dist/material/moves/items/SelectItem.js +6 -12
  96. package/dist/material/moves/items/SelectItem.js.map +1 -1
  97. package/dist/material/moves/items/Shuffle.js +7 -14
  98. package/dist/material/moves/items/Shuffle.js.map +1 -1
  99. package/dist/material/moves/items/index.js +11 -27
  100. package/dist/material/moves/items/index.js.map +1 -1
  101. package/dist/material/moves/local/CloseTutorialPopup.js +4 -7
  102. package/dist/material/moves/local/CloseTutorialPopup.js.map +1 -1
  103. package/dist/material/moves/local/DisplayHelp.js +2 -5
  104. package/dist/material/moves/local/DisplayHelp.js.map +1 -1
  105. package/dist/material/moves/local/DropItem.js +1 -2
  106. package/dist/material/moves/local/LocalMove.js +2 -5
  107. package/dist/material/moves/local/LocalMove.js.map +1 -1
  108. package/dist/material/moves/local/SetTutorialStep.js +4 -7
  109. package/dist/material/moves/local/SetTutorialStep.js.map +1 -1
  110. package/dist/material/moves/local/index.js +5 -21
  111. package/dist/material/moves/local/index.js.map +1 -1
  112. package/dist/material/moves/rules/EndGame.js +4 -7
  113. package/dist/material/moves/rules/EndGame.js.map +1 -1
  114. package/dist/material/moves/rules/EndPlayerTurn.js +4 -7
  115. package/dist/material/moves/rules/EndPlayerTurn.js.map +1 -1
  116. package/dist/material/moves/rules/RuleMove.js +3 -7
  117. package/dist/material/moves/rules/RuleMove.js.map +1 -1
  118. package/dist/material/moves/rules/StartPlayerTurn.js +4 -7
  119. package/dist/material/moves/rules/StartPlayerTurn.js.map +1 -1
  120. package/dist/material/moves/rules/StartRule.js +4 -7
  121. package/dist/material/moves/rules/StartRule.js.map +1 -1
  122. package/dist/material/moves/rules/StartSimultaneousRule.js +4 -7
  123. package/dist/material/moves/rules/StartSimultaneousRule.js.map +1 -1
  124. package/dist/material/moves/rules/index.js +6 -22
  125. package/dist/material/moves/rules/index.js.map +1 -1
  126. package/dist/material/rules/MaterialRulesPart.js +38 -63
  127. package/dist/material/rules/MaterialRulesPart.js.map +1 -1
  128. package/dist/material/rules/PlayerTurnRule.js +20 -52
  129. package/dist/material/rules/PlayerTurnRule.js.map +1 -1
  130. package/dist/material/rules/RuleStep.js +1 -2
  131. package/dist/material/rules/SimultaneousRule.js +19 -51
  132. package/dist/material/rules/SimultaneousRule.js.map +1 -1
  133. package/dist/material/rules/index.js +4 -20
  134. package/dist/material/rules/index.js.map +1 -1
  135. package/dist/material/tutorial/TutorialState.js +1 -2
  136. package/dist/material/tutorial/index.js +1 -17
  137. package/dist/material/tutorial/index.js.map +1 -1
  138. package/dist/options/EnumArrayOption.js +3 -6
  139. package/dist/options/EnumArrayOption.js.map +1 -1
  140. package/dist/options/EnumOption.js +1 -4
  141. package/dist/options/EnumOption.js.map +1 -1
  142. package/dist/options/Option.js +1 -2
  143. package/dist/options/OptionSpecOf.js +1 -2
  144. package/dist/options/OptionsSpec.js +1 -2
  145. package/dist/options/OptionsValidationError.js +6 -28
  146. package/dist/options/OptionsValidationError.js.map +1 -1
  147. package/dist/options/PlayerEnumOption.js +19 -29
  148. package/dist/options/PlayerEnumOption.js.map +1 -1
  149. package/dist/options/PlayersOptionsSpec.js +1 -2
  150. package/dist/options/WithIdOption.js +1 -2
  151. package/dist/options/WithPlayerOptionsSpec.js +1 -4
  152. package/dist/options/WithPlayerOptionsSpec.js.map +1 -1
  153. package/dist/options/WithPlayersOptions.js +1 -2
  154. package/dist/options/index.js +12 -28
  155. package/dist/options/index.js.map +1 -1
  156. package/dist/options/isWithPlayerIdOptions.js +3 -6
  157. package/dist/options/isWithPlayerIdOptions.js.map +1 -1
  158. package/dist/utils/action-view.util.js +18 -25
  159. package/dist/utils/action-view.util.js.map +1 -1
  160. package/dist/utils/action.util.js +11 -16
  161. package/dist/utils/action.util.js.map +1 -1
  162. package/dist/utils/adjacent-groups.util.js +33 -41
  163. package/dist/utils/adjacent-groups.util.js.map +1 -1
  164. package/dist/utils/automatic-moves.util.js +10 -15
  165. package/dist/utils/automatic-moves.util.js.map +1 -1
  166. package/dist/utils/enum.util.js +7 -13
  167. package/dist/utils/enum.util.js.map +1 -1
  168. package/dist/utils/game-view.util.js +5 -8
  169. package/dist/utils/game-view.util.js.map +1 -1
  170. package/dist/utils/grid.hex.util.js +36 -88
  171. package/dist/utils/grid.hex.util.js.map +1 -1
  172. package/dist/utils/grid.squares.util.js +8 -19
  173. package/dist/utils/grid.squares.util.js.map +1 -1
  174. package/dist/utils/grid.util.js +1 -5
  175. package/dist/utils/grid.util.js.map +1 -1
  176. package/dist/utils/index.js +16 -32
  177. package/dist/utils/index.js.map +1 -1
  178. package/dist/utils/listing.util.js +8 -13
  179. package/dist/utils/listing.util.js.map +1 -1
  180. package/dist/utils/loops.util.js +3 -6
  181. package/dist/utils/loops.util.js.map +1 -1
  182. package/dist/utils/money.util.js +54 -73
  183. package/dist/utils/money.util.js.map +1 -1
  184. package/dist/utils/neighbors.util.js +6 -10
  185. package/dist/utils/neighbors.util.js.map +1 -1
  186. package/dist/utils/polyhex.util.js +36 -56
  187. package/dist/utils/polyhex.util.js.map +1 -1
  188. package/dist/utils/random.util.js +2 -5
  189. package/dist/utils/random.util.js.map +1 -1
  190. package/dist/utils/rank.util.js +9 -13
  191. package/dist/utils/rank.util.js.map +1 -1
  192. package/package.json +43 -37
  193. package/dist/ApplyAutomaticMoves.d.ts +0 -2
  194. package/dist/ApplyAutomaticMoves.js +0 -25
  195. package/dist/ApplyAutomaticMoves.js.map +0 -1
  196. package/dist/DefaultGameSetup.d.ts +0 -7
  197. package/dist/DefaultGameSetup.js +0 -15
  198. package/dist/DefaultGameSetup.js.map +0 -1
  199. package/dist/Dummy.d.ts +0 -7
  200. package/dist/Dummy.js +0 -27
  201. package/dist/Dummy.js.map +0 -1
  202. package/dist/GameSetupCreator.d.ts +0 -4
  203. package/dist/GameSetupCreator.js +0 -3
  204. package/dist/GameSetupCreator.js.map +0 -1
  205. package/dist/IncompleteInformation.d.ts +0 -14
  206. package/dist/IncompleteInformation.js +0 -38
  207. package/dist/IncompleteInformation.js.map +0 -1
  208. package/dist/LoopWithFuse.d.ts +0 -4
  209. package/dist/LoopWithFuse.js +0 -15
  210. package/dist/LoopWithFuse.js.map +0 -1
  211. package/dist/Robot.d.ts +0 -1
  212. package/dist/Robot.js +0 -3
  213. package/dist/Robot.js.map +0 -1
  214. package/dist/RulesCreator.d.ts +0 -7
  215. package/dist/RulesCreator.js +0 -3
  216. package/dist/RulesCreator.js.map +0 -1
  217. package/dist/material/location/strategy/StakingStrategy.d.ts +0 -12
  218. package/dist/material/location/strategy/StakingStrategy.js +0 -32
  219. package/dist/material/location/strategy/StakingStrategy.js.map +0 -1
  220. package/dist/material/moves/items/ItemMovesBuilder.d.ts +0 -8
  221. package/dist/material/moves/items/ItemMovesBuilder.js +0 -34
  222. package/dist/material/moves/items/ItemMovesBuilder.js.map +0 -1
  223. package/dist/material/rules/MaterialMoveBuilder.d.ts +0 -9
  224. package/dist/material/rules/MaterialMoveBuilder.js +0 -28
  225. package/dist/material/rules/MaterialMoveBuilder.js.map +0 -1
  226. package/dist/material/rules/MaterialRulesMovesBuilder.d.ts +0 -12
  227. package/dist/material/rules/MaterialRulesMovesBuilder.js +0 -36
  228. package/dist/material/rules/MaterialRulesMovesBuilder.js.map +0 -1
  229. package/dist/setup/DefaultGameSetup.d.ts +0 -7
  230. package/dist/setup/DefaultGameSetup.js +0 -15
  231. package/dist/setup/DefaultGameSetup.js.map +0 -1
  232. package/dist/setup/GameSetup.d.ts +0 -3
  233. package/dist/setup/GameSetup.js +0 -3
  234. package/dist/setup/GameSetup.js.map +0 -1
  235. package/dist/setup/GameSetupCreator.d.ts +0 -4
  236. package/dist/setup/GameSetupCreator.js +0 -3
  237. package/dist/setup/GameSetupCreator.js.map +0 -1
  238. package/dist/setup/index.d.ts +0 -2
  239. package/dist/setup/index.js +0 -19
  240. package/dist/setup/index.js.map +0 -1
  241. package/dist/utils/EnumUtils.d.ts +0 -1
  242. package/dist/utils/EnumUtils.js +0 -8
  243. package/dist/utils/EnumUtils.js.map +0 -1
  244. package/dist/utils/coordinates.util.d.ts +0 -5
  245. package/dist/utils/coordinates.util.js +0 -16
  246. package/dist/utils/coordinates.util.js.map +0 -1
  247. package/dist/utils/isDeadEndMove.util.d.ts +0 -2
  248. package/dist/utils/isDeadEndMove.util.js +0 -19
  249. package/dist/utils/isDeadEndMove.util.js.map +0 -1
@@ -1,39 +1,10 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MaterialRules = void 0;
30
- var es_toolkit_1 = require("es-toolkit");
31
- var Rules_1 = require("../Rules");
32
- var TimeLimit_1 = require("../TimeLimit");
33
- var items_1 = require("./items");
34
- var memory_1 = require("./memory");
35
- var moves_1 = require("./moves");
36
- var rules_1 = require("./rules");
1
+ import { difference, random, shuffle, union } from 'es-toolkit';
2
+ import { Rules } from '../Rules';
3
+ import { hasTimeLimit } from '../TimeLimit';
4
+ import { Material, MaterialMutator } from './items';
5
+ import { GameMemory, PlayerMemory } from './memory';
6
+ import { isEndGame, isRoll, isSelectItem, isShuffle, isStartPlayerTurn, isStartSimultaneousRule, ItemMoveType, LocalMoveType, MaterialMoveBuilder, MoveKind, RuleMoveType } from './moves';
7
+ import { isSimultaneousRule } from './rules';
37
8
  /**
38
9
  * The MaterialRules class is the main class to implement the rules of a board game with the "Material oriented" approach.
39
10
  * With this approach, the game state and the game moves is structured around the game material items and their movements.
@@ -45,65 +16,42 @@ var rules_1 = require("./rules");
45
16
  * @typeparam MaterialType - Numeric enum of the types of material manipulated in the game
46
17
  * @typeparam LocationType - Numeric enum of the types of location in the game where the material can be located
47
18
  */
48
- var MaterialRules = /** @class */ (function (_super) {
49
- __extends(MaterialRules, _super);
50
- function MaterialRules() {
51
- var _this = _super !== null && _super.apply(this, arguments) || this;
52
- /**
53
- * The "location strategies" are global rules that always apply in a game when we want to maintain a consistency in the position of the material.
54
- * For example, we usually want the cards in a player hand to always go from x=0 to x=n without a gap, so we use a {@link PositiveSequenceStrategy} to enforce
55
- * the rule once and for all. If we want to create a "river" of card we can use a {@link FillGapStrategy}.
56
- * Games with more complex use cases can implement their own {@link LocationStrategy}.
57
- */
58
- _this.locationsStrategies = {};
59
- _this.startPlayerTurn = moves_1.MaterialMoveBuilder.startPlayerTurn;
60
- _this.startSimultaneousRule = moves_1.MaterialMoveBuilder.startSimultaneousRule;
61
- _this.startRule = moves_1.MaterialMoveBuilder.startRule;
62
- _this.customMove = moves_1.MaterialMoveBuilder.customMove;
63
- _this.endGame = moves_1.MaterialMoveBuilder.endGame;
64
- return _this;
65
- }
19
+ export class MaterialRules extends Rules {
20
+ /**
21
+ * The "location strategies" are global rules that always apply in a game when we want to maintain a consistency in the position of the material.
22
+ * For example, we usually want the cards in a player hand to always go from x=0 to x=n without a gap, so we use a {@link PositiveSequenceStrategy} to enforce
23
+ * the rule once and for all. If we want to create a "river" of card we can use a {@link FillGapStrategy}.
24
+ * Games with more complex use cases can implement their own {@link LocationStrategy}.
25
+ */
26
+ locationsStrategies = {};
66
27
  /**
67
28
  * Helper function to manipulate the material items of the game. See {@link Material}.
68
29
  *
69
30
  * @param type The type of Material we want to work on
70
31
  * @returns a Material instance to manipulate all the material of that type in current game state.
71
32
  */
72
- MaterialRules.prototype.material = function (type) {
73
- return new items_1.Material(type, this.game.items[type]);
74
- };
75
- Object.defineProperty(MaterialRules.prototype, "players", {
76
- /**
77
- * Shortcut for this.game.players
78
- * @returns array of the players identifiers
79
- */
80
- get: function () {
81
- return this.game.players;
82
- },
83
- enumerable: false,
84
- configurable: true
85
- });
86
- Object.defineProperty(MaterialRules.prototype, "activePlayer", {
87
- /**
88
- * @return the active player if exactly one player is active
89
- */
90
- get: function () {
91
- return this.getActivePlayer();
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- Object.defineProperty(MaterialRules.prototype, "activePlayers", {
97
- /**
98
- * @returns all the active players
99
- */
100
- get: function () {
101
- var _a, _b, _c;
102
- return ((_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.player) !== undefined ? [this.game.rule.player] : (_c = (_b = this.game.rule) === null || _b === void 0 ? void 0 : _b.players) !== null && _c !== void 0 ? _c : [];
103
- },
104
- enumerable: false,
105
- configurable: true
106
- });
33
+ material(type) {
34
+ return new Material(type, this.game.items[type]);
35
+ }
36
+ /**
37
+ * Shortcut for this.game.players
38
+ * @returns array of the players identifiers
39
+ */
40
+ get players() {
41
+ return this.game.players;
42
+ }
43
+ /**
44
+ * @return the active player if exactly one player is active
45
+ */
46
+ get activePlayer() {
47
+ return this.getActivePlayer();
48
+ }
49
+ /**
50
+ * @returns all the active players
51
+ */
52
+ get activePlayers() {
53
+ return this.game.rule?.player !== undefined ? [this.game.rule.player] : this.game.rule?.players ?? [];
54
+ }
107
55
  /**
108
56
  * Utility function to access the memory tool for the game or on player.
109
57
  * this.game.memory can be used to store any data that is not available through the state of the material, or current rule.
@@ -112,18 +60,18 @@ var MaterialRules = /** @class */ (function (_super) {
112
60
  * @returns {@link GameMemory} or {@link PlayerMemory} utility
113
61
  * @protected
114
62
  */
115
- MaterialRules.prototype.getMemory = function (player) {
116
- return player === undefined ? new memory_1.GameMemory(this.game) : new memory_1.PlayerMemory(this.game, player);
117
- };
63
+ getMemory(player) {
64
+ return player === undefined ? new GameMemory(this.game) : new PlayerMemory(this.game, player);
65
+ }
118
66
  /**
119
67
  * Save a new value inside the memory.
120
68
  * @param key The key to index the memorized value.
121
69
  * @param value Any JSON serializable value to store, or a function that takes previous stored value and returns the new value to store.
122
70
  * @param player optional, if we need to memorize a different value for each player.
123
71
  */
124
- MaterialRules.prototype.memorize = function (key, value, player) {
72
+ memorize(key, value, player) {
125
73
  return this.getMemory(player).memorize(key, value);
126
- };
74
+ }
127
75
  /**
128
76
  * Retrieve the value memorized under a given key.
129
77
  * Shortcut for this.game.memory[key] or this.game.memory[key][player]
@@ -131,37 +79,38 @@ var MaterialRules = /** @class */ (function (_super) {
131
79
  * @param key Key under which the memory is store. Usually a value of a numeric enum named "Memory".
132
80
  * @param player optional, if we need to memorize a different value for each player.
133
81
  */
134
- MaterialRules.prototype.remind = function (key, player) {
82
+ remind(key, player) {
135
83
  return this.getMemory(player).remind(key);
136
- };
84
+ }
137
85
  /**
138
86
  * Delete a value from the memory
139
87
  * @param key Key of the value to delete
140
88
  * @param player optional, if we need to memorize a different value for each player.
141
89
  */
142
- MaterialRules.prototype.forget = function (key, player) {
90
+ forget(key, player) {
143
91
  this.getMemory(player).forget(key);
144
- };
145
- Object.defineProperty(MaterialRules.prototype, "rulesStep", {
146
- /**
147
- * Instantiates the class that handled the rules of the game corresponding to the current rule id.
148
- * This function reads the current value in this.game.rule.id and instantiate the corresponding class in the {@link rules} property.
149
- *
150
- * @returns the class that handled the rules of the game, at current specific game state.
151
- */
152
- get: function () {
153
- if (!this.game.rule)
154
- return;
155
- var RulesStep = this.rules[this.game.rule.id];
156
- if (!RulesStep) {
157
- console.error("The rules class for rules id ".concat(this.game.rule.id, " is missing"));
158
- return;
159
- }
160
- return new RulesStep(this.game);
161
- },
162
- enumerable: false,
163
- configurable: true
164
- });
92
+ }
93
+ startPlayerTurn = MaterialMoveBuilder.startPlayerTurn;
94
+ startSimultaneousRule = MaterialMoveBuilder.startSimultaneousRule;
95
+ startRule = MaterialMoveBuilder.startRule;
96
+ customMove = MaterialMoveBuilder.customMove;
97
+ endGame = MaterialMoveBuilder.endGame;
98
+ /**
99
+ * Instantiates the class that handled the rules of the game corresponding to the current rule id.
100
+ * This function reads the current value in this.game.rule.id and instantiate the corresponding class in the {@link rules} property.
101
+ *
102
+ * @returns the class that handled the rules of the game, at current specific game state.
103
+ */
104
+ get rulesStep() {
105
+ if (!this.game.rule)
106
+ return;
107
+ const RulesStep = this.rules[this.game.rule.id];
108
+ if (!RulesStep) {
109
+ console.error(`The rules class for rules id ${this.game.rule.id} is missing`);
110
+ return;
111
+ }
112
+ return new RulesStep(this.game);
113
+ }
165
114
  /**
166
115
  * Returns a utility class to change the state of the items.
167
116
  * Used by the framework to apply the Material moves on the items (should not be manipulated directly in the games).
@@ -169,11 +118,11 @@ var MaterialRules = /** @class */ (function (_super) {
169
118
  * @param type MaterialType of the item we want to modify
170
119
  * @returns a MaterialMutator to change the state of the items
171
120
  */
172
- MaterialRules.prototype.mutator = function (type) {
121
+ mutator(type) {
173
122
  if (!this.game.items[type])
174
123
  this.game.items[type] = [];
175
- return new items_1.MaterialMutator(type, this.game.items[type], this.locationsStrategies[type], this.itemsCanMerge(type));
176
- };
124
+ return new MaterialMutator(type, this.game.items[type], this.locationsStrategies[type], this.itemsCanMerge(type));
125
+ }
177
126
  /**
178
127
  * Items can sometime be stored with a quantity (for example, coins).
179
128
  * By default, if you create or move similar items to the exact same location, they will merge into one item with a quantity.
@@ -182,29 +131,29 @@ var MaterialRules = /** @class */ (function (_super) {
182
131
  * @param _type type of items
183
132
  * @returns true if items can merge into one item with a quantity (default behavior)
184
133
  */
185
- MaterialRules.prototype.itemsCanMerge = function (_type) {
134
+ itemsCanMerge(_type) {
186
135
  return true;
187
- };
136
+ }
188
137
  /**
189
138
  * In the material approach, the rules behavior is delegated to the current {@link rulesStep}. See {@link Rules.delegate}
190
139
  */
191
- MaterialRules.prototype.delegate = function () {
140
+ delegate() {
192
141
  return this.rulesStep;
193
- };
142
+ }
194
143
  /**
195
144
  * Randomize Shuffle of Roll moves (see {@link RandomMove.randomize})
196
145
  * @param move The Material Move to randomize
197
146
  * @returns the randomized move
198
147
  */
199
- MaterialRules.prototype.randomize = function (move) {
200
- if ((0, moves_1.isShuffle)(move)) {
201
- return __assign(__assign({}, move), { newIndexes: (0, es_toolkit_1.shuffle)(move.indexes) });
148
+ randomize(move) {
149
+ if (isShuffle(move)) {
150
+ return { ...move, newIndexes: shuffle(move.indexes) };
202
151
  }
203
- else if ((0, moves_1.isRoll)(move)) {
204
- return __assign(__assign({}, move), { location: __assign(__assign({}, move.location), { rotation: this.roll(move) }) });
152
+ else if (isRoll(move)) {
153
+ return { ...move, location: { ...move.location, rotation: this.roll(move) } };
205
154
  }
206
155
  return move;
207
- };
156
+ }
208
157
  /**
209
158
  * When a RollItem move is create, it has to be randomized on the server side before it is saved and shared.
210
159
  * This function provides the random value. By default, it returns a value between 0 and 5 assuming a 6 sided dice is rolled.
@@ -213,9 +162,9 @@ var MaterialRules = /** @class */ (function (_super) {
213
162
  * @param _move The RollItem move to randomize
214
163
  * @returns a random rolled value, by default a value between 0 and 5 (cubic dice result)
215
164
  */
216
- MaterialRules.prototype.roll = function (_move) {
217
- return (0, es_toolkit_1.random)(5);
218
- };
165
+ roll(_move) {
166
+ return random(5);
167
+ }
219
168
  /**
220
169
  * Execution of the Material Moves. See {@link Rules.play}.
221
170
  *
@@ -223,137 +172,131 @@ var MaterialRules = /** @class */ (function (_super) {
223
172
  * @param context Context in which the move was played
224
173
  * @returns Consequences of the move
225
174
  */
226
- MaterialRules.prototype.play = function (move, context) {
227
- var consequences = [];
175
+ play(move, context) {
176
+ const consequences = [];
228
177
  switch (move.kind) {
229
- case moves_1.MoveKind.ItemMove:
230
- consequences.push.apply(consequences, this.onPlayItemMove(move, context));
178
+ case MoveKind.ItemMove:
179
+ consequences.push(...this.onPlayItemMove(move, context));
231
180
  break;
232
- case moves_1.MoveKind.RulesMove:
233
- consequences.push.apply(consequences, this.onPlayRulesMove(move, context));
181
+ case MoveKind.RulesMove:
182
+ consequences.push(...this.onPlayRulesMove(move, context));
234
183
  break;
235
- case moves_1.MoveKind.CustomMove:
236
- consequences.push.apply(consequences, this.onCustomMove(move, context));
184
+ case MoveKind.CustomMove:
185
+ consequences.push(...this.onCustomMove(move, context));
237
186
  break;
238
- case moves_1.MoveKind.LocalMove:
187
+ case MoveKind.LocalMove:
239
188
  switch (move.type) {
240
- case moves_1.LocalMoveType.DisplayHelp:
189
+ case LocalMoveType.DisplayHelp:
241
190
  this.game.helpDisplay = move.helpDisplay;
242
191
  break;
243
- case moves_1.LocalMoveType.DropItem:
192
+ case LocalMoveType.DropItem:
244
193
  if (!this.game.droppedItems) {
245
194
  this.game.droppedItems = [];
246
195
  }
247
196
  this.game.droppedItems.push(move.item);
248
197
  break;
249
- case moves_1.LocalMoveType.SetTutorialStep:
198
+ case LocalMoveType.SetTutorialStep:
250
199
  this.game.tutorial.step = move.step;
251
200
  this.game.tutorial.stepComplete = false;
252
201
  this.game.tutorial.popupClosed = false;
253
202
  break;
254
- case moves_1.LocalMoveType.CloseTutorialPopup:
203
+ case LocalMoveType.CloseTutorialPopup:
255
204
  this.game.tutorial.popupClosed = true;
256
205
  }
257
206
  }
258
- var endGameIndex = consequences.findIndex(moves_1.isEndGame);
207
+ const endGameIndex = consequences.findIndex(isEndGame);
259
208
  if (endGameIndex !== -1) {
260
209
  return consequences.slice(0, endGameIndex + 1);
261
210
  }
262
211
  return consequences;
263
- };
264
- MaterialRules.prototype.onPlayItemMove = function (move, context) {
265
- var _a, _b;
266
- var consequences = [];
267
- if (!(context === null || context === void 0 ? void 0 : context.transient)) {
268
- consequences.push.apply(consequences, this.beforeItemMove(move, context));
212
+ }
213
+ onPlayItemMove(move, context) {
214
+ const consequences = [];
215
+ if (!context?.transient) {
216
+ consequences.push(...this.beforeItemMove(move, context));
269
217
  }
270
218
  if (!this.game.items[move.itemType])
271
219
  this.game.items[move.itemType] = [];
272
- var mutator = this.mutator(move.itemType);
220
+ const mutator = this.mutator(move.itemType);
273
221
  mutator.applyMove(move);
274
222
  if (this.game.droppedItems) {
275
- this.game.droppedItems = this.game.droppedItems.filter(function (droppedItem) {
223
+ this.game.droppedItems = this.game.droppedItems.filter((droppedItem) => {
276
224
  if (move.itemType !== droppedItem.type) {
277
225
  return true;
278
226
  }
279
227
  switch (move.type) {
280
- case moves_1.ItemMoveType.Move:
281
- case moves_1.ItemMoveType.Delete:
228
+ case ItemMoveType.Move:
229
+ case ItemMoveType.Delete:
282
230
  return move.itemIndex !== droppedItem.index;
283
- case moves_1.ItemMoveType.MoveAtOnce:
231
+ case ItemMoveType.MoveAtOnce:
284
232
  return !move.indexes.includes(droppedItem.index);
285
233
  }
286
234
  });
287
235
  }
288
- var indexes = getItemMoveIndexes(move);
289
- if (context === null || context === void 0 ? void 0 : context.transient) {
236
+ const indexes = getItemMoveIndexes(move);
237
+ if (context?.transient) {
290
238
  if (!this.game.transientItems)
291
239
  this.game.transientItems = {};
292
- this.game.transientItems[move.itemType] = (0, es_toolkit_1.union)((_a = this.game.transientItems[move.itemType]) !== null && _a !== void 0 ? _a : [], indexes);
240
+ this.game.transientItems[move.itemType] = union(this.game.transientItems[move.itemType] ?? [], indexes);
293
241
  }
294
242
  else if (this.game.transientItems) {
295
- this.game.transientItems[move.itemType] = (0, es_toolkit_1.difference)((_b = this.game.transientItems[move.itemType]) !== null && _b !== void 0 ? _b : [], indexes);
243
+ this.game.transientItems[move.itemType] = difference(this.game.transientItems[move.itemType] ?? [], indexes);
296
244
  }
297
- if (!(context === null || context === void 0 ? void 0 : context.transient)) {
298
- consequences.push.apply(consequences, this.afterItemMove(move, context));
245
+ if (!context?.transient) {
246
+ consequences.push(...this.afterItemMove(move, context));
299
247
  }
300
248
  return consequences;
301
- };
302
- MaterialRules.prototype.beforeItemMove = function (move, context) {
303
- var _a, _b;
304
- return (_b = (_a = this.rulesStep) === null || _a === void 0 ? void 0 : _a.beforeItemMove(move, context)) !== null && _b !== void 0 ? _b : [];
305
- };
306
- MaterialRules.prototype.afterItemMove = function (move, context) {
307
- var _a, _b;
308
- return (_b = (_a = this.rulesStep) === null || _a === void 0 ? void 0 : _a.afterItemMove(move, context)) !== null && _b !== void 0 ? _b : [];
309
- };
310
- MaterialRules.prototype.onCustomMove = function (move, context) {
311
- var _a, _b;
312
- return (_b = (_a = this.rulesStep) === null || _a === void 0 ? void 0 : _a.onCustomMove(move, context)) !== null && _b !== void 0 ? _b : [];
313
- };
314
- MaterialRules.prototype.onPlayRulesMove = function (move, context) {
315
- var _a, _b;
316
- var consequences = [];
317
- var rulesStep = this.rulesStep;
318
- if (move.type === moves_1.RuleMoveType.EndPlayerTurn) {
319
- if ((_b = (_a = this.game.rule) === null || _a === void 0 ? void 0 : _a.players) === null || _b === void 0 ? void 0 : _b.includes(move.player)) {
320
- this.game.rule.players = this.game.rule.players.filter(function (player) { return player !== move.player; });
321
- if ((0, rules_1.isSimultaneousRule)(rulesStep)) {
322
- consequences.push.apply(consequences, rulesStep.onPlayerTurnEnd(move, context));
249
+ }
250
+ beforeItemMove(move, context) {
251
+ return this.rulesStep?.beforeItemMove(move, context) ?? [];
252
+ }
253
+ afterItemMove(move, context) {
254
+ return this.rulesStep?.afterItemMove(move, context) ?? [];
255
+ }
256
+ onCustomMove(move, context) {
257
+ return this.rulesStep?.onCustomMove(move, context) ?? [];
258
+ }
259
+ onPlayRulesMove(move, context) {
260
+ const consequences = [];
261
+ const rulesStep = this.rulesStep;
262
+ if (move.type === RuleMoveType.EndPlayerTurn) {
263
+ if (this.game.rule?.players?.includes(move.player)) {
264
+ this.game.rule.players = this.game.rule.players.filter(player => player !== move.player);
265
+ if (isSimultaneousRule(rulesStep)) {
266
+ consequences.push(...rulesStep.onPlayerTurnEnd(move, context));
323
267
  if (this.game.rule.players.length === 0) {
324
- consequences.push.apply(consequences, rulesStep.getMovesAfterPlayersDone());
268
+ consequences.push(...rulesStep.getMovesAfterPlayersDone());
325
269
  }
326
270
  }
327
271
  }
328
272
  else {
329
- console.warn("".concat(this.constructor.name, ": endPlayerTurn was triggered for player ").concat(move.player, " which is already inactive: ").concat(JSON.parse(JSON.stringify(this.game.rule))));
273
+ console.warn(`${this.constructor.name}: endPlayerTurn was triggered for player ${move.player} which is already inactive: ${JSON.parse(JSON.stringify(this.game.rule))}`);
330
274
  }
331
275
  }
332
276
  else {
333
- consequences.push.apply(consequences, this.changeRule(move, context));
277
+ consequences.push(...this.changeRule(move, context));
334
278
  }
335
279
  return consequences;
336
- };
337
- MaterialRules.prototype.changeRule = function (move, context) {
338
- var _a, _b, _c, _d, _e, _f;
339
- var moves = (_b = (_a = this.rulesStep) === null || _a === void 0 ? void 0 : _a.onRuleEnd(move, context)) !== null && _b !== void 0 ? _b : [];
340
- var rule = this.game.rule;
280
+ }
281
+ changeRule(move, context) {
282
+ const moves = this.rulesStep?.onRuleEnd(move, context) ?? [];
283
+ const rule = this.game.rule;
341
284
  switch (move.type) {
342
- case moves_1.RuleMoveType.StartPlayerTurn:
285
+ case RuleMoveType.StartPlayerTurn:
343
286
  this.game.rule = { id: move.id, player: move.player };
344
287
  break;
345
- case moves_1.RuleMoveType.StartSimultaneousRule:
346
- this.game.rule = { id: move.id, players: (_c = move.players) !== null && _c !== void 0 ? _c : this.game.players };
288
+ case RuleMoveType.StartSimultaneousRule:
289
+ this.game.rule = { id: move.id, players: move.players ?? this.game.players };
347
290
  break;
348
- case moves_1.RuleMoveType.StartRule:
349
- this.game.rule = { id: move.id, player: (_d = this.game.rule) === null || _d === void 0 ? void 0 : _d.player };
291
+ case RuleMoveType.StartRule:
292
+ this.game.rule = { id: move.id, player: this.game.rule?.player };
350
293
  break;
351
- case moves_1.RuleMoveType.EndGame:
294
+ case RuleMoveType.EndGame:
352
295
  delete this.game.rule;
353
296
  break;
354
297
  }
355
- return moves.concat((_f = (_e = this.rulesStep) === null || _e === void 0 ? void 0 : _e.onRuleStart(move, rule, context)) !== null && _f !== void 0 ? _f : []);
356
- };
298
+ return moves.concat(this.rulesStep?.onRuleStart(move, rule, context) ?? []);
299
+ }
357
300
  /**
358
301
  * By default, a Material Move can be undone if no player became active and no dice was rolled.
359
302
  * See {@link Undo.canUndo} and {@link HiddenMaterialRules.canUndo}
@@ -362,41 +305,41 @@ var MaterialRules = /** @class */ (function (_super) {
362
305
  * @param consecutiveActions Action played in between
363
306
  * @returns true if the action can be undone by the player that played it
364
307
  */
365
- MaterialRules.prototype.canUndo = function (action, consecutiveActions) {
366
- for (var i = consecutiveActions.length - 1; i >= 0; i--) {
308
+ canUndo(action, consecutiveActions) {
309
+ for (let i = consecutiveActions.length - 1; i >= 0; i--) {
367
310
  if (this.consecutiveActionBlocksUndo(action, consecutiveActions[i])) {
368
311
  return false;
369
312
  }
370
313
  }
371
314
  return !this.actionBlocksUndo(action);
372
- };
373
- MaterialRules.prototype.consecutiveActionBlocksUndo = function (action, consecutiveAction) {
315
+ }
316
+ consecutiveActionBlocksUndo(action, consecutiveAction) {
374
317
  if (this.actionActivatesPlayer(consecutiveAction)) {
375
318
  return true;
376
319
  }
377
320
  if (consecutiveAction.playerId === action.playerId) {
378
- if (!(0, moves_1.isSelectItem)(consecutiveAction.move) || !(0, moves_1.isSelectItem)(action.move)) {
321
+ if (!isSelectItem(consecutiveAction.move) || !isSelectItem(action.move)) {
379
322
  return true;
380
323
  }
381
324
  }
382
325
  return false;
383
- };
384
- MaterialRules.prototype.actionBlocksUndo = function (action) {
385
- for (var i = action.consequences.length - 1; i >= 0; i--) {
326
+ }
327
+ actionBlocksUndo(action) {
328
+ for (let i = action.consequences.length - 1; i >= 0; i--) {
386
329
  if (this.moveBlocksUndo(action.consequences[i], action.playerId)) {
387
330
  return true;
388
331
  }
389
332
  }
390
333
  return this.moveBlocksUndo(action.move, action.playerId);
391
- };
392
- MaterialRules.prototype.actionActivatesPlayer = function (action) {
393
- for (var i = action.consequences.length - 1; i >= 0; i--) {
334
+ }
335
+ actionActivatesPlayer(action) {
336
+ for (let i = action.consequences.length - 1; i >= 0; i--) {
394
337
  if (this.moveActivatesPlayer(action.consequences[i])) {
395
338
  return true;
396
339
  }
397
340
  }
398
341
  return this.moveActivatesPlayer(action.move);
399
- };
342
+ }
400
343
  /**
401
344
  * @protected
402
345
  * If a moves blocks the undo, any action with this move cannot be undone.
@@ -406,28 +349,23 @@ var MaterialRules = /** @class */ (function (_super) {
406
349
  * @param player The player that triggered the move
407
350
  * @returns true if the move blocks the undo
408
351
  */
409
- MaterialRules.prototype.moveBlocksUndo = function (move, player) {
410
- return this.moveActivatesPlayer(move, player) || (0, moves_1.isRoll)(move);
411
- };
412
- MaterialRules.prototype.moveActivatesPlayer = function (move, player) {
413
- var _a;
414
- return ((0, moves_1.isStartPlayerTurn)(move) && move.player !== player)
415
- || ((0, moves_1.isStartSimultaneousRule)(move) && ((_a = move.players) !== null && _a !== void 0 ? _a : this.game.players).some(function (p) { return p !== player; }));
416
- };
352
+ moveBlocksUndo(move, player) {
353
+ return this.moveActivatesPlayer(move, player) || isRoll(move);
354
+ }
355
+ moveActivatesPlayer(move, player) {
356
+ return (isStartPlayerTurn(move) && move.player !== player)
357
+ || (isStartSimultaneousRule(move) && (move.players ?? this.game.players).some((p) => p !== player));
358
+ }
417
359
  /**
418
360
  * Restore help display & local item moves
419
361
  */
420
- MaterialRules.prototype.restoreTransientState = function (previousState) {
421
- var _this = this;
362
+ restoreTransientState(previousState) {
422
363
  this.game.helpDisplay = previousState.helpDisplay;
423
364
  this.game.transientItems = previousState.transientItems;
424
- var _loop_1 = function (type) {
425
- previousState.transientItems[type].forEach(function (index) { return _this.game.items[type][index] = previousState.items[type][index]; });
426
- };
427
- for (var type in previousState.transientItems) {
428
- _loop_1(type);
365
+ for (const type in previousState.transientItems) {
366
+ previousState.transientItems[type].forEach(index => this.game.items[type][index] = previousState.items[type][index]);
429
367
  }
430
- };
368
+ }
431
369
  /**
432
370
  * Random moves, or moves that reveals something to me, are unpredictable.
433
371
  * Unpredictable moves cannot be precomputed on client side, the server side's response is necessary.
@@ -437,39 +375,37 @@ var MaterialRules = /** @class */ (function (_super) {
437
375
  * @param _player The player playing the move
438
376
  * @returns true if the move outcome cannot be predicted on client side
439
377
  */
440
- MaterialRules.prototype.isUnpredictableMove = function (move, _player) {
441
- return (0, moves_1.isRoll)(move);
442
- };
378
+ isUnpredictableMove(move, _player) {
379
+ return isRoll(move);
380
+ }
443
381
  /**
444
382
  * A Material Game is over when there is no rule left to execute. This state results of a {@link EndGame} move.
445
383
  *
446
384
  * @returns true if game is over
447
385
  */
448
- MaterialRules.prototype.isOver = function () {
386
+ isOver() {
449
387
  return !this.game.rule;
450
- };
388
+ }
451
389
  /**
452
390
  * Amount of time given to a player everytime it is their turn to play.
453
391
  * @param playerId Id of the player, if you want to give different time depending on the id for asymmetric games.
454
392
  * @return number of seconds to add to the player's clock
455
393
  */
456
- MaterialRules.prototype.giveTime = function (playerId) {
457
- var rule = this.rulesStep;
458
- return rule && (0, TimeLimit_1.hasTimeLimit)(rule) ? rule.giveTime(playerId) : 60;
459
- };
460
- return MaterialRules;
461
- }(Rules_1.Rules));
462
- exports.MaterialRules = MaterialRules;
394
+ giveTime(playerId) {
395
+ const rule = this.rulesStep;
396
+ return rule && hasTimeLimit(rule) ? rule.giveTime(playerId) : 60;
397
+ }
398
+ }
463
399
  function getItemMoveIndexes(move) {
464
400
  switch (move.type) {
465
- case moves_1.ItemMoveType.Move:
466
- case moves_1.ItemMoveType.Delete:
467
- case moves_1.ItemMoveType.Roll:
468
- case moves_1.ItemMoveType.Select:
401
+ case ItemMoveType.Move:
402
+ case ItemMoveType.Delete:
403
+ case ItemMoveType.Roll:
404
+ case ItemMoveType.Select:
469
405
  return [move.itemIndex];
470
- case moves_1.ItemMoveType.MoveAtOnce:
471
- case moves_1.ItemMoveType.DeleteAtOnce:
472
- case moves_1.ItemMoveType.Shuffle:
406
+ case ItemMoveType.MoveAtOnce:
407
+ case ItemMoveType.DeleteAtOnce:
408
+ case ItemMoveType.Shuffle:
473
409
  return move.indexes;
474
410
  default:
475
411
  return [];