@gamepark/rules-api 6.38.5 → 7.0.0-beta.1

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