board-game-engine 2.0.0 → 2.0.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 (251) hide show
  1. package/.github/workflows/ci.yml +33 -0
  2. package/dist/board-game-engine.cjs +463 -349
  3. package/dist/board-game-engine.js +463 -349
  4. package/dist/board-game-engine.min.js +22 -22
  5. package/dist/board-game-engine.mjs +461 -348
  6. package/dist/client/client.d.ts +76 -0
  7. package/dist/client/client.d.ts.map +1 -0
  8. package/dist/game-factory/bank/bank-slot.d.ts +30 -0
  9. package/dist/game-factory/bank/bank-slot.d.ts.map +1 -0
  10. package/dist/game-factory/bank/bank.d.ts +34 -0
  11. package/dist/game-factory/bank/bank.d.ts.map +1 -0
  12. package/dist/game-factory/board.d.ts +4 -0
  13. package/dist/game-factory/board.d.ts.map +1 -0
  14. package/dist/game-factory/condition/condition-factory.d.ts +4 -0
  15. package/dist/game-factory/condition/condition-factory.d.ts.map +1 -0
  16. package/dist/game-factory/condition/condition.d.ts +13 -0
  17. package/dist/game-factory/condition/condition.d.ts.map +1 -0
  18. package/dist/game-factory/condition/contains-condition.d.ts +8 -0
  19. package/dist/game-factory/condition/contains-condition.d.ts.map +1 -0
  20. package/dist/game-factory/condition/contains-same-condition.d.ts +7 -0
  21. package/dist/game-factory/condition/contains-same-condition.d.ts.map +1 -0
  22. package/dist/game-factory/condition/evaluate-condition.d.ts +8 -0
  23. package/dist/game-factory/condition/evaluate-condition.d.ts.map +1 -0
  24. package/dist/game-factory/condition/every-condition.d.ts +12 -0
  25. package/dist/game-factory/condition/every-condition.d.ts.map +1 -0
  26. package/dist/game-factory/condition/has-line-condition.d.ts +8 -0
  27. package/dist/game-factory/condition/has-line-condition.d.ts.map +1 -0
  28. package/dist/game-factory/condition/in-line-condition.d.ts +8 -0
  29. package/dist/game-factory/condition/in-line-condition.d.ts.map +1 -0
  30. package/dist/game-factory/condition/is-condition.d.ts +8 -0
  31. package/dist/game-factory/condition/is-condition.d.ts.map +1 -0
  32. package/dist/game-factory/condition/is-full-condition.d.ts +7 -0
  33. package/dist/game-factory/condition/is-full-condition.d.ts.map +1 -0
  34. package/dist/game-factory/condition/no-possible-moves-condition.d.ts +7 -0
  35. package/dist/game-factory/condition/no-possible-moves-condition.d.ts.map +1 -0
  36. package/dist/game-factory/condition/not-condition.d.ts +7 -0
  37. package/dist/game-factory/condition/not-condition.d.ts.map +1 -0
  38. package/dist/game-factory/condition/or-condition.d.ts +7 -0
  39. package/dist/game-factory/condition/or-condition.d.ts.map +1 -0
  40. package/dist/game-factory/condition/position-condition.d.ts +7 -0
  41. package/dist/game-factory/condition/position-condition.d.ts.map +1 -0
  42. package/dist/game-factory/condition/some-condition.d.ts +8 -0
  43. package/dist/game-factory/condition/some-condition.d.ts.map +1 -0
  44. package/dist/game-factory/condition/would-condition.d.ts +8 -0
  45. package/dist/game-factory/condition/would-condition.d.ts.map +1 -0
  46. package/dist/game-factory/entity.d.ts +13 -0
  47. package/dist/game-factory/entity.d.ts.map +1 -0
  48. package/dist/game-factory/expand-game-rules.d.ts +3 -0
  49. package/dist/game-factory/expand-game-rules.d.ts.map +1 -0
  50. package/dist/game-factory/game-factory.d.ts +10 -0
  51. package/dist/game-factory/game-factory.d.ts.map +1 -0
  52. package/{src/game-factory/move/end-turn.js → dist/game-factory/move/end-turn.d.ts} +2 -4
  53. package/dist/game-factory/move/end-turn.d.ts.map +1 -0
  54. package/dist/game-factory/move/for-each.d.ts +5 -0
  55. package/dist/game-factory/move/for-each.d.ts.map +1 -0
  56. package/dist/game-factory/move/index.d.ts +6 -0
  57. package/dist/game-factory/move/index.d.ts.map +1 -0
  58. package/dist/game-factory/move/move-entity.d.ts +7 -0
  59. package/dist/game-factory/move/move-entity.d.ts.map +1 -0
  60. package/dist/game-factory/move/move-factory.d.ts +18 -0
  61. package/dist/game-factory/move/move-factory.d.ts.map +1 -0
  62. package/dist/game-factory/move/move.d.ts +54 -0
  63. package/dist/game-factory/move/move.d.ts.map +1 -0
  64. package/dist/game-factory/move/pass-turn.d.ts +5 -0
  65. package/dist/game-factory/move/pass-turn.d.ts.map +1 -0
  66. package/{src/game-factory/move/pass.js → dist/game-factory/move/pass.d.ts} +2 -4
  67. package/dist/game-factory/move/pass.d.ts.map +1 -0
  68. package/dist/game-factory/move/place-new.d.ts +5 -0
  69. package/dist/game-factory/move/place-new.d.ts.map +1 -0
  70. package/dist/game-factory/move/remove-entity.d.ts +5 -0
  71. package/dist/game-factory/move/remove-entity.d.ts.map +1 -0
  72. package/dist/game-factory/move/set-active-players.d.ts +5 -0
  73. package/dist/game-factory/move/set-active-players.d.ts.map +1 -0
  74. package/dist/game-factory/move/set-state.d.ts +5 -0
  75. package/dist/game-factory/move/set-state.d.ts.map +1 -0
  76. package/dist/game-factory/move/shuffle.d.ts +5 -0
  77. package/dist/game-factory/move/shuffle.d.ts.map +1 -0
  78. package/dist/game-factory/move/take-from.d.ts +11 -0
  79. package/dist/game-factory/move/take-from.d.ts.map +1 -0
  80. package/dist/game-factory/space/space.d.ts +10 -0
  81. package/dist/game-factory/space/space.d.ts.map +1 -0
  82. package/dist/game-factory/space-group/grid.d.ts +15 -0
  83. package/dist/game-factory/space-group/grid.d.ts.map +1 -0
  84. package/dist/game-factory/space-group/space-group.d.ts +20 -0
  85. package/dist/game-factory/space-group/space-group.d.ts.map +1 -0
  86. package/dist/index.d.ts +6 -0
  87. package/dist/index.d.ts.map +1 -0
  88. package/dist/registry.d.ts +17 -0
  89. package/dist/registry.d.ts.map +1 -0
  90. package/dist/types/bagel-types.d.ts +339 -0
  91. package/dist/types/bagel-types.d.ts.map +1 -0
  92. package/dist/types/index.d.ts +3 -0
  93. package/dist/types/index.d.ts.map +1 -0
  94. package/dist/types/rule-with-conditions.d.ts +9 -0
  95. package/dist/types/rule-with-conditions.d.ts.map +1 -0
  96. package/dist/utils/any-valid-moves.d.ts +2 -0
  97. package/dist/utils/any-valid-moves.d.ts.map +1 -0
  98. package/dist/utils/bgio-resolve-types.d.ts +25 -0
  99. package/dist/utils/bgio-resolve-types.d.ts.map +1 -0
  100. package/dist/utils/check-conditions.d.ts +7 -0
  101. package/dist/utils/check-conditions.d.ts.map +1 -0
  102. package/dist/utils/create-payload.d.ts +5 -0
  103. package/dist/utils/create-payload.d.ts.map +1 -0
  104. package/dist/utils/deserialize-bgio-arguments.d.ts +3 -0
  105. package/dist/utils/deserialize-bgio-arguments.d.ts.map +1 -0
  106. package/dist/utils/do-moves.d.ts +8 -0
  107. package/dist/utils/do-moves.d.ts.map +1 -0
  108. package/dist/utils/entity-matches.d.ts +6 -0
  109. package/dist/utils/entity-matches.d.ts.map +1 -0
  110. package/dist/utils/find-met-condition.d.ts +6 -0
  111. package/dist/utils/find-met-condition.d.ts.map +1 -0
  112. package/dist/utils/get-current-moves.d.ts +24 -0
  113. package/dist/utils/get-current-moves.d.ts.map +1 -0
  114. package/dist/utils/get-scenario-results.d.ts +3 -0
  115. package/dist/utils/get-scenario-results.d.ts.map +1 -0
  116. package/dist/utils/get-steps.d.ts +13 -0
  117. package/dist/utils/get-steps.d.ts.map +1 -0
  118. package/dist/utils/get.d.ts +7 -0
  119. package/dist/utils/get.d.ts.map +1 -0
  120. package/dist/utils/grid-contains-sequence.d.ts +27 -0
  121. package/dist/utils/grid-contains-sequence.d.ts.map +1 -0
  122. package/dist/utils/json-transformer.d.ts +8 -0
  123. package/dist/utils/json-transformer.d.ts.map +1 -0
  124. package/dist/utils/prepare-payload.d.ts +2 -0
  125. package/dist/utils/prepare-payload.d.ts.map +1 -0
  126. package/dist/utils/resolve-entity.d.ts +3 -0
  127. package/dist/utils/resolve-entity.d.ts.map +1 -0
  128. package/dist/utils/resolve-expression.d.ts +6 -0
  129. package/dist/utils/resolve-expression.d.ts.map +1 -0
  130. package/dist/utils/resolve-properties.d.ts +4 -0
  131. package/dist/utils/resolve-properties.d.ts.map +1 -0
  132. package/dist/utils/simulate-move.d.ts +16 -0
  133. package/dist/utils/simulate-move.d.ts.map +1 -0
  134. package/package.json +9 -3
  135. package/playwright-report/index.html +1 -1
  136. package/scripts/build.mjs +2 -2
  137. package/src/client/client.ts +306 -0
  138. package/src/game-factory/bank/bank-slot.ts +81 -0
  139. package/src/game-factory/bank/bank.ts +125 -0
  140. package/src/game-factory/{board.js → board.ts} +1 -1
  141. package/src/game-factory/condition/condition-factory.ts +59 -0
  142. package/src/game-factory/condition/condition.ts +50 -0
  143. package/src/game-factory/condition/{contains-condition.js → contains-condition.ts} +5 -4
  144. package/src/game-factory/condition/{contains-same-condition.js → contains-same-condition.ts} +8 -5
  145. package/src/game-factory/condition/{evaluate-condition.js → evaluate-condition.ts} +4 -3
  146. package/src/game-factory/condition/every-condition.ts +27 -0
  147. package/src/game-factory/condition/has-line-condition.ts +15 -0
  148. package/src/game-factory/condition/in-line-condition.ts +25 -0
  149. package/src/game-factory/condition/is-condition.ts +24 -0
  150. package/src/game-factory/condition/is-full-condition.ts +10 -0
  151. package/src/game-factory/condition/{no-possible-moves-condition.js → no-possible-moves-condition.ts} +3 -2
  152. package/src/game-factory/condition/{not-condition.js → not-condition.ts} +3 -2
  153. package/src/game-factory/condition/{or-condition.js → or-condition.ts} +3 -2
  154. package/src/game-factory/condition/position-condition.ts +13 -0
  155. package/src/game-factory/condition/{some-condition.js → some-condition.ts} +5 -3
  156. package/src/game-factory/condition/would-condition.ts +104 -0
  157. package/src/game-factory/entity.ts +37 -0
  158. package/src/game-factory/expand-game-rules.ts +263 -0
  159. package/src/game-factory/game-factory.ts +263 -0
  160. package/src/game-factory/move/end-turn.ts +7 -0
  161. package/src/game-factory/move/for-each.ts +20 -0
  162. package/src/game-factory/move/move-entity.ts +18 -0
  163. package/src/game-factory/move/move-factory.ts +107 -0
  164. package/src/game-factory/move/move.ts +147 -0
  165. package/src/game-factory/move/pass-turn.ts +15 -0
  166. package/src/game-factory/move/pass.ts +7 -0
  167. package/src/game-factory/move/place-new.ts +42 -0
  168. package/src/game-factory/move/remove-entity.ts +11 -0
  169. package/src/game-factory/move/set-active-players.ts +26 -0
  170. package/src/game-factory/move/set-state.ts +14 -0
  171. package/src/game-factory/move/shuffle.ts +9 -0
  172. package/src/game-factory/move/take-from.ts +12 -0
  173. package/src/game-factory/space/space.ts +36 -0
  174. package/src/game-factory/space-group/grid.ts +48 -0
  175. package/src/game-factory/space-group/space-group.ts +44 -0
  176. package/src/index.ts +5 -0
  177. package/src/types/bagel-types.ts +449 -0
  178. package/src/types/boardgame-io-core.d.ts +7 -0
  179. package/src/types/index.ts +70 -0
  180. package/src/types/rule-with-conditions.ts +9 -0
  181. package/src/utils/{any-valid-moves.js → any-valid-moves.ts} +54 -49
  182. package/src/utils/bgio-resolve-types.ts +27 -0
  183. package/src/utils/check-conditions.ts +28 -0
  184. package/src/utils/create-payload.ts +19 -0
  185. package/src/utils/deserialize-bgio-arguments.ts +10 -0
  186. package/src/utils/do-moves.ts +22 -0
  187. package/src/utils/entity-matches.ts +30 -0
  188. package/src/utils/expr-eval.d.ts +6 -0
  189. package/src/utils/find-met-condition.ts +23 -0
  190. package/src/utils/get-current-moves.ts +39 -0
  191. package/src/utils/get-scenario-results.ts +30 -0
  192. package/src/utils/get-steps.ts +38 -0
  193. package/src/utils/get.ts +28 -0
  194. package/src/utils/{grid-contains-sequence.js → grid-contains-sequence.ts} +71 -33
  195. package/src/utils/json-transformer.ts +17 -0
  196. package/src/utils/prepare-payload.ts +20 -0
  197. package/src/utils/resolve-entity.ts +15 -0
  198. package/src/utils/resolve-expression.ts +16 -0
  199. package/src/utils/resolve-properties.ts +172 -0
  200. package/src/utils/simulate-move.ts +32 -0
  201. package/src/wackson.d.ts +4 -0
  202. package/tsconfig.build.json +14 -0
  203. package/tsconfig.json +21 -0
  204. package/src/client/client.js +0 -224
  205. package/src/game-factory/bank/bank-slot.js +0 -69
  206. package/src/game-factory/bank/bank.js +0 -114
  207. package/src/game-factory/condition/condition-factory.js +0 -52
  208. package/src/game-factory/condition/condition.js +0 -39
  209. package/src/game-factory/condition/every-condition.js +0 -25
  210. package/src/game-factory/condition/has-line-condition.js +0 -14
  211. package/src/game-factory/condition/in-line-condition.js +0 -19
  212. package/src/game-factory/condition/is-condition.js +0 -23
  213. package/src/game-factory/condition/is-full-condition.js +0 -9
  214. package/src/game-factory/condition/position-condition.js +0 -12
  215. package/src/game-factory/condition/would-condition.js +0 -94
  216. package/src/game-factory/entity.js +0 -29
  217. package/src/game-factory/expand-game-rules.js +0 -271
  218. package/src/game-factory/game-factory.js +0 -239
  219. package/src/game-factory/move/for-each.js +0 -18
  220. package/src/game-factory/move/move-entity.js +0 -16
  221. package/src/game-factory/move/move-factory.js +0 -89
  222. package/src/game-factory/move/move.js +0 -131
  223. package/src/game-factory/move/pass-turn.js +0 -10
  224. package/src/game-factory/move/place-new.js +0 -33
  225. package/src/game-factory/move/remove-entity.js +0 -7
  226. package/src/game-factory/move/set-active-players.js +0 -23
  227. package/src/game-factory/move/set-state.js +0 -11
  228. package/src/game-factory/move/shuffle.js +0 -7
  229. package/src/game-factory/move/take-from.js +0 -7
  230. package/src/game-factory/space/space.js +0 -30
  231. package/src/game-factory/space-group/grid.js +0 -43
  232. package/src/game-factory/space-group/space-group.js +0 -29
  233. package/src/index.js +0 -2
  234. package/src/utils/check-conditions.js +0 -28
  235. package/src/utils/create-payload.js +0 -16
  236. package/src/utils/deserialize-bgio-arguments.js +0 -8
  237. package/src/utils/do-moves.js +0 -18
  238. package/src/utils/entity-matches.js +0 -20
  239. package/src/utils/find-met-condition.js +0 -22
  240. package/src/utils/get-current-moves.js +0 -12
  241. package/src/utils/get-scenario-results.js +0 -23
  242. package/src/utils/get-steps.js +0 -29
  243. package/src/utils/get.js +0 -25
  244. package/src/utils/json-transformer.js +0 -12
  245. package/src/utils/prepare-payload.js +0 -16
  246. package/src/utils/resolve-entity.js +0 -9
  247. package/src/utils/resolve-expression.js +0 -10
  248. package/src/utils/resolve-properties.js +0 -149
  249. package/src/utils/simulate-move.js +0 -25
  250. /package/src/game-factory/move/{index.js → index.ts} +0 -0
  251. /package/src/{registry.js → registry.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5794,19 +5795,6 @@ var require_matches = __commonJS({
5794
5795
  }
5795
5796
  });
5796
5797
 
5797
- // node_modules/lodash/cloneDeep.js
5798
- var require_cloneDeep = __commonJS({
5799
- "node_modules/lodash/cloneDeep.js"(exports, module2) {
5800
- var baseClone = require_baseClone();
5801
- var CLONE_DEEP_FLAG = 1;
5802
- var CLONE_SYMBOLS_FLAG = 4;
5803
- function cloneDeep2(value2) {
5804
- return baseClone(value2, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
5805
- }
5806
- module2.exports = cloneDeep2;
5807
- }
5808
- });
5809
-
5810
5798
  // node_modules/rfc6902/pointer.js
5811
5799
  var require_pointer = __commonJS({
5812
5800
  "node_modules/rfc6902/pointer.js"(exports) {
@@ -6487,7 +6475,7 @@ var require_setImmediate = __commonJS({
6487
6475
  }
6488
6476
  });
6489
6477
 
6490
- // src/index.js
6478
+ // src/index.ts
6491
6479
  var index_exports = {};
6492
6480
  __export(index_exports, {
6493
6481
  Client: () => Client2,
@@ -6610,10 +6598,10 @@ function walkCyclical(value2, visitor, seen = /* @__PURE__ */ new WeakSet(), par
6610
6598
  return { duplicates, circular };
6611
6599
  }
6612
6600
 
6613
- // src/game-factory/move/move-factory.js
6601
+ // src/game-factory/move/move-factory.ts
6614
6602
  var import_core2 = __toESM(require_core());
6615
6603
 
6616
- // src/game-factory/entity.js
6604
+ // src/game-factory/entity.ts
6617
6605
  var Entity = class {
6618
6606
  constructor(options, rule, id) {
6619
6607
  if (!options?.fromBank) {
@@ -6641,10 +6629,10 @@ var Entity = class {
6641
6629
  }
6642
6630
  };
6643
6631
 
6644
- // src/game-factory/space/space.js
6632
+ // src/game-factory/space/space.ts
6645
6633
  var Space = class extends Entity {
6646
- constructor(...args) {
6647
- super(...args);
6634
+ constructor(options, rule, id) {
6635
+ super(options, rule, id);
6648
6636
  this.entities = [];
6649
6637
  }
6650
6638
  placeEntity(entity, position = "Last") {
@@ -6667,24 +6655,27 @@ var Space = class extends Entity {
6667
6655
  }
6668
6656
  };
6669
6657
 
6670
- // src/game-factory/board.js
6658
+ // src/game-factory/board.ts
6671
6659
  var Board = class extends Space {
6672
6660
  };
6673
6661
 
6674
- // src/game-factory/space-group/space-group.js
6662
+ // src/game-factory/space-group/space-group.ts
6675
6663
  var SpaceGroup = class extends Entity {
6676
- constructor(options, ...rest) {
6677
- super(options, ...rest);
6664
+ constructor(options, rule, id) {
6665
+ super(options, rule, id);
6678
6666
  this.spaces = this.makeSpaces(options.bank);
6679
6667
  }
6680
6668
  makeSpaces(bank) {
6681
- return Array(this.getSpacesCount()).fill().map((_2, i2) => bank.createEntity({ entityType: "Space", index: i2 }));
6669
+ return Array(this.getSpacesCount()).fill(void 0).map((_2, i2) => bank.createEntity({ entityType: "Space", index: i2 }));
6682
6670
  }
6683
6671
  getEmptySpaces() {
6684
6672
  return this.spaces.filter((space2) => space2.isEmpty());
6685
6673
  }
6686
- getSpace(index) {
6687
- return this.spaces[index];
6674
+ getSpace(arg) {
6675
+ if (Array.isArray(arg)) {
6676
+ throw new Error("Numeric index only for SpaceGroup#getSpace");
6677
+ }
6678
+ return this.spaces[arg];
6688
6679
  }
6689
6680
  getEntities(index) {
6690
6681
  return this.getSpace(index).entities;
@@ -6692,9 +6683,12 @@ var SpaceGroup = class extends Entity {
6692
6683
  placeEntity(index, entity) {
6693
6684
  this.getSpace(index).placeEntity(entity);
6694
6685
  }
6686
+ getSpacesCount() {
6687
+ throw new Error("SpaceGroup#getSpacesCount must be implemented by subclass");
6688
+ }
6695
6689
  };
6696
6690
 
6697
- // src/game-factory/space-group/grid.js
6691
+ // src/game-factory/space-group/grid.ts
6698
6692
  var import_chunk = __toESM(require_chunk());
6699
6693
  var Grid = class extends SpaceGroup {
6700
6694
  getSpacesCount() {
@@ -6714,8 +6708,11 @@ var Grid = class extends SpaceGroup {
6714
6708
  const { width } = this.rule;
6715
6709
  return y2 * width + x2;
6716
6710
  }
6717
- getSpace(coordinates) {
6718
- return this.spaces[this.getIndex(coordinates)];
6711
+ getSpace(arg) {
6712
+ if (Array.isArray(arg)) {
6713
+ return this.spaces[this.getIndex(arg)];
6714
+ }
6715
+ return this.spaces[arg];
6719
6716
  }
6720
6717
  getRelativeCoordinates([oldX, oldY], [relativeX, relativeY]) {
6721
6718
  const newCoordinates = [oldX + relativeX, oldY + relativeY];
@@ -6726,29 +6723,30 @@ var Grid = class extends SpaceGroup {
6726
6723
  }
6727
6724
  };
6728
6725
 
6729
- // src/game-factory/bank/bank.js
6726
+ // src/game-factory/bank/bank.ts
6730
6727
  var import_find = __toESM(require_find());
6731
6728
  var import_filter = __toESM(require_filter());
6732
6729
 
6733
- // src/utils/resolve-properties.js
6730
+ // src/utils/resolve-properties.ts
6734
6731
  var import_isPlainObject2 = __toESM(require_isPlainObject());
6735
6732
  var import_pick = __toESM(require_pick());
6736
6733
 
6737
- // src/utils/get.js
6734
+ // src/utils/get.ts
6738
6735
  function get(obj, pathArray) {
6739
6736
  let current = obj;
6740
6737
  for (const step of pathArray) {
6741
6738
  if (current === void 0) {
6742
6739
  return current;
6743
6740
  }
6744
- if (step?.flatten) {
6741
+ if (step && typeof step === "object" && "flatten" in step && step.flatten) {
6745
6742
  if (!Array.isArray(current)) {
6746
6743
  return void 0;
6747
6744
  }
6748
- current = current.flat();
6745
+ let flat = current.flat();
6749
6746
  if (step.map) {
6750
- current = current.map((item) => get(item, step.map));
6747
+ flat = flat.map((item) => get(item, step.map));
6751
6748
  }
6749
+ current = flat;
6752
6750
  } else {
6753
6751
  current = current[step];
6754
6752
  }
@@ -8362,36 +8360,43 @@ Parser.prototype.isOperatorEnabled = function(op) {
8362
8360
  return !(optionName in operators) || !!operators[optionName];
8363
8361
  };
8364
8362
 
8365
- // src/utils/resolve-expression.js
8363
+ // src/utils/resolve-expression.ts
8366
8364
  var parser = new Parser();
8367
- parser.functions.sum = (array) => array.reduce((acc, val) => acc + val, 0);
8365
+ parser.functions.sum = (...args) => args[0].reduce((acc, val) => acc + val, 0);
8368
8366
  function resolveExpression2(bgioArguments, rule, context) {
8369
8367
  const args = resolveProperties(bgioArguments, rule.arguments, context);
8370
8368
  return parser.evaluate(rule.expression, args);
8371
8369
  }
8372
8370
 
8373
- // src/utils/resolve-entity.js
8371
+ // src/utils/resolve-entity.ts
8374
8372
  var import_isPlainObject = __toESM(require_isPlainObject());
8373
+
8374
+ // src/utils/bgio-resolve-types.ts
8375
+ function bankOf(bg) {
8376
+ return bg.G.bank;
8377
+ }
8378
+
8379
+ // src/utils/resolve-entity.ts
8375
8380
  var abstractTargetNames = ["state"];
8376
8381
  function resolveEntity(bgioArguments, target, context, targetName) {
8377
- return !abstractTargetNames.includes(targetName) && (0, import_isPlainObject.default)(target) ? bgioArguments.G.bank.find(bgioArguments, target, context) : target;
8382
+ return !abstractTargetNames.includes(targetName ?? "") && (0, import_isPlainObject.default)(target) ? bankOf(bgioArguments).find(bgioArguments, target, context) : target;
8378
8383
  }
8379
8384
 
8380
- // src/utils/resolve-properties.js
8385
+ // src/utils/resolve-properties.ts
8381
8386
  var resolutionTerminators = [
8382
8387
  "conditions",
8383
8388
  "move",
8384
8389
  "then",
8385
8390
  "mapping"
8386
8391
  ];
8387
- function resolveProperties(bgioArguments, obj, context, key) {
8392
+ function resolveProperties(bgioArguments, obj, context = {}, key) {
8388
8393
  if (!(0, import_isPlainObject2.default)(obj) && !Array.isArray(obj)) {
8389
8394
  return obj;
8390
8395
  }
8391
8396
  let resolvedProperties = Array.isArray(obj) ? [...obj] : { ...obj };
8392
- Object.entries(obj).forEach(([key2, value2]) => {
8393
- if (!resolutionTerminators.includes(key2)) {
8394
- resolvedProperties[key2] = resolveProperties(bgioArguments, value2, context, key2);
8397
+ Object.entries(obj).forEach(([k2, value2]) => {
8398
+ if (!resolutionTerminators.includes(k2)) {
8399
+ resolvedProperties[k2] = resolveProperties(bgioArguments, value2, context, k2);
8395
8400
  }
8396
8401
  });
8397
8402
  const resolved = resolveProperty(bgioArguments, resolvedProperties, context);
@@ -8404,45 +8409,47 @@ function resolveProperties(bgioArguments, obj, context, key) {
8404
8409
  ) : resolved;
8405
8410
  }
8406
8411
  function resolveProperty(bgioArguments, value2, context) {
8407
- if (value2?.type === "expression") {
8412
+ const v2 = value2;
8413
+ if (v2?.type === "expression") {
8414
+ const expr = v2;
8408
8415
  return resolveExpression2(
8409
8416
  bgioArguments,
8410
8417
  {
8411
- ...value2,
8412
- arguments: resolveProperties(bgioArguments, value2.arguments, context, "arguments")
8418
+ ...expr,
8419
+ arguments: resolveProperties(bgioArguments, expr.arguments, context, "arguments")
8413
8420
  },
8414
8421
  context
8415
8422
  );
8416
- } else if (value2?.type === "count") {
8417
- return bgioArguments.G.bank.findAll(
8423
+ } else if (v2?.type === "count") {
8424
+ return bankOf(bgioArguments).findAll(
8418
8425
  bgioArguments,
8419
8426
  value2,
8420
8427
  context
8421
8428
  ).length;
8422
- } else if (value2?.type === "contextPath") {
8423
- return get(context, value2.path);
8424
- } else if (value2?.type === "ctxPath") {
8425
- return get(bgioArguments.ctx, value2.path);
8426
- } else if (value2?.type === "gamePath") {
8427
- return get(bgioArguments.G, value2.path);
8428
- } else if (value2?.type === "relativePath" || value2?.type === "RelativePath") {
8429
- const target = resolveProperties(bgioArguments, value2.target, context, "target");
8430
- return get(target.attributes, value2.path) ?? null;
8431
- } else if (value2?.type === "parent" || value2?.type === "Parent") {
8432
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8433
- return bgioArguments.G.bank.findParent(originalTarget) ?? null;
8434
- } else if (value2?.type === "map") {
8429
+ } else if (v2?.type === "contextPath") {
8430
+ return get(context, v2.path);
8431
+ } else if (v2?.type === "ctxPath") {
8432
+ return get(bgioArguments.ctx, v2.path);
8433
+ } else if (v2?.type === "gamePath") {
8434
+ return get(bgioArguments.G, v2.path);
8435
+ } else if (v2?.type === "relativePath" || v2?.type === "RelativePath") {
8436
+ const target = resolveProperties(bgioArguments, v2.target, context, "target");
8437
+ return get(target?.attributes, v2.path) ?? null;
8438
+ } else if (v2?.type === "parent" || v2?.type === "Parent") {
8439
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8440
+ return bankOf(bgioArguments).findParent(originalTarget) ?? null;
8441
+ } else if (v2?.type === "map") {
8435
8442
  return getMappedTargets(
8436
8443
  bgioArguments,
8437
- value2.targets,
8438
- value2.mapping,
8444
+ v2.targets,
8445
+ v2.mapping,
8439
8446
  context
8440
8447
  ).map((mappedTarget) => mappedTarget.value);
8441
- } else if (value2?.type === "mapMax") {
8448
+ } else if (v2?.type === "mapMax") {
8442
8449
  const mappedTargets = getMappedTargets(
8443
8450
  bgioArguments,
8444
- value2.targets,
8445
- value2.mapping,
8451
+ v2.targets,
8452
+ v2.mapping,
8446
8453
  context
8447
8454
  );
8448
8455
  let maxValue;
@@ -8458,28 +8465,28 @@ function resolveProperty(bgioArguments, value2, context) {
8458
8465
  }
8459
8466
  }
8460
8467
  return maxTargets;
8461
- } else if (value2?.type === "pick" || value2?.type === "Pick") {
8462
- const target = resolveProperties(bgioArguments, value2.target, context, "target");
8468
+ } else if (v2?.type === "pick" || v2?.type === "Pick") {
8469
+ const target = resolveProperties(bgioArguments, v2.target, context, "target");
8463
8470
  return (0, import_pick.default)(
8464
8471
  resolveProperties(
8465
8472
  bgioArguments,
8466
- target.attributes,
8473
+ target?.attributes,
8467
8474
  context,
8468
8475
  "attributes"
8469
8476
  ),
8470
- value2.properties
8477
+ v2.properties
8471
8478
  );
8472
- } else if (value2?.type === "coordinates" || value2?.type === "Coordinates") {
8473
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8474
- const parent = bgioArguments.G.bank.findParent(originalTarget);
8479
+ } else if (v2?.type === "coordinates" || v2?.type === "Coordinates") {
8480
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8481
+ const parent = bankOf(bgioArguments).findParent(originalTarget);
8475
8482
  return parent.getCoordinates(originalTarget.rule.index);
8476
- } else if (value2?.type === "relativeCoordinates") {
8477
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8478
- const parent = bgioArguments.G.bank.findParent(originalTarget);
8483
+ } else if (v2?.type === "relativeCoordinates") {
8484
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8485
+ const parent = bankOf(bgioArguments).findParent(originalTarget);
8479
8486
  const oldCoordinates = parent.getCoordinates(originalTarget.rule.index);
8480
8487
  const newCoordinates = parent.getRelativeCoordinates(
8481
8488
  oldCoordinates,
8482
- resolveProperties(bgioArguments, value2.location, context, "location")
8489
+ resolveProperties(bgioArguments, v2.location, context, "location")
8483
8490
  );
8484
8491
  return (newCoordinates && parent.spaces[parent.getIndex(newCoordinates)]) ?? null;
8485
8492
  } else {
@@ -8488,7 +8495,8 @@ function resolveProperty(bgioArguments, value2, context) {
8488
8495
  }
8489
8496
  function getMappedTargets(bgioArguments, targetsRule, mapping, context) {
8490
8497
  targetsRule.resolveAsEntity = true;
8491
- return resolveProperties(bgioArguments, targetsRule, context)?.map((target) => ({
8498
+ const resolved = resolveProperties(bgioArguments, targetsRule, context);
8499
+ return resolved?.map((target) => ({
8492
8500
  target,
8493
8501
  value: resolveProperties(
8494
8502
  bgioArguments,
@@ -8498,7 +8506,7 @@ function getMappedTargets(bgioArguments, targetsRule, mapping, context) {
8498
8506
  })) ?? [];
8499
8507
  }
8500
8508
 
8501
- // src/game-factory/condition/condition.js
8509
+ // src/game-factory/condition/condition.ts
8502
8510
  var Condition = class {
8503
8511
  constructor(rule) {
8504
8512
  this.rule = rule;
@@ -8523,11 +8531,15 @@ var Condition = class {
8523
8531
  return this.checkCondition(bgioArguments, rule, conditionPayload, newContext);
8524
8532
  }
8525
8533
  isMet(...args) {
8526
- return this.check(...args).conditionIsMet;
8534
+ return this.check(
8535
+ args[0],
8536
+ args[1] ?? {},
8537
+ args[2] ?? {}
8538
+ ).conditionIsMet;
8527
8539
  }
8528
8540
  };
8529
8541
 
8530
- // src/utils/entity-matches.js
8542
+ // src/utils/entity-matches.ts
8531
8543
  var import_matches = __toESM(require_matches());
8532
8544
  function resolveMatcher(bgioArguments, matcher, context) {
8533
8545
  const resolvedMatcher = { ...matcher };
@@ -8545,7 +8557,7 @@ function entityMatches(bgioArguments, matcher, entity, context) {
8545
8557
  return (0, import_matches.default)(resolveMatcher(bgioArguments, matcher, context))(getEntityMatcher(entity));
8546
8558
  }
8547
8559
 
8548
- // src/game-factory/condition/is-condition.js
8560
+ // src/game-factory/condition/is-condition.ts
8549
8561
  var Is = class extends Condition {
8550
8562
  checkCondition(bgioArguments, rule, { target }, context) {
8551
8563
  if (this.rule.entity && target !== rule.entity) {
@@ -8566,12 +8578,12 @@ var Is = class extends Condition {
8566
8578
  }
8567
8579
  };
8568
8580
 
8569
- // src/game-factory/condition/not-condition.js
8581
+ // src/game-factory/condition/not-condition.ts
8570
8582
  var NotCondition = class extends Condition {
8571
8583
  checkCondition(bgioArguments, rule, payload, context) {
8572
8584
  const result = checkConditions(
8573
8585
  bgioArguments,
8574
- rule,
8586
+ rule.conditions,
8575
8587
  payload,
8576
8588
  context
8577
8589
  );
@@ -8579,8 +8591,8 @@ var NotCondition = class extends Condition {
8579
8591
  }
8580
8592
  };
8581
8593
 
8582
- // src/utils/find-met-condition.js
8583
- function findMetCondition(bgioArguments, { conditions = [] }, payload, context) {
8594
+ // src/utils/find-met-condition.ts
8595
+ function findMetCondition(bgioArguments, conditions = [], payload, context) {
8584
8596
  let success;
8585
8597
  for (const conditionRule of conditions) {
8586
8598
  const result = conditionFactory(conditionRule).check(bgioArguments, payload, context);
@@ -8595,12 +8607,12 @@ function findMetCondition(bgioArguments, { conditions = [] }, payload, context)
8595
8607
  return success;
8596
8608
  }
8597
8609
 
8598
- // src/game-factory/condition/or-condition.js
8610
+ // src/game-factory/condition/or-condition.ts
8599
8611
  var Or = class extends Condition {
8600
8612
  checkCondition(bgioArguments, rule, payload, context) {
8601
8613
  const result = findMetCondition(
8602
8614
  bgioArguments,
8603
- rule,
8615
+ rule.conditions,
8604
8616
  payload,
8605
8617
  context
8606
8618
  );
@@ -8608,9 +8620,10 @@ var Or = class extends Condition {
8608
8620
  }
8609
8621
  };
8610
8622
 
8611
- // src/game-factory/condition/some-condition.js
8623
+ // src/game-factory/condition/some-condition.ts
8612
8624
  var SomeCondition = class extends Condition {
8613
- checkCondition(bgioArguments, rule, { target: targets }, context) {
8625
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8626
+ const targets = conditionPayload.target;
8614
8627
  const result = targets.find((target) => {
8615
8628
  const loopContext = {
8616
8629
  ...context,
@@ -8618,7 +8631,7 @@ var SomeCondition = class extends Condition {
8618
8631
  };
8619
8632
  return checkConditions(
8620
8633
  bgioArguments,
8621
- rule,
8634
+ rule.conditions,
8622
8635
  void 0,
8623
8636
  loopContext
8624
8637
  ).conditionsAreMet;
@@ -8630,9 +8643,10 @@ var SomeCondition = class extends Condition {
8630
8643
  }
8631
8644
  };
8632
8645
 
8633
- // src/game-factory/condition/every-condition.js
8646
+ // src/game-factory/condition/every-condition.ts
8634
8647
  var EveryCondition = class extends Condition {
8635
- checkCondition(bgioArguments, rule, { target: targets }, context) {
8648
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8649
+ const targets = conditionPayload.target;
8636
8650
  const results = targets.map((target) => {
8637
8651
  const loopContext = {
8638
8652
  ...context,
@@ -8640,7 +8654,7 @@ var EveryCondition = class extends Condition {
8640
8654
  };
8641
8655
  return checkConditions(
8642
8656
  bgioArguments,
8643
- rule,
8657
+ rule.conditions,
8644
8658
  void 0,
8645
8659
  loopContext
8646
8660
  );
@@ -8652,18 +8666,18 @@ var EveryCondition = class extends Condition {
8652
8666
  }
8653
8667
  };
8654
8668
 
8655
- // src/game-factory/condition/contains-condition.js
8669
+ // src/game-factory/condition/contains-condition.ts
8656
8670
  var import_matches2 = __toESM(require_matches());
8657
8671
  var ContainsCondition = class extends Condition {
8658
8672
  checkCondition(bgioArguments, rule, payload, context) {
8659
- const { target } = payload;
8673
+ const target = payload.target;
8660
8674
  if (!target) {
8661
8675
  return { matches: [], conditionIsMet: false };
8662
8676
  } else {
8663
8677
  const candidates = target.entities ?? target.spaces;
8664
8678
  const matches2 = candidates?.filter((entity) => checkConditions(
8665
8679
  bgioArguments,
8666
- rule,
8680
+ rule.conditions,
8667
8681
  { target: entity },
8668
8682
  context
8669
8683
  ).conditionsAreMet) ?? [];
@@ -8672,22 +8686,25 @@ var ContainsCondition = class extends Condition {
8672
8686
  }
8673
8687
  };
8674
8688
 
8675
- // src/game-factory/condition/contains-same-condition.js
8689
+ // src/game-factory/condition/contains-same-condition.ts
8676
8690
  var import_pick2 = __toESM(require_pick());
8677
8691
  var ContainsSame = class extends Condition {
8678
- checkCondition(bgioArguments, rule, { targets }) {
8692
+ checkCondition(bgioArguments, rule, conditionPayload, _newContext) {
8693
+ const { targets } = conditionPayload;
8679
8694
  if (targets.length === 1 && targets[0].entities?.length) {
8680
8695
  return { conditionIsMet: true };
8681
8696
  }
8682
8697
  const [first, ...restEntities] = targets;
8683
- const conditionIsMet = first.entities.some((entity) => {
8698
+ const conditionIsMet = (first.entities ?? []).some((entity) => {
8699
+ const e = entity;
8684
8700
  const condition2 = conditionFactory({
8685
8701
  conditionType: "Contains",
8686
8702
  conditions: [{
8687
8703
  conditionType: "Is",
8688
- matcher: (0, import_pick2.default)(entity.rule, rule.properties)
8704
+ matcher: (0, import_pick2.default)(e.rule, rule.properties)
8689
8705
  }]
8690
8706
  });
8707
+ if (!condition2) return false;
8691
8708
  return restEntities.every((ent) => {
8692
8709
  return condition2.isMet(bgioArguments, { target: ent });
8693
8710
  });
@@ -8696,7 +8713,7 @@ var ContainsSame = class extends Condition {
8696
8713
  }
8697
8714
  };
8698
8715
 
8699
- // src/utils/grid-contains-sequence.js
8716
+ // src/utils/grid-contains-sequence.ts
8700
8717
  var import_matches3 = __toESM(require_matches());
8701
8718
  var directions = [
8702
8719
  [1, 0],
@@ -8815,12 +8832,9 @@ function tryMatchSequence(bgioArguments, lineSpaces, startIndex, sequencePattern
8815
8832
  return matchedSpaces.length > 0 ? matchedSpaces : null;
8816
8833
  }
8817
8834
  function checkSpaceConditions(bgioArguments, space2, conditions, chunkMatches = [], context) {
8818
- if (!conditions || conditions.length === 0) {
8819
- return true;
8820
- }
8821
8835
  return checkConditions(
8822
8836
  bgioArguments,
8823
- { conditions },
8837
+ conditions,
8824
8838
  {
8825
8839
  target: space2,
8826
8840
  targets: [space2, ...chunkMatches]
@@ -8869,13 +8883,18 @@ function gridContainsSequence(bgioArguments, grid, sequencePattern, context) {
8869
8883
  return result;
8870
8884
  }
8871
8885
 
8872
- // src/game-factory/condition/in-line-condition.js
8886
+ // src/game-factory/condition/in-line-condition.ts
8873
8887
  var InLineCondition = class extends Condition {
8874
8888
  checkCondition(bgioArguments, rule, payload, context) {
8875
8889
  const { G: G2 } = bgioArguments;
8876
8890
  const { target } = payload;
8877
8891
  const parent = G2.bank.findParent(payload.target);
8878
- const { matches: allMatches } = gridContainsSequence(bgioArguments, parent, rule.sequence, context);
8892
+ const { matches: allMatches } = gridContainsSequence(
8893
+ bgioArguments,
8894
+ parent,
8895
+ rule.sequence,
8896
+ context
8897
+ );
8879
8898
  const matches2 = allMatches.filter(
8880
8899
  (sequence) => sequence.some((space2) => space2 === target)
8881
8900
  );
@@ -8883,7 +8902,7 @@ var InLineCondition = class extends Condition {
8883
8902
  }
8884
8903
  };
8885
8904
 
8886
- // src/game-factory/condition/has-line-condition.js
8905
+ // src/game-factory/condition/has-line-condition.ts
8887
8906
  var HasLineCondition = class extends Condition {
8888
8907
  checkCondition(bgioArguments, rule, payload, context) {
8889
8908
  const { matches: matches2 } = gridContainsSequence(
@@ -8896,16 +8915,17 @@ var HasLineCondition = class extends Condition {
8896
8915
  }
8897
8916
  };
8898
8917
 
8899
- // src/game-factory/condition/is-full-condition.js
8918
+ // src/game-factory/condition/is-full-condition.ts
8900
8919
  var IsFull = class extends Condition {
8901
- checkCondition(bgioArguments, rule, payload, context) {
8920
+ checkCondition(_bgioArguments, _rule, payload, _context) {
8921
+ const t2 = payload.target;
8902
8922
  return {
8903
- conditionIsMet: payload.target.spaces.every((space2) => space2?.entities.length)
8923
+ conditionIsMet: t2.spaces.every((space2) => space2?.entities?.length)
8904
8924
  };
8905
8925
  }
8906
8926
  };
8907
8927
 
8908
- // src/utils/simulate-move.js
8928
+ // src/utils/simulate-move.ts
8909
8929
  function simulateMove(bgioArguments, payload, context) {
8910
8930
  const simulatedG = deserialize(serialize(bgioArguments.G), registry);
8911
8931
  const newBgioArguments = {
@@ -8925,7 +8945,7 @@ function simulateMove(bgioArguments, payload, context) {
8925
8945
  return simulatedG;
8926
8946
  }
8927
8947
 
8928
- // src/game-factory/condition/would-condition.js
8948
+ // src/game-factory/condition/would-condition.ts
8929
8949
  var argNameMap = {
8930
8950
  PlaceNew: ["destination"],
8931
8951
  RemoveEntity: ["entity"],
@@ -8934,12 +8954,16 @@ var argNameMap = {
8934
8954
  SetState: ["entity", "state"]
8935
8955
  };
8936
8956
  var WouldCondition = class extends Condition {
8937
- checkCondition(bgioArguments, rule, { target, targets = [target] }, context) {
8957
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8958
+ const target = conditionPayload.target;
8959
+ const targets = conditionPayload.targets ?? [target];
8960
+ const moveType = context.moveInstance?.rule?.moveType;
8961
+ const argNames = moveType ? argNameMap[moveType] : void 0;
8938
8962
  const payload = {
8939
- arguments: targets.reduce((acc, target2, i2) => ({
8940
- ...acc,
8941
- [argNameMap[context.moveInstance.rule.moveType][i2]]: target2
8942
- }), {})
8963
+ arguments: targets.reduce((acc, t2, i2) => {
8964
+ const key = argNames?.[i2] ?? `arg${i2}`;
8965
+ return { ...acc, [key]: t2 };
8966
+ }, {})
8943
8967
  };
8944
8968
  const simulatedG = simulateMove(
8945
8969
  bgioArguments,
@@ -8957,11 +8981,8 @@ var WouldCondition = class extends Condition {
8957
8981
  };
8958
8982
  }
8959
8983
  const conditionResults = checkConditions(
8960
- {
8961
- ...bgioArguments,
8962
- G: simulatedG
8963
- },
8964
- rule,
8984
+ { ...bgioArguments, G: simulatedG },
8985
+ rule.conditions,
8965
8986
  simulatedConditionsPayload,
8966
8987
  context
8967
8988
  );
@@ -8989,26 +9010,26 @@ function restoreReferences(obj, getOriginalEntity, seen = /* @__PURE__ */ new We
8989
9010
  }
8990
9011
  if (Array.isArray(obj)) {
8991
9012
  return obj.map((item) => restoreReferences(item, getOriginalEntity, seen));
8992
- } else {
8993
- const restored = {};
8994
- for (const key in obj) {
8995
- if (obj.hasOwnProperty(key)) {
8996
- restored[key] = restoreReferences(obj[key], getOriginalEntity, seen);
8997
- }
9013
+ }
9014
+ const restored = {};
9015
+ for (const key in obj) {
9016
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
9017
+ restored[key] = restoreReferences(obj[key], getOriginalEntity, seen);
8998
9018
  }
8999
- return restored;
9000
9019
  }
9020
+ return restored;
9001
9021
  }
9002
9022
 
9003
- // src/utils/any-valid-moves.js
9023
+ // src/utils/any-valid-moves.ts
9004
9024
  var import_isPlainObject3 = __toESM(require_isPlainObject());
9005
9025
  function findMoveArgumentReferences(obj, refs = /* @__PURE__ */ new Set()) {
9006
9026
  if (!obj || typeof obj !== "object") {
9007
9027
  return refs;
9008
9028
  }
9009
- if (obj.type === "contextPath" && Array.isArray(obj.path)) {
9010
- if (obj.path[0] === "moveArguments" && obj.path[1]) {
9011
- refs.add(obj.path[1]);
9029
+ const o2 = obj;
9030
+ if (o2.type === "contextPath" && Array.isArray(o2.path)) {
9031
+ if (o2.path[0] === "moveArguments" && o2.path[1]) {
9032
+ refs.add(String(o2.path[1]));
9012
9033
  }
9013
9034
  }
9014
9035
  for (const value2 of Object.values(obj)) {
@@ -9082,21 +9103,23 @@ function findValidCombination(bgioArguments, moveInstance, ruleArguments, ordere
9082
9103
  });
9083
9104
  }
9084
9105
  function areThereValidMoves(bgioArguments, moves) {
9106
+ const bgio = bgioArguments;
9085
9107
  return Object.values(moves).some((move) => {
9086
- const { moveInstance } = move;
9108
+ const moveInstance = move?.moveInstance;
9109
+ if (!moveInstance) return false;
9087
9110
  const context = { moveInstance };
9088
9111
  const rule = resolveProperties(
9089
- bgioArguments,
9112
+ bgio,
9090
9113
  moveInstance.rule,
9091
9114
  context
9092
9115
  );
9093
9116
  const ruleArguments = rule.arguments ?? {};
9094
9117
  if (Object.keys(ruleArguments).length === 0) {
9095
- return moveInstance.isValid(bgioArguments, { arguments: {} }, context);
9118
+ return moveInstance.isValid(bgio, { arguments: {} }, context);
9096
9119
  }
9097
9120
  const orderedArgNames = getArgumentOrder(ruleArguments);
9098
9121
  return findValidCombination(
9099
- bgioArguments,
9122
+ bgio,
9100
9123
  moveInstance,
9101
9124
  ruleArguments,
9102
9125
  orderedArgNames,
@@ -9105,18 +9128,19 @@ function areThereValidMoves(bgioArguments, moves) {
9105
9128
  });
9106
9129
  }
9107
9130
 
9108
- // src/utils/get-current-moves.js
9109
- function getCurrentMoves(state, { game, playerID, stageName }) {
9131
+ // src/utils/get-current-moves.ts
9132
+ function getCurrentMoves(state, client) {
9133
+ const { game, playerID, stageName } = client;
9110
9134
  const phaseName = state.ctx.phase;
9111
- const stageNameToUse = stageName ?? state.ctx.activePlayers?.[playerID ?? state.ctx.currentPlayer];
9135
+ const stageNameToUse = stageName ?? state.ctx.activePlayers?.[playerID ?? state.ctx.currentPlayer ?? ""];
9112
9136
  const phaseOrRoot = game.phases?.[phaseName] ?? game;
9113
9137
  const stageOrPhaseOrRoot = phaseOrRoot.turn?.stages?.[stageNameToUse] ?? phaseOrRoot;
9114
9138
  return stageOrPhaseOrRoot.moves ?? {};
9115
9139
  }
9116
9140
 
9117
- // src/game-factory/condition/no-possible-moves-condition.js
9141
+ // src/game-factory/condition/no-possible-moves-condition.ts
9118
9142
  var NoPossibleMoves = class extends Condition {
9119
- checkCondition(bgioArguments, _2, __, context) {
9143
+ checkCondition(bgioArguments, _unused, _payload, context) {
9120
9144
  return {
9121
9145
  conditionIsMet: !areThereValidMoves(
9122
9146
  bgioArguments,
@@ -9126,7 +9150,7 @@ var NoPossibleMoves = class extends Condition {
9126
9150
  }
9127
9151
  };
9128
9152
 
9129
- // src/game-factory/condition/evaluate-condition.js
9153
+ // src/game-factory/condition/evaluate-condition.ts
9130
9154
  var import_matches4 = __toESM(require_matches());
9131
9155
  var Evaluate = class extends Condition {
9132
9156
  checkCondition(bgioArguments, rule, payload, context) {
@@ -9143,11 +9167,12 @@ var Evaluate = class extends Condition {
9143
9167
  }
9144
9168
  };
9145
9169
 
9146
- // src/game-factory/condition/position-condition.js
9170
+ // src/game-factory/condition/position-condition.ts
9147
9171
  var Position = class extends Condition {
9148
- checkCondition(bgioArguments, rule, { target }) {
9172
+ checkCondition(bgioArguments, rule, conditionPayload, _newContext) {
9173
+ const target = conditionPayload.target;
9149
9174
  const parent = bgioArguments.G.bank.findParent(target);
9150
- let conditionIsMet;
9175
+ let conditionIsMet = false;
9151
9176
  if (rule.position === "First") {
9152
9177
  conditionIsMet = parent.entities.indexOf(target) === 0;
9153
9178
  }
@@ -9155,42 +9180,46 @@ var Position = class extends Condition {
9155
9180
  }
9156
9181
  };
9157
9182
 
9158
- // src/game-factory/condition/condition-factory.js
9183
+ // src/game-factory/condition/condition-factory.ts
9159
9184
  function conditionFactory(rule) {
9160
- if (rule.conditionType === "Is") {
9161
- return new Is(rule);
9162
- } else if (rule.conditionType === "Not") {
9163
- return new NotCondition(rule);
9164
- } else if (rule.conditionType === "Or") {
9165
- return new Or(rule);
9166
- } else if (rule.conditionType === "Some") {
9167
- return new SomeCondition(rule);
9168
- } else if (rule.conditionType === "Contains") {
9169
- return new ContainsCondition(rule);
9170
- } else if (rule.conditionType === "ContainsSame") {
9171
- return new ContainsSame(rule);
9172
- } else if (rule.conditionType === "Every") {
9173
- return new EveryCondition(rule);
9174
- } else if (rule.conditionType === "InLine") {
9175
- return new InLineCondition(rule);
9176
- } else if (rule.conditionType === "HasLine") {
9177
- return new HasLineCondition(rule);
9178
- } else if (rule.conditionType === "IsFull") {
9179
- return new IsFull(rule);
9180
- } else if (rule.conditionType === "Would") {
9181
- return new WouldCondition(rule);
9182
- } else if (rule.conditionType === "NoPossibleMoves") {
9183
- return new NoPossibleMoves(rule);
9184
- } else if (rule.conditionType === "Evaluate") {
9185
- return new Evaluate(rule);
9186
- } else if (rule.conditionType === "Position") {
9187
- return new Position(rule);
9188
- }
9189
- }
9190
-
9191
- // src/utils/check-conditions.js
9192
- function checkConditions(bgioArguments, rule, payload, context) {
9193
- const { conditions = [] } = rule;
9185
+ if (typeof rule !== "object" || rule === null || !("conditionType" in rule)) {
9186
+ return void 0;
9187
+ }
9188
+ const r2 = rule;
9189
+ if (r2.conditionType === "Is") {
9190
+ return new Is(r2);
9191
+ } else if (r2.conditionType === "Not") {
9192
+ return new NotCondition(r2);
9193
+ } else if (r2.conditionType === "Or") {
9194
+ return new Or(r2);
9195
+ } else if (r2.conditionType === "Some") {
9196
+ return new SomeCondition(r2);
9197
+ } else if (r2.conditionType === "Contains") {
9198
+ return new ContainsCondition(r2);
9199
+ } else if (r2.conditionType === "ContainsSame") {
9200
+ return new ContainsSame(r2);
9201
+ } else if (r2.conditionType === "Every") {
9202
+ return new EveryCondition(r2);
9203
+ } else if (r2.conditionType === "InLine") {
9204
+ return new InLineCondition(r2);
9205
+ } else if (r2.conditionType === "HasLine") {
9206
+ return new HasLineCondition(r2);
9207
+ } else if (r2.conditionType === "IsFull") {
9208
+ return new IsFull(r2);
9209
+ } else if (r2.conditionType === "Would") {
9210
+ return new WouldCondition(r2);
9211
+ } else if (r2.conditionType === "NoPossibleMoves") {
9212
+ return new NoPossibleMoves(r2);
9213
+ } else if (r2.conditionType === "Evaluate") {
9214
+ return new Evaluate(r2);
9215
+ } else if (r2.conditionType === "Position") {
9216
+ return new Position(r2);
9217
+ }
9218
+ return void 0;
9219
+ }
9220
+
9221
+ // src/utils/check-conditions.ts
9222
+ function checkConditions(bgioArguments, conditions = [], payload = {}, context = {}) {
9194
9223
  const results = [];
9195
9224
  let failedAt;
9196
9225
  for (const conditionRule of conditions) {
@@ -9209,18 +9238,18 @@ function checkConditions(bgioArguments, rule, payload, context) {
9209
9238
  };
9210
9239
  }
9211
9240
 
9212
- // src/game-factory/bank/bank-slot.js
9241
+ // src/game-factory/bank/bank-slot.ts
9213
9242
  var BankSlot = class {
9214
9243
  constructor(rule, bank) {
9215
9244
  this.bank = bank;
9216
9245
  this.rule = rule;
9217
9246
  this.pool = [];
9218
- this.remaining = +rule.count || 1;
9247
+ this.remaining = +(rule.count || 1);
9219
9248
  }
9220
9249
  getOne(bgioArguments, options, context) {
9221
9250
  return this.getMultiple(bgioArguments, 1, options, context)[0];
9222
9251
  }
9223
- getMultiple(bgioArguments, count = Infinity, options = {}, context) {
9252
+ getMultiple(bgioArguments, count = Infinity, options = {}, context = {}) {
9224
9253
  const toReturn = [];
9225
9254
  if (this.remaining === Infinity && count === Infinity) {
9226
9255
  throw new Error(`Cannot get infinite pieces from slot with infinite remaining: ${this.rule.name}`);
@@ -9245,7 +9274,10 @@ var BankSlot = class {
9245
9274
  if (options.state) {
9246
9275
  const newState = resolveProperties(bgioArguments, options.state, context);
9247
9276
  toReturn.forEach((entity) => {
9248
- entity.state = { ...entity.state, ...newState };
9277
+ entity.state = {
9278
+ ...entity.state,
9279
+ ...newState
9280
+ };
9249
9281
  });
9250
9282
  }
9251
9283
  return toReturn;
@@ -9264,7 +9296,7 @@ var BankSlot = class {
9264
9296
  };
9265
9297
  var bank_slot_default = BankSlot;
9266
9298
 
9267
- // src/game-factory/bank/bank.js
9299
+ // src/game-factory/bank/bank.ts
9268
9300
  var Bank = class {
9269
9301
  constructor(entityRules) {
9270
9302
  this.currentEntityId = 0;
@@ -9272,7 +9304,8 @@ var Bank = class {
9272
9304
  this.slots = entityRules.map((rule) => new bank_slot_default(rule, this));
9273
9305
  }
9274
9306
  createEntity(definition = {}, options) {
9275
- const entity = new registry[definition.entityType || "Entity"](
9307
+ const Ctor = registry[definition.entityType || "Entity"];
9308
+ const entity = new Ctor(
9276
9309
  {
9277
9310
  bank: this,
9278
9311
  fromBank: true,
@@ -9298,7 +9331,7 @@ var Bank = class {
9298
9331
  Object.values(this.tracker),
9299
9332
  (entity) => checkConditions(
9300
9333
  bgioArguments,
9301
- rule,
9334
+ rule.conditions,
9302
9335
  { target: entity },
9303
9336
  context
9304
9337
  ).conditionsAreMet
@@ -9337,7 +9370,7 @@ var Bank = class {
9337
9370
  return this.slots.find(
9338
9371
  (slot) => checkConditions(
9339
9372
  bgioArguments,
9340
- rule,
9373
+ rule.conditions,
9341
9374
  { target: slot },
9342
9375
  context
9343
9376
  ).conditionsAreMet
@@ -9347,7 +9380,7 @@ var Bank = class {
9347
9380
  return this.slots.filter(
9348
9381
  (slot) => checkConditions(
9349
9382
  bgioArguments,
9350
- rule,
9383
+ rule.conditions,
9351
9384
  { target: slot },
9352
9385
  context
9353
9386
  ).conditionsAreMet
@@ -9355,13 +9388,13 @@ var Bank = class {
9355
9388
  }
9356
9389
  returnToBank(bgioArguments, entity) {
9357
9390
  this.findParent(entity).remove(entity);
9358
- this.getSlot(bgioArguments, entity.rule).returnToBank(entity);
9391
+ this.getSlot(bgioArguments, entity.rule, {}).returnToBank(entity);
9359
9392
  delete this.tracker[entity.entityId];
9360
9393
  }
9361
9394
  };
9362
9395
  var bank_default = Bank;
9363
9396
 
9364
- // src/registry.js
9397
+ // src/registry.ts
9365
9398
  var registry = {
9366
9399
  Board,
9367
9400
  SpaceGroup,
@@ -9372,7 +9405,7 @@ var registry = {
9372
9405
  Entity
9373
9406
  };
9374
9407
 
9375
- // src/utils/deserialize-bgio-arguments.js
9408
+ // src/utils/deserialize-bgio-arguments.ts
9376
9409
  function deserializeBgioArguments(bgioArguments) {
9377
9410
  return {
9378
9411
  ...bgioArguments,
@@ -9380,14 +9413,15 @@ function deserializeBgioArguments(bgioArguments) {
9380
9413
  };
9381
9414
  }
9382
9415
 
9383
- // src/game-factory/move/move.js
9416
+ // src/game-factory/move/move.ts
9384
9417
  var import_core = __toESM(require_core());
9385
9418
  var Move = class {
9386
9419
  constructor(rule) {
9387
9420
  this.rule = this.transformRule(rule);
9388
9421
  }
9389
9422
  checkValidity(bgioArguments, payload, context) {
9390
- const argRuleEntries = Object.entries(this.rule.arguments ?? {});
9423
+ const moveArguments = "arguments" in this.rule && this.rule.arguments ? this.rule.arguments : {};
9424
+ const argRuleEntries = Object.entries(moveArguments);
9391
9425
  if (!argRuleEntries.every(([argName]) => {
9392
9426
  const arg = payload.arguments[argName];
9393
9427
  return arg !== void 0 && (!Array.isArray(arg) || arg.length);
@@ -9400,11 +9434,11 @@ var Move = class {
9400
9434
  const payloadArg = payload.arguments[argName];
9401
9435
  const args = Array.isArray(payloadArg) ? payloadArg : [payloadArg];
9402
9436
  const argResults = [];
9403
- for (let j2 = 0, len2 = args.length; j2 < len2; j2++) {
9437
+ for (let j2 = 0, lenj = args.length; j2 < lenj; j2++) {
9404
9438
  const arg = args[j2];
9405
9439
  const result = checkConditions(
9406
9440
  bgioArguments,
9407
- argRule,
9441
+ argRule.conditions,
9408
9442
  { target: arg },
9409
9443
  { ...context, moveArguments: payload.arguments }
9410
9444
  );
@@ -9413,7 +9447,8 @@ var Move = class {
9413
9447
  break;
9414
9448
  }
9415
9449
  }
9416
- const argConditionsAreMet = argResults.at(-1).conditionsAreMet;
9450
+ const last = argResults[argResults.length - 1];
9451
+ const argConditionsAreMet = last?.conditionsAreMet ?? false;
9417
9452
  argumentResults[argName] = {
9418
9453
  results: argResults,
9419
9454
  conditionsAreMet: argConditionsAreMet
@@ -9424,8 +9459,8 @@ var Move = class {
9424
9459
  }
9425
9460
  const moveResults = checkConditions(
9426
9461
  bgioArguments,
9427
- { conditions: this.rule.conditions },
9428
- void 0,
9462
+ this.rule.conditions,
9463
+ {},
9429
9464
  { ...context, moveArguments: payload.arguments }
9430
9465
  );
9431
9466
  return {
@@ -9440,6 +9475,7 @@ var Move = class {
9440
9475
  payload,
9441
9476
  context
9442
9477
  );
9478
+ if (conditionResults === false) return false;
9443
9479
  return conditionResults.conditionsAreMet;
9444
9480
  }
9445
9481
  doMove(bgioArguments, payload, context, { skipCheck = false } = {}) {
@@ -9450,12 +9486,10 @@ var Move = class {
9450
9486
  );
9451
9487
  const resolvedPayload = {
9452
9488
  ...payload,
9453
- arguments: Object.entries(rule.arguments ?? {}).reduce((acc, [argName, arg]) => {
9454
- return {
9455
- ...acc,
9456
- [argName]: payload?.arguments?.[argName] ?? arg
9457
- };
9458
- }, {})
9489
+ arguments: Object.entries(rule.arguments ?? {}).reduce((acc, [argName, arg]) => ({
9490
+ ...acc,
9491
+ [argName]: payload?.arguments?.[argName] ?? arg
9492
+ }), {})
9459
9493
  };
9460
9494
  if (rule.name) {
9461
9495
  bgioArguments.G._meta.previousPayloads[rule.name] = resolvedPayload;
@@ -9464,7 +9498,7 @@ var Move = class {
9464
9498
  if (!skipCheck) {
9465
9499
  conditionResults = this.checkValidity(bgioArguments, resolvedPayload, context);
9466
9500
  }
9467
- if (!skipCheck && !conditionResults.conditionsAreMet) {
9501
+ if (!skipCheck && conditionResults !== false && !conditionResults.conditionsAreMet) {
9468
9502
  return import_core.INVALID_MOVE;
9469
9503
  } else {
9470
9504
  this.do(bgioArguments, rule, resolvedPayload, context);
@@ -9474,81 +9508,100 @@ var Move = class {
9474
9508
  }
9475
9509
  return { conditionResults };
9476
9510
  }
9511
+ do(_bgioArguments, _rule, _resolvedPayload, _context) {
9512
+ throw new Error("Move#do must be implemented by subclass");
9513
+ }
9477
9514
  transformRule(rule) {
9478
9515
  const args = rule.arguments;
9479
- for (let key in args) {
9480
- const arg = args[key];
9481
- if (!arg.playerChoice) {
9482
- arg.resolveAsEntity = true;
9516
+ if (args) {
9517
+ for (const key in args) {
9518
+ const arg = args[key];
9519
+ if (arg && !arg.playerChoice) {
9520
+ arg.resolveAsEntity = true;
9521
+ }
9483
9522
  }
9484
9523
  }
9485
9524
  return rule;
9486
9525
  }
9487
9526
  };
9488
9527
 
9489
- // src/game-factory/move/move-entity.js
9528
+ // src/game-factory/move/move-entity.ts
9490
9529
  var MoveEntity = class extends Move {
9491
- do(bgioArguments, rule, { arguments: { entity, destination } }) {
9530
+ do(bgioArguments, rule, resolvedPayload) {
9531
+ const { entity, destination } = resolvedPayload.arguments;
9532
+ const g2 = bgioArguments;
9492
9533
  if (Array.isArray(entity)) {
9493
9534
  entity.forEach((e) => {
9494
- bgioArguments.G.bank.findParent(e)?.remove(e);
9535
+ g2.G.bank.findParent(e)?.remove(e);
9495
9536
  destination.placeEntity(e, rule.position);
9496
9537
  });
9497
9538
  } else {
9498
- bgioArguments.G.bank.findParent(entity)?.remove(entity);
9539
+ g2.G.bank.findParent(entity)?.remove(entity);
9499
9540
  destination.placeEntity(entity, rule.position);
9500
9541
  }
9501
9542
  }
9502
9543
  };
9503
9544
 
9504
- // src/game-factory/move/remove-entity.js
9545
+ // src/game-factory/move/remove-entity.ts
9505
9546
  var RemoveEntity = class extends Move {
9506
- do(bgioArguments, rule, { arguments: { entity } }) {
9507
- bgioArguments.G.bank.returnToBank(bgioArguments, entity);
9547
+ do(bgioArguments, _rule, resolvedPayload) {
9548
+ const { entity } = resolvedPayload.arguments;
9549
+ const bgio = bgioArguments;
9550
+ bankOf(bgio).returnToBank(bgio, entity);
9508
9551
  }
9509
9552
  };
9510
9553
 
9511
- // src/game-factory/move/place-new.js
9554
+ // src/game-factory/move/place-new.ts
9512
9555
  var PlaceNew = class extends Move {
9513
- do(bgioArguments, rule, { arguments: { destination } }, context) {
9514
- const entities = rule.matchMultiple ? bgioArguments.G.bank.getMultiple(
9515
- bgioArguments,
9556
+ do(bgioArguments, rule, resolvedPayload, context) {
9557
+ const { destination } = resolvedPayload.arguments;
9558
+ const bgio = bgioArguments;
9559
+ const r2 = rule;
9560
+ const bank = bankOf(bgio);
9561
+ const entities = r2.matchMultiple ? bank.getMultiple(
9562
+ bgio,
9516
9563
  {
9517
- ...rule.entity,
9564
+ ...r2.entity,
9518
9565
  conditions: [
9519
- ...rule.entity?.conditions || [],
9520
- ...rule.conditions || []
9566
+ ...r2.entity?.conditions || [],
9567
+ ...r2.conditions || []
9521
9568
  ]
9522
9569
  },
9523
- rule.count,
9570
+ r2.count ?? 1,
9524
9571
  context
9525
- ) : [bgioArguments.G.bank.getOne(
9526
- bgioArguments,
9572
+ ) : [bank.getOne(
9573
+ bgio,
9527
9574
  {
9528
- ...rule.entity,
9575
+ ...r2.entity,
9529
9576
  conditions: [
9530
- ...rule.entity?.conditions || [],
9531
- ...rule.conditions || []
9577
+ ...r2.entity?.conditions || [],
9578
+ ...r2.conditions || []
9532
9579
  ]
9533
9580
  },
9534
9581
  context
9535
9582
  )];
9536
9583
  entities.forEach((entity) => {
9537
- destination.placeEntity(entity, rule.position);
9584
+ destination.placeEntity(entity, r2.position);
9538
9585
  });
9539
9586
  }
9540
9587
  };
9541
9588
 
9542
- // src/game-factory/move/take-from.js
9589
+ // src/game-factory/move/take-from.ts
9543
9590
  var TakeFrom = class extends Move {
9544
- do(bgioArguments, rule, { arguments: { source, destination } }) {
9545
- destination.placeEntity(source.takeOne(rule.arguments.source.position));
9591
+ do(_bgioArguments, rule, resolvedPayload) {
9592
+ const { source, destination } = resolvedPayload.arguments;
9593
+ destination.placeEntity(
9594
+ source.takeOne(
9595
+ rule.arguments.source.position
9596
+ )
9597
+ );
9546
9598
  }
9547
9599
  };
9548
9600
 
9549
- // src/game-factory/move/set-state.js
9601
+ // src/game-factory/move/set-state.ts
9550
9602
  var SetState = class extends Move {
9551
- do(_2, __, { arguments: { entity, state } }) {
9603
+ do(_unused, _rule, resolvedPayload) {
9604
+ const { entity, state } = resolvedPayload.arguments;
9552
9605
  entity.state = {
9553
9606
  ...entity.state,
9554
9607
  [state.property]: state.value
@@ -9556,7 +9609,7 @@ var SetState = class extends Move {
9556
9609
  }
9557
9610
  };
9558
9611
 
9559
- // src/utils/do-moves.js
9612
+ // src/utils/do-moves.ts
9560
9613
  function doMoves(bgioArguments, moves = [], context) {
9561
9614
  if (!moves?.length) {
9562
9615
  return bgioArguments.G;
@@ -9571,11 +9624,12 @@ function doMoves(bgioArguments, moves = [], context) {
9571
9624
  return bgioArguments.G;
9572
9625
  }
9573
9626
 
9574
- // src/game-factory/move/set-active-players.js
9627
+ // src/game-factory/move/set-active-players.ts
9575
9628
  var SetActivePlayers = class extends Move {
9576
- do(bgioArguments, rule, _2, context) {
9577
- bgioArguments.events.setActivePlayers(rule.options);
9578
- const phaseName = bgioArguments.ctx.phase;
9629
+ do(bgioArguments, rule, _unused, context) {
9630
+ const b2 = bgioArguments;
9631
+ b2.events.setActivePlayers(rule.options);
9632
+ const phaseName = b2.ctx.phase;
9579
9633
  const stageName = rule.options.currentPlayer?.stage;
9580
9634
  const phaseOrRoot = context.game.phases?.[phaseName] ?? context.game;
9581
9635
  const stage = phaseOrRoot?.turn?.stages?.[stageName];
@@ -9590,26 +9644,28 @@ var SetActivePlayers = class extends Move {
9590
9644
  }
9591
9645
  };
9592
9646
 
9593
- // src/game-factory/move/end-turn.js
9647
+ // src/game-factory/move/end-turn.ts
9594
9648
  var EndTurn = class extends Move {
9595
9649
  do(bgioArguments) {
9596
9650
  bgioArguments.events.endTurn();
9597
9651
  }
9598
9652
  };
9599
9653
 
9600
- // src/game-factory/move/pass-turn.js
9654
+ // src/game-factory/move/pass-turn.ts
9601
9655
  var PassTurn = class extends Move {
9602
9656
  do(bgioArguments) {
9603
- if (bgioArguments.G._meta.passedPlayers.length < bgioArguments.ctx.numPlayers) {
9604
- bgioArguments.G._meta.passedPlayers.push(bgioArguments.ctx.currentPlayer);
9605
- bgioArguments.events.pass();
9657
+ const a2 = bgioArguments;
9658
+ if (a2.G._meta.passedPlayers.length < a2.ctx.numPlayers) {
9659
+ a2.G._meta.passedPlayers.push(a2.ctx.currentPlayer);
9660
+ a2.events.pass();
9606
9661
  }
9607
9662
  }
9608
9663
  };
9609
9664
 
9610
- // src/game-factory/move/for-each.js
9665
+ // src/game-factory/move/for-each.ts
9611
9666
  var ForEach = class extends Move {
9612
- do(bgioArguments, rule, { arguments: { targets } }, context) {
9667
+ do(bgioArguments, rule, resolvedPayload, context) {
9668
+ const { targets } = resolvedPayload.arguments;
9613
9669
  targets.forEach((target) => {
9614
9670
  const loopContext = {
9615
9671
  ...context,
@@ -9624,23 +9680,28 @@ var ForEach = class extends Move {
9624
9680
  }
9625
9681
  };
9626
9682
 
9627
- // src/game-factory/move/pass.js
9683
+ // src/game-factory/move/pass.ts
9628
9684
  var Pass = class extends Move {
9629
9685
  do(bgioArguments) {
9630
9686
  bgioArguments.events.endTurn();
9631
9687
  }
9632
9688
  };
9633
9689
 
9634
- // src/game-factory/move/shuffle.js
9690
+ // src/game-factory/move/shuffle.ts
9635
9691
  var Shuffle = class extends Move {
9636
- do(bgioArguments, _2, { arguments: { target } }) {
9637
- target.entities = bgioArguments.random.Shuffle(target.entities);
9692
+ do(bgioArguments, _rule, resolvedPayload) {
9693
+ const { target } = resolvedPayload.arguments;
9694
+ const b2 = bgioArguments;
9695
+ target.entities = b2.random.Shuffle(target.entities);
9638
9696
  }
9639
9697
  };
9640
9698
 
9641
- // src/game-factory/move/move-factory.js
9699
+ // src/game-factory/move/move-factory.ts
9642
9700
  function moveFactory(moveRule, game) {
9643
9701
  const moveInstance = getMoveInstance(moveRule);
9702
+ if (!moveInstance) {
9703
+ throw new Error("moveFactory: unknown moveType");
9704
+ }
9644
9705
  const compatibleMove = function(bgioArguments, serializablePayload) {
9645
9706
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
9646
9707
  const { G: G2 } = newBgioArguments;
@@ -9649,8 +9710,10 @@ function moveFactory(moveRule, game) {
9649
9710
  const moveConditionResults = moveInstance.doMove(newBgioArguments, payload, context);
9650
9711
  context.moveConditionResults = [moveConditionResults];
9651
9712
  if (moveConditionResults !== import_core2.INVALID_MOVE && moveRule.then) {
9652
- for (let automaticMoveRule of moveRule.then) {
9653
- const result = getMoveInstance(automaticMoveRule).doMove(
9713
+ for (const automaticMoveRule of moveRule.then) {
9714
+ const auto = getMoveInstance(automaticMoveRule);
9715
+ if (!auto) continue;
9716
+ const result = auto.doMove(
9654
9717
  newBgioArguments,
9655
9718
  {},
9656
9719
  { ...context }
@@ -9665,16 +9728,15 @@ function moveFactory(moveRule, game) {
9665
9728
  return compatibleMove;
9666
9729
  }
9667
9730
  function revivePayload(serializablePayload, G2) {
9668
- if (serializablePayload) {
9669
- const payload = deserialize(JSON.stringify(serializablePayload), registry);
9670
- payload.arguments = Object.entries(payload.arguments).reduce((acc, [key, argOrEntityId]) => ({
9671
- ...acc,
9672
- [key]: typeof argOrEntityId === "number" ? G2.bank.locate(argOrEntityId) : argOrEntityId
9673
- }), {});
9674
- return payload;
9675
- } else {
9676
- return serializablePayload;
9731
+ if (!serializablePayload) {
9732
+ return void 0;
9677
9733
  }
9734
+ const payload = deserialize(JSON.stringify(serializablePayload), registry);
9735
+ payload.arguments = Object.entries(payload.arguments).reduce((acc, [key, argOrEntityId]) => ({
9736
+ ...acc,
9737
+ [key]: typeof argOrEntityId === "number" ? G2.bank.locate(argOrEntityId) : argOrEntityId
9738
+ }), {});
9739
+ return payload;
9678
9740
  }
9679
9741
  function getMoveInstance(moveRule) {
9680
9742
  switch (moveRule.moveType) {
@@ -9703,13 +9765,12 @@ function getMoveInstance(moveRule) {
9703
9765
  }
9704
9766
  }
9705
9767
 
9706
- // src/game-factory/expand-game-rules.js
9707
- var import_cloneDeep = __toESM(require_cloneDeep());
9768
+ // src/game-factory/expand-game-rules.ts
9708
9769
  var import_find2 = __toESM(require_find());
9709
9770
 
9710
- // src/utils/json-transformer.js
9771
+ // src/utils/json-transformer.ts
9711
9772
  function transformJSON(data, rules) {
9712
- return JSON.parse(JSON.stringify(data), (key, value2) => {
9773
+ return JSON.parse(JSON.stringify(data), (_key, value2) => {
9713
9774
  let result = value2;
9714
9775
  for (const rule of rules) {
9715
9776
  if (rule.test(result)) {
@@ -9720,7 +9781,7 @@ function transformJSON(data, rules) {
9720
9781
  });
9721
9782
  }
9722
9783
 
9723
- // src/game-factory/expand-game-rules.js
9784
+ // src/game-factory/expand-game-rules.ts
9724
9785
  var invariantEntities = [
9725
9786
  {
9726
9787
  entityType: "Space",
@@ -9744,7 +9805,8 @@ function expandEntities(rules) {
9744
9805
  }
9745
9806
  function expandInitialPlacements(rules, entities) {
9746
9807
  if (rules.sharedBoard) {
9747
- const sharedBoardPlacements = rules.sharedBoard.map((matcher) => ({ entity: matcher, destination: { name: "sharedBoard" } }));
9808
+ const sharedBoard = rules.sharedBoard;
9809
+ const sharedBoardPlacements = sharedBoard.map((matcher) => ({ entity: matcher, destination: { name: "sharedBoard" } }));
9748
9810
  if (!rules.initialPlacements) rules.initialPlacements = [];
9749
9811
  rules.initialPlacements.unshift(...sharedBoardPlacements);
9750
9812
  }
@@ -9754,7 +9816,8 @@ function expandInitialPlacements(rules, entities) {
9754
9816
  name: "personalBoard",
9755
9817
  perPlayer: true
9756
9818
  });
9757
- const personalBoardPlacements = rules.personalBoard.map((matcher) => ({
9819
+ const personalBoard = rules.personalBoard;
9820
+ const personalBoardPlacements = personalBoard.map((matcher) => ({
9758
9821
  entity: matcher,
9759
9822
  destination: {
9760
9823
  name: "personalBoard"
@@ -9784,7 +9847,7 @@ function expandInitialPlacements(rules, entities) {
9784
9847
  conditionType: "Is",
9785
9848
  matcher: {
9786
9849
  ...matcher,
9787
- ...entityDefinition.perPlayer ? {
9850
+ ...entityDefinition?.perPlayer ? {
9788
9851
  player: {
9789
9852
  type: "contextPath",
9790
9853
  path: ["loopTarget"]
@@ -9858,21 +9921,21 @@ var simpleReplacements = [
9858
9921
  ],
9859
9922
  [
9860
9923
  "ownerOfFirstResultEntity",
9861
- // might have to more tightly couple this to HasLine condition
9862
9924
  {
9863
- "type": "contextPath",
9864
- "path": ["results", 0, "matches", 0, 0, "entities", 0, "attributes", "player"]
9925
+ type: "contextPath",
9926
+ path: ["results", 0, "matches", 0, 0, "entities", 0, "attributes", "player"]
9865
9927
  }
9866
9928
  ]
9867
9929
  ];
9868
9930
  var transformationRules = [
9869
9931
  {
9870
- test: (val) => val && typeof val === "object",
9932
+ test: (val) => Boolean(val && typeof val === "object"),
9871
9933
  replace: (val) => {
9934
+ const obj = val;
9872
9935
  keyMappings.forEach(([oldKey, newKey]) => {
9873
- if (val.hasOwnProperty(oldKey)) {
9874
- val[newKey] = val[oldKey];
9875
- delete val[oldKey];
9936
+ if (Object.prototype.hasOwnProperty.call(obj, oldKey)) {
9937
+ obj[newKey] = obj[oldKey];
9938
+ delete obj[oldKey];
9876
9939
  }
9877
9940
  });
9878
9941
  return val;
@@ -9890,22 +9953,24 @@ var transformationRules = [
9890
9953
  }
9891
9954
  },
9892
9955
  {
9893
- test: (val) => val?.conditions,
9956
+ test: (val) => Boolean(val && typeof val === "object" && val.conditions),
9894
9957
  replace: (val) => {
9895
- if (!Array.isArray(val.conditions)) {
9896
- val.conditions = [val.conditions];
9958
+ const v2 = val;
9959
+ if (!Array.isArray(v2.conditions)) {
9960
+ v2.conditions = [v2.conditions];
9897
9961
  }
9898
9962
  return val;
9899
9963
  }
9900
9964
  },
9901
9965
  {
9902
- test: (val) => val?.conditions,
9966
+ test: (val) => Boolean(val && typeof val === "object" && val.conditions),
9903
9967
  replace: (val) => {
9904
- for (let i2 = 0, len = val.conditions.length; i2 < len; i2++) {
9905
- if (!val.conditions[i2].conditionType) {
9906
- val.conditions[i2] = {
9968
+ const v2 = val;
9969
+ for (let i2 = 0, len = v2.conditions.length; i2 < len; i2++) {
9970
+ if (!v2.conditions[i2].conditionType) {
9971
+ v2.conditions[i2] = {
9907
9972
  conditionType: "Is",
9908
- matcher: val.conditions[i2]
9973
+ matcher: v2.conditions[i2]
9909
9974
  };
9910
9975
  }
9911
9976
  }
@@ -9913,18 +9978,21 @@ var transformationRules = [
9913
9978
  }
9914
9979
  },
9915
9980
  {
9916
- test: (val) => typeof val?.target === "string",
9917
- replace: (val) => ({
9918
- ...val,
9919
- target: {
9920
- conditions: [{
9921
- conditionType: "Is",
9922
- matcher: {
9923
- name: val.target
9924
- }
9925
- }]
9926
- }
9927
- })
9981
+ test: (val) => Boolean(val && typeof val === "object" && typeof val.target === "string"),
9982
+ replace: (val) => {
9983
+ const v2 = val;
9984
+ return {
9985
+ ...v2,
9986
+ target: {
9987
+ conditions: [{
9988
+ conditionType: "Is",
9989
+ matcher: {
9990
+ name: v2.target
9991
+ }
9992
+ }]
9993
+ }
9994
+ };
9995
+ }
9928
9996
  }
9929
9997
  ];
9930
9998
  function expandGameRules(gameRules) {
@@ -9951,11 +10019,14 @@ function expandGameRules(gameRules) {
9951
10019
  return rules;
9952
10020
  }
9953
10021
 
9954
- // src/utils/get-scenario-results.js
9955
- function getScenarioResults(bgioArguments, scenarios, context) {
10022
+ // src/utils/get-scenario-results.ts
10023
+ function getScenarioResults(bgioArguments, scenarios) {
9956
10024
  let match;
9957
10025
  for (const scenario of scenarios) {
9958
- const conditionResults = checkConditions(bgioArguments, scenario);
10026
+ const conditionResults = checkConditions(
10027
+ bgioArguments,
10028
+ scenario.conditions
10029
+ );
9959
10030
  if (conditionResults.conditionsAreMet) {
9960
10031
  match = { scenario, conditionResults };
9961
10032
  break;
@@ -9972,7 +10043,7 @@ function getScenarioResults(bgioArguments, scenarios, context) {
9972
10043
  }
9973
10044
  }
9974
10045
 
9975
- // src/game-factory/game-factory.js
10046
+ // src/game-factory/game-factory.ts
9976
10047
  function gameFactory(gameRules, gameName) {
9977
10048
  const game = { name: gameName };
9978
10049
  const rules = expandGameRules(gameRules);
@@ -9985,19 +10056,21 @@ function gameFactory(gameRules, gameName) {
9985
10056
  }
9986
10057
  };
9987
10058
  const entityDefinitions = expandEntityDefinitions(rules.entities, ctx);
9988
- initialState.bank = new bank_default(entityDefinitions);
9989
- initialState.sharedBoard = initialState.bank.getOne(
10059
+ const bank = new bank_default(entityDefinitions);
10060
+ initialState.bank = bank;
10061
+ initialState.sharedBoard = bank.getOne(
9990
10062
  bgioArguments,
9991
10063
  {
9992
10064
  conditions: [{
9993
10065
  conditionType: "Is",
9994
10066
  matcher: { name: "sharedBoard" }
9995
10067
  }]
9996
- }
10068
+ },
10069
+ {}
9997
10070
  );
9998
10071
  if (rules.personalBoard) {
9999
10072
  initialState.personalBoards = bgioArguments.ctx.playOrder.map(
10000
- (playerID) => initialState.bank.getOne(
10073
+ (playerID) => bank.getOne(
10001
10074
  bgioArguments,
10002
10075
  {
10003
10076
  conditions: [{
@@ -10007,13 +10080,16 @@ function gameFactory(gameRules, gameName) {
10007
10080
  player: playerID
10008
10081
  }
10009
10082
  }]
10010
- }
10083
+ },
10084
+ {}
10011
10085
  )
10012
10086
  );
10013
10087
  }
10014
10088
  rules.initialMoves?.forEach((moveRule) => {
10015
10089
  moveFactory(moveRule, game).moveInstance.doMove(
10016
- { ...bgioArguments, G: initialState }
10090
+ { ...bgioArguments, G: initialState },
10091
+ void 0,
10092
+ {}
10017
10093
  );
10018
10094
  });
10019
10095
  return JSON.parse(serialize(initialState));
@@ -10031,16 +10107,18 @@ function gameFactory(gameRules, gameName) {
10031
10107
  }), {});
10032
10108
  }
10033
10109
  if (rules.endIf) {
10110
+ const endIfRules = rules.endIf;
10034
10111
  game.endIf = (bgioArguments) => {
10035
10112
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
10036
- return getScenarioResults(newBgioArguments, rules.endIf);
10113
+ return getScenarioResults(newBgioArguments, endIfRules);
10037
10114
  };
10038
10115
  }
10039
10116
  if (!gameRules.DEBUG_DISABLE_SECRET_STATE) {
10040
10117
  game.playerView = (bgioArguments) => {
10041
10118
  const { G: G2, playerID } = deserializeBgioArguments(bgioArguments);
10042
- Object.values(G2.bank.tracker).forEach((entity) => {
10043
- if (entity.rule.contentsHiddenFrom === "All" || entity.rule.contentsHiddenFrom === "Others" && (playerID !== entity.rule.player || playerID == void 0)) {
10119
+ const tracker = G2.bank.tracker;
10120
+ Object.values(tracker).forEach((entity) => {
10121
+ if (entity.rule.contentsHiddenFrom === "All" || entity.rule.contentsHiddenFrom === "Others" && (playerID !== entity.rule.player || playerID === void 0)) {
10044
10122
  if (entity.spaces) {
10045
10123
  entity.spaces = entity.rule.hideLength ? [] : entity.spaces.map(() => G2.bank.createEntity());
10046
10124
  }
@@ -10060,12 +10138,12 @@ function expandEntityDefinitions(entities, ctx) {
10060
10138
  if (entityCopy.perPlayer) {
10061
10139
  delete entityCopy.perPlayer;
10062
10140
  if (entityCopy.variants) {
10063
- entityCopy.variants = new Array(ctx.numPlayers).fill().reduce((accu, _2, i2) => [
10141
+ entityCopy.variants = new Array(ctx.numPlayers).fill(void 0).reduce((accu, _2, i2) => [
10064
10142
  ...accu,
10065
10143
  ...entityCopy.variants.map((variant) => ({ ...variant, player: `${i2}` }))
10066
10144
  ], []);
10067
10145
  } else {
10068
- entityCopy.variants = new Array(ctx.numPlayers).fill().map((_2, i2) => ({ player: `${i2}` }));
10146
+ entityCopy.variants = new Array(ctx.numPlayers).fill(void 0).map((_2, i2) => ({ player: `${i2}` }));
10069
10147
  }
10070
10148
  }
10071
10149
  if (entityCopy.variants) {
@@ -10103,9 +10181,10 @@ function createTurn(turnRule, game) {
10103
10181
  }
10104
10182
  });
10105
10183
  }
10106
- if (turnRule.order?.playOrder === "RotateFirst") {
10107
- turnRule.order.first = () => 0;
10108
- turnRule.order.next = ({ ctx }) => (ctx.playOrderPos + 1) % ctx.numPlayers;
10184
+ const order = turnRule.order;
10185
+ if (order?.playOrder === "RotateFirst") {
10186
+ order.first = () => 0;
10187
+ order.next = ({ ctx }) => (ctx.playOrderPos + 1) % ctx.numPlayers;
10109
10188
  turn.order.playOrder = ({ ctx, G: G2 }) => {
10110
10189
  return G2._meta.isAfterFirstPhase ? [...ctx.playOrder.slice(1), ctx.playOrder[0]] : ctx.playOrder;
10111
10190
  };
@@ -10128,10 +10207,11 @@ function createPhase(phaseRule, game) {
10128
10207
  return JSON.parse(serialize(newBgioArguments.G));
10129
10208
  };
10130
10209
  if (phaseRule.endIf) {
10210
+ const phaseEndIf = phaseRule.endIf;
10131
10211
  phase.endIf = (bgioArguments) => {
10132
10212
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
10133
10213
  if (newBgioArguments.G._meta.currentPhaseHasBeenSetUp) {
10134
- const result = getScenarioResults(newBgioArguments, phaseRule.endIf);
10214
+ const result = getScenarioResults(newBgioArguments, phaseEndIf);
10135
10215
  if (result) {
10136
10216
  return result;
10137
10217
  }
@@ -27015,21 +27095,24 @@ function SocketIO({ server, socketOpts } = {}) {
27015
27095
  var import_lodash4 = __toESM(require_lodash());
27016
27096
  var import_rfc69024 = __toESM(require_rfc6902());
27017
27097
 
27018
- // src/utils/prepare-payload.js
27098
+ // src/utils/prepare-payload.ts
27019
27099
  function preparePayload(payload) {
27020
- if (payload?.arguments) {
27021
- const payloadCopy = { ...payload };
27022
- payloadCopy.arguments = Object.entries(payloadCopy.arguments).reduce((acc, [key, argument]) => ({
27023
- ...acc,
27024
- [key]: argument.abstract ? argument : argument.entityId
27025
- }), {});
27100
+ const p2 = payload;
27101
+ if (p2?.arguments) {
27102
+ const payloadCopy = {
27103
+ ...p2,
27104
+ arguments: Object.entries(p2.arguments).reduce((acc, [key, argument]) => ({
27105
+ ...acc,
27106
+ [key]: argument.abstract ? argument : argument.entityId
27107
+ }), {})
27108
+ };
27026
27109
  return JSON.parse(serialize(payloadCopy, { deduplicateInstances: false }));
27027
27110
  } else {
27028
27111
  return payload;
27029
27112
  }
27030
27113
  }
27031
27114
 
27032
- // src/utils/get-steps.js
27115
+ // src/utils/get-steps.ts
27033
27116
  var argNamesMap = {
27034
27117
  PlaceNew: ["destination"],
27035
27118
  RemoveEntity: ["entity"],
@@ -27038,13 +27121,15 @@ var argNamesMap = {
27038
27121
  SetState: ["entity", "state"]
27039
27122
  };
27040
27123
  function getSteps(bgioState, moveRule) {
27041
- return argNamesMap[moveRule.moveType].filter((argName) => moveRule.arguments[argName].playerChoice).map((argName) => ({
27124
+ const names = argNamesMap[moveRule.moveType];
27125
+ if (!names) return [];
27126
+ return names.filter((argName) => moveRule.arguments[argName]?.playerChoice).map((argName) => ({
27042
27127
  argName,
27043
27128
  getClickable: argName === "state" ? () => moveRule.arguments[argName].possibleValues.map((value2) => ({
27044
27129
  abstract: true,
27045
27130
  ...moveRule.arguments[argName],
27046
27131
  value: value2
27047
- })) : (context) => bgioState.G.bank.findAll(
27132
+ })) : (context) => bankOf(bgioState).findAll(
27048
27133
  bgioState,
27049
27134
  moveRule.arguments[argName],
27050
27135
  context
@@ -27052,12 +27137,11 @@ function getSteps(bgioState, moveRule) {
27052
27137
  }));
27053
27138
  }
27054
27139
 
27055
- // src/utils/create-payload.js
27056
- function createPayload(bgioState, moveRule, targets, context) {
27140
+ // src/utils/create-payload.ts
27141
+ function createPayload(bgioState, moveRule, targets, _context) {
27057
27142
  const argNames = getSteps(
27058
27143
  bgioState,
27059
- moveRule,
27060
- context
27144
+ moveRule
27061
27145
  ).map((s2) => s2.argName);
27062
27146
  return {
27063
27147
  arguments: targets.reduce((acc, target, i2) => ({
@@ -27067,11 +27151,11 @@ function createPayload(bgioState, moveRule, targets, context) {
27067
27151
  };
27068
27152
  }
27069
27153
 
27070
- // src/client/client.js
27154
+ // src/client/client.ts
27071
27155
  var Client2 = class {
27072
27156
  constructor(options) {
27073
27157
  this.options = options;
27074
- this.game = options.boardgameIOGame || gameFactory(JSON.parse(options.gameRules), options.gameName);
27158
+ this.game = options.boardgameIOGame || gameFactory(JSON.parse(options.gameRules), options.gameName ?? "");
27075
27159
  if (!options.boardgameIOGame) {
27076
27160
  this.moveBuilder = { targets: [], stepIndex: 0, eliminatedMoves: [] };
27077
27161
  this.optimisticWinner = null;
@@ -27095,7 +27179,7 @@ var Client2 = class {
27095
27179
  game: this.game,
27096
27180
  multiplayer,
27097
27181
  matchID,
27098
- playerID,
27182
+ playerID: playerID ?? void 0,
27099
27183
  credentials,
27100
27184
  numPlayers,
27101
27185
  debug
@@ -27105,8 +27189,9 @@ var Client2 = class {
27105
27189
  this.client.start();
27106
27190
  return this;
27107
27191
  } catch (error2) {
27108
- console.error("Failed to join game:", error2?.message ?? error2);
27109
- if (error2?.stack) console.error(error2.stack);
27192
+ const err = error2;
27193
+ console.error("Failed to join game:", err?.message ?? error2);
27194
+ if (err?.stack) console.error(err.stack);
27110
27195
  }
27111
27196
  }
27112
27197
  update() {
@@ -27149,7 +27234,12 @@ var Client2 = class {
27149
27234
  return;
27150
27235
  }
27151
27236
  const remainingMoveEntries = Object.entries(_possibleMoveMeta).filter(([name]) => !newEliminated.includes(name));
27152
- if (isMoveCompleted(state, _wrappedMoves, remainingMoveEntries, this.moveBuilder.stepIndex)) {
27237
+ if (isMoveCompleted(
27238
+ state,
27239
+ _wrappedMoves,
27240
+ remainingMoveEntries,
27241
+ this.moveBuilder.stepIndex
27242
+ )) {
27153
27243
  const [moveName] = remainingMoveEntries[0];
27154
27244
  const move = _wrappedMoves[moveName];
27155
27245
  const payload = createPayload(
@@ -27197,7 +27287,10 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27197
27287
  const _possibleMoveMeta = {};
27198
27288
  const allClickable = /* @__PURE__ */ new Set();
27199
27289
  Object.entries(moves).filter(([moveName]) => !eliminatedMoves.includes(moveName)).forEach(([moveName, move]) => {
27200
- const moveRule = resolveProperties(bgioState, { ...move.moveInstance.rule, moveName });
27290
+ const moveRule = resolveProperties(bgioState, {
27291
+ ...move.moveInstance.rule,
27292
+ moveName
27293
+ });
27201
27294
  const context = {
27202
27295
  moveInstance: move.moveInstance,
27203
27296
  moveArguments: moveRule.arguments
@@ -27205,10 +27298,23 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27205
27298
  const targets = moveBuilder.targets.map(
27206
27299
  (t2) => t2.abstract ? t2 : bgioState.G.bank.locate(t2.entityId)
27207
27300
  );
27208
- const payload = createPayload(bgioState, moveRule, targets, context);
27301
+ const payload = createPayload(
27302
+ bgioState,
27303
+ moveRule,
27304
+ targets,
27305
+ context
27306
+ );
27209
27307
  context.moveArguments = { ...context.moveArguments, ...payload.arguments };
27210
- const moveIsAllowed = checkConditions(bgioState, moveRule, {}, context).conditionsAreMet;
27211
- const moveSteps = getSteps(bgioState, moveRule);
27308
+ const moveIsAllowed = checkConditions(
27309
+ bgioState,
27310
+ moveRule.conditions,
27311
+ {},
27312
+ context
27313
+ ).conditionsAreMet;
27314
+ const moveSteps = getSteps(
27315
+ bgioState,
27316
+ moveRule
27317
+ );
27212
27318
  const clickableForMove = new Set(
27213
27319
  moveIsAllowed && moveSteps?.[stepIndex]?.getClickable(context) || []
27214
27320
  );
@@ -27218,11 +27324,19 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27218
27324
  return { _possibleMoveMeta, allClickable };
27219
27325
  }
27220
27326
  function isMoveCompleted(state, moves, remainingMoveEntries, stepIndex) {
27221
- return remainingMoveEntries.length === 1 && getSteps(state, moves[remainingMoveEntries[0][0]].moveInstance.rule).length === stepIndex + 1;
27327
+ return remainingMoveEntries.length === 1 && getSteps(
27328
+ state,
27329
+ moves[remainingMoveEntries[0][0]].moveInstance.rule
27330
+ ).length === stepIndex + 1;
27222
27331
  }
27223
27332
  function getWinnerAfterMove(state, game, moveInstance, movePayload) {
27224
- const simulatedG = simulateMove(state, preparePayload(movePayload), { moveInstance });
27225
- return game.endIf?.({ ...state, G: JSON.parse(serialize(simulatedG)) });
27333
+ const simulatedG = simulateMove(
27334
+ state,
27335
+ preparePayload(movePayload),
27336
+ { moveInstance }
27337
+ );
27338
+ const endIf = game.endIf;
27339
+ return endIf?.({ ...state, G: JSON.parse(serialize(simulatedG)) });
27226
27340
  }
27227
27341
  /*! Bundled license information:
27228
27342