board-game-engine 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.github/workflows/ci.yml +33 -0
  2. package/README.md +2 -2
  3. package/dist/board-game-engine.cjs +463 -349
  4. package/dist/board-game-engine.js +463 -349
  5. package/dist/board-game-engine.min.js +22 -22
  6. package/dist/board-game-engine.mjs +461 -348
  7. package/dist/client/client.d.ts +76 -0
  8. package/dist/client/client.d.ts.map +1 -0
  9. package/dist/game-factory/bank/bank-slot.d.ts +30 -0
  10. package/dist/game-factory/bank/bank-slot.d.ts.map +1 -0
  11. package/dist/game-factory/bank/bank.d.ts +34 -0
  12. package/dist/game-factory/bank/bank.d.ts.map +1 -0
  13. package/dist/game-factory/board.d.ts +4 -0
  14. package/dist/game-factory/board.d.ts.map +1 -0
  15. package/dist/game-factory/condition/condition-factory.d.ts +4 -0
  16. package/dist/game-factory/condition/condition-factory.d.ts.map +1 -0
  17. package/dist/game-factory/condition/condition.d.ts +13 -0
  18. package/dist/game-factory/condition/condition.d.ts.map +1 -0
  19. package/dist/game-factory/condition/contains-condition.d.ts +8 -0
  20. package/dist/game-factory/condition/contains-condition.d.ts.map +1 -0
  21. package/dist/game-factory/condition/contains-same-condition.d.ts +7 -0
  22. package/dist/game-factory/condition/contains-same-condition.d.ts.map +1 -0
  23. package/dist/game-factory/condition/evaluate-condition.d.ts +8 -0
  24. package/dist/game-factory/condition/evaluate-condition.d.ts.map +1 -0
  25. package/dist/game-factory/condition/every-condition.d.ts +12 -0
  26. package/dist/game-factory/condition/every-condition.d.ts.map +1 -0
  27. package/dist/game-factory/condition/has-line-condition.d.ts +8 -0
  28. package/dist/game-factory/condition/has-line-condition.d.ts.map +1 -0
  29. package/dist/game-factory/condition/in-line-condition.d.ts +8 -0
  30. package/dist/game-factory/condition/in-line-condition.d.ts.map +1 -0
  31. package/dist/game-factory/condition/is-condition.d.ts +8 -0
  32. package/dist/game-factory/condition/is-condition.d.ts.map +1 -0
  33. package/dist/game-factory/condition/is-full-condition.d.ts +7 -0
  34. package/dist/game-factory/condition/is-full-condition.d.ts.map +1 -0
  35. package/dist/game-factory/condition/no-possible-moves-condition.d.ts +7 -0
  36. package/dist/game-factory/condition/no-possible-moves-condition.d.ts.map +1 -0
  37. package/dist/game-factory/condition/not-condition.d.ts +7 -0
  38. package/dist/game-factory/condition/not-condition.d.ts.map +1 -0
  39. package/dist/game-factory/condition/or-condition.d.ts +7 -0
  40. package/dist/game-factory/condition/or-condition.d.ts.map +1 -0
  41. package/dist/game-factory/condition/position-condition.d.ts +7 -0
  42. package/dist/game-factory/condition/position-condition.d.ts.map +1 -0
  43. package/dist/game-factory/condition/some-condition.d.ts +8 -0
  44. package/dist/game-factory/condition/some-condition.d.ts.map +1 -0
  45. package/dist/game-factory/condition/would-condition.d.ts +8 -0
  46. package/dist/game-factory/condition/would-condition.d.ts.map +1 -0
  47. package/dist/game-factory/entity.d.ts +13 -0
  48. package/dist/game-factory/entity.d.ts.map +1 -0
  49. package/dist/game-factory/expand-game-rules.d.ts +3 -0
  50. package/dist/game-factory/expand-game-rules.d.ts.map +1 -0
  51. package/dist/game-factory/game-factory.d.ts +10 -0
  52. package/dist/game-factory/game-factory.d.ts.map +1 -0
  53. package/{src/game-factory/move/end-turn.js → dist/game-factory/move/end-turn.d.ts} +2 -4
  54. package/dist/game-factory/move/end-turn.d.ts.map +1 -0
  55. package/dist/game-factory/move/for-each.d.ts +5 -0
  56. package/dist/game-factory/move/for-each.d.ts.map +1 -0
  57. package/dist/game-factory/move/index.d.ts +6 -0
  58. package/dist/game-factory/move/index.d.ts.map +1 -0
  59. package/dist/game-factory/move/move-entity.d.ts +7 -0
  60. package/dist/game-factory/move/move-entity.d.ts.map +1 -0
  61. package/dist/game-factory/move/move-factory.d.ts +18 -0
  62. package/dist/game-factory/move/move-factory.d.ts.map +1 -0
  63. package/dist/game-factory/move/move.d.ts +54 -0
  64. package/dist/game-factory/move/move.d.ts.map +1 -0
  65. package/dist/game-factory/move/pass-turn.d.ts +5 -0
  66. package/dist/game-factory/move/pass-turn.d.ts.map +1 -0
  67. package/{src/game-factory/move/pass.js → dist/game-factory/move/pass.d.ts} +2 -4
  68. package/dist/game-factory/move/pass.d.ts.map +1 -0
  69. package/dist/game-factory/move/place-new.d.ts +5 -0
  70. package/dist/game-factory/move/place-new.d.ts.map +1 -0
  71. package/dist/game-factory/move/remove-entity.d.ts +5 -0
  72. package/dist/game-factory/move/remove-entity.d.ts.map +1 -0
  73. package/dist/game-factory/move/set-active-players.d.ts +5 -0
  74. package/dist/game-factory/move/set-active-players.d.ts.map +1 -0
  75. package/dist/game-factory/move/set-state.d.ts +5 -0
  76. package/dist/game-factory/move/set-state.d.ts.map +1 -0
  77. package/dist/game-factory/move/shuffle.d.ts +5 -0
  78. package/dist/game-factory/move/shuffle.d.ts.map +1 -0
  79. package/dist/game-factory/move/take-from.d.ts +11 -0
  80. package/dist/game-factory/move/take-from.d.ts.map +1 -0
  81. package/dist/game-factory/space/space.d.ts +10 -0
  82. package/dist/game-factory/space/space.d.ts.map +1 -0
  83. package/dist/game-factory/space-group/grid.d.ts +15 -0
  84. package/dist/game-factory/space-group/grid.d.ts.map +1 -0
  85. package/dist/game-factory/space-group/space-group.d.ts +20 -0
  86. package/dist/game-factory/space-group/space-group.d.ts.map +1 -0
  87. package/dist/index.d.ts +6 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/registry.d.ts +17 -0
  90. package/dist/registry.d.ts.map +1 -0
  91. package/dist/types/bagel-types.d.ts +339 -0
  92. package/dist/types/bagel-types.d.ts.map +1 -0
  93. package/dist/types/index.d.ts +3 -0
  94. package/dist/types/index.d.ts.map +1 -0
  95. package/dist/types/rule-with-conditions.d.ts +9 -0
  96. package/dist/types/rule-with-conditions.d.ts.map +1 -0
  97. package/dist/utils/any-valid-moves.d.ts +2 -0
  98. package/dist/utils/any-valid-moves.d.ts.map +1 -0
  99. package/dist/utils/bgio-resolve-types.d.ts +25 -0
  100. package/dist/utils/bgio-resolve-types.d.ts.map +1 -0
  101. package/dist/utils/check-conditions.d.ts +7 -0
  102. package/dist/utils/check-conditions.d.ts.map +1 -0
  103. package/dist/utils/create-payload.d.ts +5 -0
  104. package/dist/utils/create-payload.d.ts.map +1 -0
  105. package/dist/utils/deserialize-bgio-arguments.d.ts +3 -0
  106. package/dist/utils/deserialize-bgio-arguments.d.ts.map +1 -0
  107. package/dist/utils/do-moves.d.ts +8 -0
  108. package/dist/utils/do-moves.d.ts.map +1 -0
  109. package/dist/utils/entity-matches.d.ts +6 -0
  110. package/dist/utils/entity-matches.d.ts.map +1 -0
  111. package/dist/utils/find-met-condition.d.ts +6 -0
  112. package/dist/utils/find-met-condition.d.ts.map +1 -0
  113. package/dist/utils/get-current-moves.d.ts +24 -0
  114. package/dist/utils/get-current-moves.d.ts.map +1 -0
  115. package/dist/utils/get-scenario-results.d.ts +3 -0
  116. package/dist/utils/get-scenario-results.d.ts.map +1 -0
  117. package/dist/utils/get-steps.d.ts +13 -0
  118. package/dist/utils/get-steps.d.ts.map +1 -0
  119. package/dist/utils/get.d.ts +7 -0
  120. package/dist/utils/get.d.ts.map +1 -0
  121. package/dist/utils/grid-contains-sequence.d.ts +27 -0
  122. package/dist/utils/grid-contains-sequence.d.ts.map +1 -0
  123. package/dist/utils/json-transformer.d.ts +8 -0
  124. package/dist/utils/json-transformer.d.ts.map +1 -0
  125. package/dist/utils/prepare-payload.d.ts +2 -0
  126. package/dist/utils/prepare-payload.d.ts.map +1 -0
  127. package/dist/utils/resolve-entity.d.ts +3 -0
  128. package/dist/utils/resolve-entity.d.ts.map +1 -0
  129. package/dist/utils/resolve-expression.d.ts +6 -0
  130. package/dist/utils/resolve-expression.d.ts.map +1 -0
  131. package/dist/utils/resolve-properties.d.ts +4 -0
  132. package/dist/utils/resolve-properties.d.ts.map +1 -0
  133. package/dist/utils/simulate-move.d.ts +16 -0
  134. package/dist/utils/simulate-move.d.ts.map +1 -0
  135. package/e2e/fixtures/bge-checkers.html +1 -2
  136. package/e2e/fixtures/bge-minimal.html +1 -2
  137. package/e2e/fixtures/bge-ttt.html +1 -2
  138. package/examples/index.html +1 -1
  139. package/package.json +9 -3
  140. package/playwright-report/index.html +1 -1
  141. package/scripts/build.mjs +2 -2
  142. package/src/client/client.ts +305 -0
  143. package/src/game-factory/bank/bank-slot.ts +81 -0
  144. package/src/game-factory/bank/bank.ts +125 -0
  145. package/src/game-factory/{board.js → board.ts} +1 -1
  146. package/src/game-factory/condition/condition-factory.ts +59 -0
  147. package/src/game-factory/condition/condition.ts +50 -0
  148. package/src/game-factory/condition/{contains-condition.js → contains-condition.ts} +5 -4
  149. package/src/game-factory/condition/{contains-same-condition.js → contains-same-condition.ts} +8 -5
  150. package/src/game-factory/condition/{evaluate-condition.js → evaluate-condition.ts} +4 -3
  151. package/src/game-factory/condition/every-condition.ts +27 -0
  152. package/src/game-factory/condition/has-line-condition.ts +15 -0
  153. package/src/game-factory/condition/in-line-condition.ts +25 -0
  154. package/src/game-factory/condition/is-condition.ts +24 -0
  155. package/src/game-factory/condition/is-full-condition.ts +10 -0
  156. package/src/game-factory/condition/{no-possible-moves-condition.js → no-possible-moves-condition.ts} +3 -2
  157. package/src/game-factory/condition/{not-condition.js → not-condition.ts} +3 -2
  158. package/src/game-factory/condition/{or-condition.js → or-condition.ts} +3 -2
  159. package/src/game-factory/condition/position-condition.ts +13 -0
  160. package/src/game-factory/condition/{some-condition.js → some-condition.ts} +5 -3
  161. package/src/game-factory/condition/would-condition.ts +104 -0
  162. package/src/game-factory/entity.ts +37 -0
  163. package/src/game-factory/expand-game-rules.ts +263 -0
  164. package/src/game-factory/game-factory.ts +263 -0
  165. package/src/game-factory/move/end-turn.ts +7 -0
  166. package/src/game-factory/move/for-each.ts +20 -0
  167. package/src/game-factory/move/move-entity.ts +18 -0
  168. package/src/game-factory/move/move-factory.ts +107 -0
  169. package/src/game-factory/move/move.ts +147 -0
  170. package/src/game-factory/move/pass-turn.ts +15 -0
  171. package/src/game-factory/move/pass.ts +7 -0
  172. package/src/game-factory/move/place-new.ts +42 -0
  173. package/src/game-factory/move/remove-entity.ts +11 -0
  174. package/src/game-factory/move/set-active-players.ts +26 -0
  175. package/src/game-factory/move/set-state.ts +14 -0
  176. package/src/game-factory/move/shuffle.ts +9 -0
  177. package/src/game-factory/move/take-from.ts +12 -0
  178. package/src/game-factory/space/space.ts +36 -0
  179. package/src/game-factory/space-group/grid.ts +48 -0
  180. package/src/game-factory/space-group/space-group.ts +44 -0
  181. package/src/index.ts +5 -0
  182. package/src/types/bagel-types.ts +449 -0
  183. package/src/types/boardgame-io-core.d.ts +7 -0
  184. package/src/types/index.ts +70 -0
  185. package/src/types/rule-with-conditions.ts +9 -0
  186. package/src/utils/{any-valid-moves.js → any-valid-moves.ts} +54 -49
  187. package/src/utils/bgio-resolve-types.ts +27 -0
  188. package/src/utils/check-conditions.ts +28 -0
  189. package/src/utils/create-payload.ts +19 -0
  190. package/src/utils/deserialize-bgio-arguments.ts +10 -0
  191. package/src/utils/do-moves.ts +22 -0
  192. package/src/utils/entity-matches.ts +30 -0
  193. package/src/utils/expr-eval.d.ts +6 -0
  194. package/src/utils/find-met-condition.ts +23 -0
  195. package/src/utils/get-current-moves.ts +39 -0
  196. package/src/utils/get-scenario-results.ts +30 -0
  197. package/src/utils/get-steps.ts +38 -0
  198. package/src/utils/get.ts +28 -0
  199. package/src/utils/{grid-contains-sequence.js → grid-contains-sequence.ts} +71 -33
  200. package/src/utils/json-transformer.ts +17 -0
  201. package/src/utils/prepare-payload.ts +20 -0
  202. package/src/utils/resolve-entity.ts +15 -0
  203. package/src/utils/resolve-expression.ts +16 -0
  204. package/src/utils/resolve-properties.ts +172 -0
  205. package/src/utils/simulate-move.ts +32 -0
  206. package/src/wackson.d.ts +4 -0
  207. package/tsconfig.build.json +14 -0
  208. package/tsconfig.json +21 -0
  209. package/src/client/client.js +0 -224
  210. package/src/game-factory/bank/bank-slot.js +0 -69
  211. package/src/game-factory/bank/bank.js +0 -114
  212. package/src/game-factory/condition/condition-factory.js +0 -52
  213. package/src/game-factory/condition/condition.js +0 -39
  214. package/src/game-factory/condition/every-condition.js +0 -25
  215. package/src/game-factory/condition/has-line-condition.js +0 -14
  216. package/src/game-factory/condition/in-line-condition.js +0 -19
  217. package/src/game-factory/condition/is-condition.js +0 -23
  218. package/src/game-factory/condition/is-full-condition.js +0 -9
  219. package/src/game-factory/condition/position-condition.js +0 -12
  220. package/src/game-factory/condition/would-condition.js +0 -94
  221. package/src/game-factory/entity.js +0 -29
  222. package/src/game-factory/expand-game-rules.js +0 -271
  223. package/src/game-factory/game-factory.js +0 -239
  224. package/src/game-factory/move/for-each.js +0 -18
  225. package/src/game-factory/move/move-entity.js +0 -16
  226. package/src/game-factory/move/move-factory.js +0 -89
  227. package/src/game-factory/move/move.js +0 -131
  228. package/src/game-factory/move/pass-turn.js +0 -10
  229. package/src/game-factory/move/place-new.js +0 -33
  230. package/src/game-factory/move/remove-entity.js +0 -7
  231. package/src/game-factory/move/set-active-players.js +0 -23
  232. package/src/game-factory/move/set-state.js +0 -11
  233. package/src/game-factory/move/shuffle.js +0 -7
  234. package/src/game-factory/move/take-from.js +0 -7
  235. package/src/game-factory/space/space.js +0 -30
  236. package/src/game-factory/space-group/grid.js +0 -43
  237. package/src/game-factory/space-group/space-group.js +0 -29
  238. package/src/index.js +0 -2
  239. package/src/utils/check-conditions.js +0 -28
  240. package/src/utils/create-payload.js +0 -16
  241. package/src/utils/deserialize-bgio-arguments.js +0 -8
  242. package/src/utils/do-moves.js +0 -18
  243. package/src/utils/entity-matches.js +0 -20
  244. package/src/utils/find-met-condition.js +0 -22
  245. package/src/utils/get-current-moves.js +0 -12
  246. package/src/utils/get-scenario-results.js +0 -23
  247. package/src/utils/get-steps.js +0 -29
  248. package/src/utils/get.js +0 -25
  249. package/src/utils/json-transformer.js +0 -12
  250. package/src/utils/prepare-payload.js +0 -16
  251. package/src/utils/resolve-entity.js +0 -9
  252. package/src/utils/resolve-expression.js +0 -10
  253. package/src/utils/resolve-properties.js +0 -149
  254. package/src/utils/simulate-move.js +0 -25
  255. /package/src/game-factory/move/{index.js → index.ts} +0 -0
  256. /package/src/{registry.js → registry.ts} +0 -0
@@ -5793,19 +5793,6 @@ var require_matches = __commonJS({
5793
5793
  }
5794
5794
  });
5795
5795
 
5796
- // node_modules/lodash/cloneDeep.js
5797
- var require_cloneDeep = __commonJS({
5798
- "node_modules/lodash/cloneDeep.js"(exports, module) {
5799
- var baseClone = require_baseClone();
5800
- var CLONE_DEEP_FLAG = 1;
5801
- var CLONE_SYMBOLS_FLAG = 4;
5802
- function cloneDeep2(value2) {
5803
- return baseClone(value2, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
5804
- }
5805
- module.exports = cloneDeep2;
5806
- }
5807
- });
5808
-
5809
5796
  // node_modules/rfc6902/pointer.js
5810
5797
  var require_pointer = __commonJS({
5811
5798
  "node_modules/rfc6902/pointer.js"(exports) {
@@ -6601,10 +6588,10 @@ function walkCyclical(value2, visitor, seen = /* @__PURE__ */ new WeakSet(), par
6601
6588
  return { duplicates, circular };
6602
6589
  }
6603
6590
 
6604
- // src/game-factory/move/move-factory.js
6591
+ // src/game-factory/move/move-factory.ts
6605
6592
  var import_core2 = __toESM(require_core());
6606
6593
 
6607
- // src/game-factory/entity.js
6594
+ // src/game-factory/entity.ts
6608
6595
  var Entity = class {
6609
6596
  constructor(options, rule, id) {
6610
6597
  if (!options?.fromBank) {
@@ -6632,10 +6619,10 @@ var Entity = class {
6632
6619
  }
6633
6620
  };
6634
6621
 
6635
- // src/game-factory/space/space.js
6622
+ // src/game-factory/space/space.ts
6636
6623
  var Space = class extends Entity {
6637
- constructor(...args) {
6638
- super(...args);
6624
+ constructor(options, rule, id) {
6625
+ super(options, rule, id);
6639
6626
  this.entities = [];
6640
6627
  }
6641
6628
  placeEntity(entity, position = "Last") {
@@ -6658,24 +6645,27 @@ var Space = class extends Entity {
6658
6645
  }
6659
6646
  };
6660
6647
 
6661
- // src/game-factory/board.js
6648
+ // src/game-factory/board.ts
6662
6649
  var Board = class extends Space {
6663
6650
  };
6664
6651
 
6665
- // src/game-factory/space-group/space-group.js
6652
+ // src/game-factory/space-group/space-group.ts
6666
6653
  var SpaceGroup = class extends Entity {
6667
- constructor(options, ...rest) {
6668
- super(options, ...rest);
6654
+ constructor(options, rule, id) {
6655
+ super(options, rule, id);
6669
6656
  this.spaces = this.makeSpaces(options.bank);
6670
6657
  }
6671
6658
  makeSpaces(bank) {
6672
- return Array(this.getSpacesCount()).fill().map((_2, i2) => bank.createEntity({ entityType: "Space", index: i2 }));
6659
+ return Array(this.getSpacesCount()).fill(void 0).map((_2, i2) => bank.createEntity({ entityType: "Space", index: i2 }));
6673
6660
  }
6674
6661
  getEmptySpaces() {
6675
6662
  return this.spaces.filter((space2) => space2.isEmpty());
6676
6663
  }
6677
- getSpace(index) {
6678
- return this.spaces[index];
6664
+ getSpace(arg) {
6665
+ if (Array.isArray(arg)) {
6666
+ throw new Error("Numeric index only for SpaceGroup#getSpace");
6667
+ }
6668
+ return this.spaces[arg];
6679
6669
  }
6680
6670
  getEntities(index) {
6681
6671
  return this.getSpace(index).entities;
@@ -6683,9 +6673,12 @@ var SpaceGroup = class extends Entity {
6683
6673
  placeEntity(index, entity) {
6684
6674
  this.getSpace(index).placeEntity(entity);
6685
6675
  }
6676
+ getSpacesCount() {
6677
+ throw new Error("SpaceGroup#getSpacesCount must be implemented by subclass");
6678
+ }
6686
6679
  };
6687
6680
 
6688
- // src/game-factory/space-group/grid.js
6681
+ // src/game-factory/space-group/grid.ts
6689
6682
  var import_chunk = __toESM(require_chunk());
6690
6683
  var Grid = class extends SpaceGroup {
6691
6684
  getSpacesCount() {
@@ -6705,8 +6698,11 @@ var Grid = class extends SpaceGroup {
6705
6698
  const { width } = this.rule;
6706
6699
  return y2 * width + x2;
6707
6700
  }
6708
- getSpace(coordinates) {
6709
- return this.spaces[this.getIndex(coordinates)];
6701
+ getSpace(arg) {
6702
+ if (Array.isArray(arg)) {
6703
+ return this.spaces[this.getIndex(arg)];
6704
+ }
6705
+ return this.spaces[arg];
6710
6706
  }
6711
6707
  getRelativeCoordinates([oldX, oldY], [relativeX, relativeY]) {
6712
6708
  const newCoordinates = [oldX + relativeX, oldY + relativeY];
@@ -6717,29 +6713,30 @@ var Grid = class extends SpaceGroup {
6717
6713
  }
6718
6714
  };
6719
6715
 
6720
- // src/game-factory/bank/bank.js
6716
+ // src/game-factory/bank/bank.ts
6721
6717
  var import_find = __toESM(require_find());
6722
6718
  var import_filter = __toESM(require_filter());
6723
6719
 
6724
- // src/utils/resolve-properties.js
6720
+ // src/utils/resolve-properties.ts
6725
6721
  var import_isPlainObject2 = __toESM(require_isPlainObject());
6726
6722
  var import_pick = __toESM(require_pick());
6727
6723
 
6728
- // src/utils/get.js
6724
+ // src/utils/get.ts
6729
6725
  function get(obj, pathArray) {
6730
6726
  let current = obj;
6731
6727
  for (const step of pathArray) {
6732
6728
  if (current === void 0) {
6733
6729
  return current;
6734
6730
  }
6735
- if (step?.flatten) {
6731
+ if (step && typeof step === "object" && "flatten" in step && step.flatten) {
6736
6732
  if (!Array.isArray(current)) {
6737
6733
  return void 0;
6738
6734
  }
6739
- current = current.flat();
6735
+ let flat = current.flat();
6740
6736
  if (step.map) {
6741
- current = current.map((item) => get(item, step.map));
6737
+ flat = flat.map((item) => get(item, step.map));
6742
6738
  }
6739
+ current = flat;
6743
6740
  } else {
6744
6741
  current = current[step];
6745
6742
  }
@@ -8353,36 +8350,43 @@ Parser.prototype.isOperatorEnabled = function(op) {
8353
8350
  return !(optionName in operators) || !!operators[optionName];
8354
8351
  };
8355
8352
 
8356
- // src/utils/resolve-expression.js
8353
+ // src/utils/resolve-expression.ts
8357
8354
  var parser = new Parser();
8358
- parser.functions.sum = (array) => array.reduce((acc, val) => acc + val, 0);
8355
+ parser.functions.sum = (...args) => args[0].reduce((acc, val) => acc + val, 0);
8359
8356
  function resolveExpression2(bgioArguments, rule, context) {
8360
8357
  const args = resolveProperties(bgioArguments, rule.arguments, context);
8361
8358
  return parser.evaluate(rule.expression, args);
8362
8359
  }
8363
8360
 
8364
- // src/utils/resolve-entity.js
8361
+ // src/utils/resolve-entity.ts
8365
8362
  var import_isPlainObject = __toESM(require_isPlainObject());
8363
+
8364
+ // src/utils/bgio-resolve-types.ts
8365
+ function bankOf(bg) {
8366
+ return bg.G.bank;
8367
+ }
8368
+
8369
+ // src/utils/resolve-entity.ts
8366
8370
  var abstractTargetNames = ["state"];
8367
8371
  function resolveEntity(bgioArguments, target, context, targetName) {
8368
- return !abstractTargetNames.includes(targetName) && (0, import_isPlainObject.default)(target) ? bgioArguments.G.bank.find(bgioArguments, target, context) : target;
8372
+ return !abstractTargetNames.includes(targetName ?? "") && (0, import_isPlainObject.default)(target) ? bankOf(bgioArguments).find(bgioArguments, target, context) : target;
8369
8373
  }
8370
8374
 
8371
- // src/utils/resolve-properties.js
8375
+ // src/utils/resolve-properties.ts
8372
8376
  var resolutionTerminators = [
8373
8377
  "conditions",
8374
8378
  "move",
8375
8379
  "then",
8376
8380
  "mapping"
8377
8381
  ];
8378
- function resolveProperties(bgioArguments, obj, context, key) {
8382
+ function resolveProperties(bgioArguments, obj, context = {}, key) {
8379
8383
  if (!(0, import_isPlainObject2.default)(obj) && !Array.isArray(obj)) {
8380
8384
  return obj;
8381
8385
  }
8382
8386
  let resolvedProperties = Array.isArray(obj) ? [...obj] : { ...obj };
8383
- Object.entries(obj).forEach(([key2, value2]) => {
8384
- if (!resolutionTerminators.includes(key2)) {
8385
- resolvedProperties[key2] = resolveProperties(bgioArguments, value2, context, key2);
8387
+ Object.entries(obj).forEach(([k2, value2]) => {
8388
+ if (!resolutionTerminators.includes(k2)) {
8389
+ resolvedProperties[k2] = resolveProperties(bgioArguments, value2, context, k2);
8386
8390
  }
8387
8391
  });
8388
8392
  const resolved = resolveProperty(bgioArguments, resolvedProperties, context);
@@ -8395,45 +8399,47 @@ function resolveProperties(bgioArguments, obj, context, key) {
8395
8399
  ) : resolved;
8396
8400
  }
8397
8401
  function resolveProperty(bgioArguments, value2, context) {
8398
- if (value2?.type === "expression") {
8402
+ const v2 = value2;
8403
+ if (v2?.type === "expression") {
8404
+ const expr = v2;
8399
8405
  return resolveExpression2(
8400
8406
  bgioArguments,
8401
8407
  {
8402
- ...value2,
8403
- arguments: resolveProperties(bgioArguments, value2.arguments, context, "arguments")
8408
+ ...expr,
8409
+ arguments: resolveProperties(bgioArguments, expr.arguments, context, "arguments")
8404
8410
  },
8405
8411
  context
8406
8412
  );
8407
- } else if (value2?.type === "count") {
8408
- return bgioArguments.G.bank.findAll(
8413
+ } else if (v2?.type === "count") {
8414
+ return bankOf(bgioArguments).findAll(
8409
8415
  bgioArguments,
8410
8416
  value2,
8411
8417
  context
8412
8418
  ).length;
8413
- } else if (value2?.type === "contextPath") {
8414
- return get(context, value2.path);
8415
- } else if (value2?.type === "ctxPath") {
8416
- return get(bgioArguments.ctx, value2.path);
8417
- } else if (value2?.type === "gamePath") {
8418
- return get(bgioArguments.G, value2.path);
8419
- } else if (value2?.type === "relativePath" || value2?.type === "RelativePath") {
8420
- const target = resolveProperties(bgioArguments, value2.target, context, "target");
8421
- return get(target.attributes, value2.path) ?? null;
8422
- } else if (value2?.type === "parent" || value2?.type === "Parent") {
8423
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8424
- return bgioArguments.G.bank.findParent(originalTarget) ?? null;
8425
- } else if (value2?.type === "map") {
8419
+ } else if (v2?.type === "contextPath") {
8420
+ return get(context, v2.path);
8421
+ } else if (v2?.type === "ctxPath") {
8422
+ return get(bgioArguments.ctx, v2.path);
8423
+ } else if (v2?.type === "gamePath") {
8424
+ return get(bgioArguments.G, v2.path);
8425
+ } else if (v2?.type === "relativePath" || v2?.type === "RelativePath") {
8426
+ const target = resolveProperties(bgioArguments, v2.target, context, "target");
8427
+ return get(target?.attributes, v2.path) ?? null;
8428
+ } else if (v2?.type === "parent" || v2?.type === "Parent") {
8429
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8430
+ return bankOf(bgioArguments).findParent(originalTarget) ?? null;
8431
+ } else if (v2?.type === "map") {
8426
8432
  return getMappedTargets(
8427
8433
  bgioArguments,
8428
- value2.targets,
8429
- value2.mapping,
8434
+ v2.targets,
8435
+ v2.mapping,
8430
8436
  context
8431
8437
  ).map((mappedTarget) => mappedTarget.value);
8432
- } else if (value2?.type === "mapMax") {
8438
+ } else if (v2?.type === "mapMax") {
8433
8439
  const mappedTargets = getMappedTargets(
8434
8440
  bgioArguments,
8435
- value2.targets,
8436
- value2.mapping,
8441
+ v2.targets,
8442
+ v2.mapping,
8437
8443
  context
8438
8444
  );
8439
8445
  let maxValue;
@@ -8449,28 +8455,28 @@ function resolveProperty(bgioArguments, value2, context) {
8449
8455
  }
8450
8456
  }
8451
8457
  return maxTargets;
8452
- } else if (value2?.type === "pick" || value2?.type === "Pick") {
8453
- const target = resolveProperties(bgioArguments, value2.target, context, "target");
8458
+ } else if (v2?.type === "pick" || v2?.type === "Pick") {
8459
+ const target = resolveProperties(bgioArguments, v2.target, context, "target");
8454
8460
  return (0, import_pick.default)(
8455
8461
  resolveProperties(
8456
8462
  bgioArguments,
8457
- target.attributes,
8463
+ target?.attributes,
8458
8464
  context,
8459
8465
  "attributes"
8460
8466
  ),
8461
- value2.properties
8467
+ v2.properties
8462
8468
  );
8463
- } else if (value2?.type === "coordinates" || value2?.type === "Coordinates") {
8464
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8465
- const parent = bgioArguments.G.bank.findParent(originalTarget);
8469
+ } else if (v2?.type === "coordinates" || v2?.type === "Coordinates") {
8470
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8471
+ const parent = bankOf(bgioArguments).findParent(originalTarget);
8466
8472
  return parent.getCoordinates(originalTarget.rule.index);
8467
- } else if (value2?.type === "relativeCoordinates") {
8468
- const originalTarget = value2.target ? resolveProperties(bgioArguments, value2.target, context, "target") : context.originalTarget;
8469
- const parent = bgioArguments.G.bank.findParent(originalTarget);
8473
+ } else if (v2?.type === "relativeCoordinates") {
8474
+ const originalTarget = v2.target ? resolveProperties(bgioArguments, v2.target, context, "target") : context.originalTarget;
8475
+ const parent = bankOf(bgioArguments).findParent(originalTarget);
8470
8476
  const oldCoordinates = parent.getCoordinates(originalTarget.rule.index);
8471
8477
  const newCoordinates = parent.getRelativeCoordinates(
8472
8478
  oldCoordinates,
8473
- resolveProperties(bgioArguments, value2.location, context, "location")
8479
+ resolveProperties(bgioArguments, v2.location, context, "location")
8474
8480
  );
8475
8481
  return (newCoordinates && parent.spaces[parent.getIndex(newCoordinates)]) ?? null;
8476
8482
  } else {
@@ -8479,7 +8485,8 @@ function resolveProperty(bgioArguments, value2, context) {
8479
8485
  }
8480
8486
  function getMappedTargets(bgioArguments, targetsRule, mapping, context) {
8481
8487
  targetsRule.resolveAsEntity = true;
8482
- return resolveProperties(bgioArguments, targetsRule, context)?.map((target) => ({
8488
+ const resolved = resolveProperties(bgioArguments, targetsRule, context);
8489
+ return resolved?.map((target) => ({
8483
8490
  target,
8484
8491
  value: resolveProperties(
8485
8492
  bgioArguments,
@@ -8489,7 +8496,7 @@ function getMappedTargets(bgioArguments, targetsRule, mapping, context) {
8489
8496
  })) ?? [];
8490
8497
  }
8491
8498
 
8492
- // src/game-factory/condition/condition.js
8499
+ // src/game-factory/condition/condition.ts
8493
8500
  var Condition = class {
8494
8501
  constructor(rule) {
8495
8502
  this.rule = rule;
@@ -8514,11 +8521,15 @@ var Condition = class {
8514
8521
  return this.checkCondition(bgioArguments, rule, conditionPayload, newContext);
8515
8522
  }
8516
8523
  isMet(...args) {
8517
- return this.check(...args).conditionIsMet;
8524
+ return this.check(
8525
+ args[0],
8526
+ args[1] ?? {},
8527
+ args[2] ?? {}
8528
+ ).conditionIsMet;
8518
8529
  }
8519
8530
  };
8520
8531
 
8521
- // src/utils/entity-matches.js
8532
+ // src/utils/entity-matches.ts
8522
8533
  var import_matches = __toESM(require_matches());
8523
8534
  function resolveMatcher(bgioArguments, matcher, context) {
8524
8535
  const resolvedMatcher = { ...matcher };
@@ -8536,7 +8547,7 @@ function entityMatches(bgioArguments, matcher, entity, context) {
8536
8547
  return (0, import_matches.default)(resolveMatcher(bgioArguments, matcher, context))(getEntityMatcher(entity));
8537
8548
  }
8538
8549
 
8539
- // src/game-factory/condition/is-condition.js
8550
+ // src/game-factory/condition/is-condition.ts
8540
8551
  var Is = class extends Condition {
8541
8552
  checkCondition(bgioArguments, rule, { target }, context) {
8542
8553
  if (this.rule.entity && target !== rule.entity) {
@@ -8557,12 +8568,12 @@ var Is = class extends Condition {
8557
8568
  }
8558
8569
  };
8559
8570
 
8560
- // src/game-factory/condition/not-condition.js
8571
+ // src/game-factory/condition/not-condition.ts
8561
8572
  var NotCondition = class extends Condition {
8562
8573
  checkCondition(bgioArguments, rule, payload, context) {
8563
8574
  const result = checkConditions(
8564
8575
  bgioArguments,
8565
- rule,
8576
+ rule.conditions,
8566
8577
  payload,
8567
8578
  context
8568
8579
  );
@@ -8570,8 +8581,8 @@ var NotCondition = class extends Condition {
8570
8581
  }
8571
8582
  };
8572
8583
 
8573
- // src/utils/find-met-condition.js
8574
- function findMetCondition(bgioArguments, { conditions = [] }, payload, context) {
8584
+ // src/utils/find-met-condition.ts
8585
+ function findMetCondition(bgioArguments, conditions = [], payload, context) {
8575
8586
  let success;
8576
8587
  for (const conditionRule of conditions) {
8577
8588
  const result = conditionFactory(conditionRule).check(bgioArguments, payload, context);
@@ -8586,12 +8597,12 @@ function findMetCondition(bgioArguments, { conditions = [] }, payload, context)
8586
8597
  return success;
8587
8598
  }
8588
8599
 
8589
- // src/game-factory/condition/or-condition.js
8600
+ // src/game-factory/condition/or-condition.ts
8590
8601
  var Or = class extends Condition {
8591
8602
  checkCondition(bgioArguments, rule, payload, context) {
8592
8603
  const result = findMetCondition(
8593
8604
  bgioArguments,
8594
- rule,
8605
+ rule.conditions,
8595
8606
  payload,
8596
8607
  context
8597
8608
  );
@@ -8599,9 +8610,10 @@ var Or = class extends Condition {
8599
8610
  }
8600
8611
  };
8601
8612
 
8602
- // src/game-factory/condition/some-condition.js
8613
+ // src/game-factory/condition/some-condition.ts
8603
8614
  var SomeCondition = class extends Condition {
8604
- checkCondition(bgioArguments, rule, { target: targets }, context) {
8615
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8616
+ const targets = conditionPayload.target;
8605
8617
  const result = targets.find((target) => {
8606
8618
  const loopContext = {
8607
8619
  ...context,
@@ -8609,7 +8621,7 @@ var SomeCondition = class extends Condition {
8609
8621
  };
8610
8622
  return checkConditions(
8611
8623
  bgioArguments,
8612
- rule,
8624
+ rule.conditions,
8613
8625
  void 0,
8614
8626
  loopContext
8615
8627
  ).conditionsAreMet;
@@ -8621,9 +8633,10 @@ var SomeCondition = class extends Condition {
8621
8633
  }
8622
8634
  };
8623
8635
 
8624
- // src/game-factory/condition/every-condition.js
8636
+ // src/game-factory/condition/every-condition.ts
8625
8637
  var EveryCondition = class extends Condition {
8626
- checkCondition(bgioArguments, rule, { target: targets }, context) {
8638
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8639
+ const targets = conditionPayload.target;
8627
8640
  const results = targets.map((target) => {
8628
8641
  const loopContext = {
8629
8642
  ...context,
@@ -8631,7 +8644,7 @@ var EveryCondition = class extends Condition {
8631
8644
  };
8632
8645
  return checkConditions(
8633
8646
  bgioArguments,
8634
- rule,
8647
+ rule.conditions,
8635
8648
  void 0,
8636
8649
  loopContext
8637
8650
  );
@@ -8643,18 +8656,18 @@ var EveryCondition = class extends Condition {
8643
8656
  }
8644
8657
  };
8645
8658
 
8646
- // src/game-factory/condition/contains-condition.js
8659
+ // src/game-factory/condition/contains-condition.ts
8647
8660
  var import_matches2 = __toESM(require_matches());
8648
8661
  var ContainsCondition = class extends Condition {
8649
8662
  checkCondition(bgioArguments, rule, payload, context) {
8650
- const { target } = payload;
8663
+ const target = payload.target;
8651
8664
  if (!target) {
8652
8665
  return { matches: [], conditionIsMet: false };
8653
8666
  } else {
8654
8667
  const candidates = target.entities ?? target.spaces;
8655
8668
  const matches2 = candidates?.filter((entity) => checkConditions(
8656
8669
  bgioArguments,
8657
- rule,
8670
+ rule.conditions,
8658
8671
  { target: entity },
8659
8672
  context
8660
8673
  ).conditionsAreMet) ?? [];
@@ -8663,22 +8676,25 @@ var ContainsCondition = class extends Condition {
8663
8676
  }
8664
8677
  };
8665
8678
 
8666
- // src/game-factory/condition/contains-same-condition.js
8679
+ // src/game-factory/condition/contains-same-condition.ts
8667
8680
  var import_pick2 = __toESM(require_pick());
8668
8681
  var ContainsSame = class extends Condition {
8669
- checkCondition(bgioArguments, rule, { targets }) {
8682
+ checkCondition(bgioArguments, rule, conditionPayload, _newContext) {
8683
+ const { targets } = conditionPayload;
8670
8684
  if (targets.length === 1 && targets[0].entities?.length) {
8671
8685
  return { conditionIsMet: true };
8672
8686
  }
8673
8687
  const [first, ...restEntities] = targets;
8674
- const conditionIsMet = first.entities.some((entity) => {
8688
+ const conditionIsMet = (first.entities ?? []).some((entity) => {
8689
+ const e = entity;
8675
8690
  const condition2 = conditionFactory({
8676
8691
  conditionType: "Contains",
8677
8692
  conditions: [{
8678
8693
  conditionType: "Is",
8679
- matcher: (0, import_pick2.default)(entity.rule, rule.properties)
8694
+ matcher: (0, import_pick2.default)(e.rule, rule.properties)
8680
8695
  }]
8681
8696
  });
8697
+ if (!condition2) return false;
8682
8698
  return restEntities.every((ent) => {
8683
8699
  return condition2.isMet(bgioArguments, { target: ent });
8684
8700
  });
@@ -8687,7 +8703,7 @@ var ContainsSame = class extends Condition {
8687
8703
  }
8688
8704
  };
8689
8705
 
8690
- // src/utils/grid-contains-sequence.js
8706
+ // src/utils/grid-contains-sequence.ts
8691
8707
  var import_matches3 = __toESM(require_matches());
8692
8708
  var directions = [
8693
8709
  [1, 0],
@@ -8806,12 +8822,9 @@ function tryMatchSequence(bgioArguments, lineSpaces, startIndex, sequencePattern
8806
8822
  return matchedSpaces.length > 0 ? matchedSpaces : null;
8807
8823
  }
8808
8824
  function checkSpaceConditions(bgioArguments, space2, conditions, chunkMatches = [], context) {
8809
- if (!conditions || conditions.length === 0) {
8810
- return true;
8811
- }
8812
8825
  return checkConditions(
8813
8826
  bgioArguments,
8814
- { conditions },
8827
+ conditions,
8815
8828
  {
8816
8829
  target: space2,
8817
8830
  targets: [space2, ...chunkMatches]
@@ -8860,13 +8873,18 @@ function gridContainsSequence(bgioArguments, grid, sequencePattern, context) {
8860
8873
  return result;
8861
8874
  }
8862
8875
 
8863
- // src/game-factory/condition/in-line-condition.js
8876
+ // src/game-factory/condition/in-line-condition.ts
8864
8877
  var InLineCondition = class extends Condition {
8865
8878
  checkCondition(bgioArguments, rule, payload, context) {
8866
8879
  const { G: G2 } = bgioArguments;
8867
8880
  const { target } = payload;
8868
8881
  const parent = G2.bank.findParent(payload.target);
8869
- const { matches: allMatches } = gridContainsSequence(bgioArguments, parent, rule.sequence, context);
8882
+ const { matches: allMatches } = gridContainsSequence(
8883
+ bgioArguments,
8884
+ parent,
8885
+ rule.sequence,
8886
+ context
8887
+ );
8870
8888
  const matches2 = allMatches.filter(
8871
8889
  (sequence) => sequence.some((space2) => space2 === target)
8872
8890
  );
@@ -8874,7 +8892,7 @@ var InLineCondition = class extends Condition {
8874
8892
  }
8875
8893
  };
8876
8894
 
8877
- // src/game-factory/condition/has-line-condition.js
8895
+ // src/game-factory/condition/has-line-condition.ts
8878
8896
  var HasLineCondition = class extends Condition {
8879
8897
  checkCondition(bgioArguments, rule, payload, context) {
8880
8898
  const { matches: matches2 } = gridContainsSequence(
@@ -8887,16 +8905,17 @@ var HasLineCondition = class extends Condition {
8887
8905
  }
8888
8906
  };
8889
8907
 
8890
- // src/game-factory/condition/is-full-condition.js
8908
+ // src/game-factory/condition/is-full-condition.ts
8891
8909
  var IsFull = class extends Condition {
8892
- checkCondition(bgioArguments, rule, payload, context) {
8910
+ checkCondition(_bgioArguments, _rule, payload, _context) {
8911
+ const t2 = payload.target;
8893
8912
  return {
8894
- conditionIsMet: payload.target.spaces.every((space2) => space2?.entities.length)
8913
+ conditionIsMet: t2.spaces.every((space2) => space2?.entities?.length)
8895
8914
  };
8896
8915
  }
8897
8916
  };
8898
8917
 
8899
- // src/utils/simulate-move.js
8918
+ // src/utils/simulate-move.ts
8900
8919
  function simulateMove(bgioArguments, payload, context) {
8901
8920
  const simulatedG = deserialize(serialize(bgioArguments.G), registry);
8902
8921
  const newBgioArguments = {
@@ -8916,7 +8935,7 @@ function simulateMove(bgioArguments, payload, context) {
8916
8935
  return simulatedG;
8917
8936
  }
8918
8937
 
8919
- // src/game-factory/condition/would-condition.js
8938
+ // src/game-factory/condition/would-condition.ts
8920
8939
  var argNameMap = {
8921
8940
  PlaceNew: ["destination"],
8922
8941
  RemoveEntity: ["entity"],
@@ -8925,12 +8944,16 @@ var argNameMap = {
8925
8944
  SetState: ["entity", "state"]
8926
8945
  };
8927
8946
  var WouldCondition = class extends Condition {
8928
- checkCondition(bgioArguments, rule, { target, targets = [target] }, context) {
8947
+ checkCondition(bgioArguments, rule, conditionPayload, context) {
8948
+ const target = conditionPayload.target;
8949
+ const targets = conditionPayload.targets ?? [target];
8950
+ const moveType = context.moveInstance?.rule?.moveType;
8951
+ const argNames = moveType ? argNameMap[moveType] : void 0;
8929
8952
  const payload = {
8930
- arguments: targets.reduce((acc, target2, i2) => ({
8931
- ...acc,
8932
- [argNameMap[context.moveInstance.rule.moveType][i2]]: target2
8933
- }), {})
8953
+ arguments: targets.reduce((acc, t2, i2) => {
8954
+ const key = argNames?.[i2] ?? `arg${i2}`;
8955
+ return { ...acc, [key]: t2 };
8956
+ }, {})
8934
8957
  };
8935
8958
  const simulatedG = simulateMove(
8936
8959
  bgioArguments,
@@ -8948,11 +8971,8 @@ var WouldCondition = class extends Condition {
8948
8971
  };
8949
8972
  }
8950
8973
  const conditionResults = checkConditions(
8951
- {
8952
- ...bgioArguments,
8953
- G: simulatedG
8954
- },
8955
- rule,
8974
+ { ...bgioArguments, G: simulatedG },
8975
+ rule.conditions,
8956
8976
  simulatedConditionsPayload,
8957
8977
  context
8958
8978
  );
@@ -8980,26 +9000,26 @@ function restoreReferences(obj, getOriginalEntity, seen = /* @__PURE__ */ new We
8980
9000
  }
8981
9001
  if (Array.isArray(obj)) {
8982
9002
  return obj.map((item) => restoreReferences(item, getOriginalEntity, seen));
8983
- } else {
8984
- const restored = {};
8985
- for (const key in obj) {
8986
- if (obj.hasOwnProperty(key)) {
8987
- restored[key] = restoreReferences(obj[key], getOriginalEntity, seen);
8988
- }
9003
+ }
9004
+ const restored = {};
9005
+ for (const key in obj) {
9006
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
9007
+ restored[key] = restoreReferences(obj[key], getOriginalEntity, seen);
8989
9008
  }
8990
- return restored;
8991
9009
  }
9010
+ return restored;
8992
9011
  }
8993
9012
 
8994
- // src/utils/any-valid-moves.js
9013
+ // src/utils/any-valid-moves.ts
8995
9014
  var import_isPlainObject3 = __toESM(require_isPlainObject());
8996
9015
  function findMoveArgumentReferences(obj, refs = /* @__PURE__ */ new Set()) {
8997
9016
  if (!obj || typeof obj !== "object") {
8998
9017
  return refs;
8999
9018
  }
9000
- if (obj.type === "contextPath" && Array.isArray(obj.path)) {
9001
- if (obj.path[0] === "moveArguments" && obj.path[1]) {
9002
- refs.add(obj.path[1]);
9019
+ const o2 = obj;
9020
+ if (o2.type === "contextPath" && Array.isArray(o2.path)) {
9021
+ if (o2.path[0] === "moveArguments" && o2.path[1]) {
9022
+ refs.add(String(o2.path[1]));
9003
9023
  }
9004
9024
  }
9005
9025
  for (const value2 of Object.values(obj)) {
@@ -9073,21 +9093,23 @@ function findValidCombination(bgioArguments, moveInstance, ruleArguments, ordere
9073
9093
  });
9074
9094
  }
9075
9095
  function areThereValidMoves(bgioArguments, moves) {
9096
+ const bgio = bgioArguments;
9076
9097
  return Object.values(moves).some((move) => {
9077
- const { moveInstance } = move;
9098
+ const moveInstance = move?.moveInstance;
9099
+ if (!moveInstance) return false;
9078
9100
  const context = { moveInstance };
9079
9101
  const rule = resolveProperties(
9080
- bgioArguments,
9102
+ bgio,
9081
9103
  moveInstance.rule,
9082
9104
  context
9083
9105
  );
9084
9106
  const ruleArguments = rule.arguments ?? {};
9085
9107
  if (Object.keys(ruleArguments).length === 0) {
9086
- return moveInstance.isValid(bgioArguments, { arguments: {} }, context);
9108
+ return moveInstance.isValid(bgio, { arguments: {} }, context);
9087
9109
  }
9088
9110
  const orderedArgNames = getArgumentOrder(ruleArguments);
9089
9111
  return findValidCombination(
9090
- bgioArguments,
9112
+ bgio,
9091
9113
  moveInstance,
9092
9114
  ruleArguments,
9093
9115
  orderedArgNames,
@@ -9096,18 +9118,19 @@ function areThereValidMoves(bgioArguments, moves) {
9096
9118
  });
9097
9119
  }
9098
9120
 
9099
- // src/utils/get-current-moves.js
9100
- function getCurrentMoves(state, { game, playerID, stageName }) {
9121
+ // src/utils/get-current-moves.ts
9122
+ function getCurrentMoves(state, client) {
9123
+ const { game, playerID, stageName } = client;
9101
9124
  const phaseName = state.ctx.phase;
9102
- const stageNameToUse = stageName ?? state.ctx.activePlayers?.[playerID ?? state.ctx.currentPlayer];
9125
+ const stageNameToUse = stageName ?? state.ctx.activePlayers?.[playerID ?? state.ctx.currentPlayer ?? ""];
9103
9126
  const phaseOrRoot = game.phases?.[phaseName] ?? game;
9104
9127
  const stageOrPhaseOrRoot = phaseOrRoot.turn?.stages?.[stageNameToUse] ?? phaseOrRoot;
9105
9128
  return stageOrPhaseOrRoot.moves ?? {};
9106
9129
  }
9107
9130
 
9108
- // src/game-factory/condition/no-possible-moves-condition.js
9131
+ // src/game-factory/condition/no-possible-moves-condition.ts
9109
9132
  var NoPossibleMoves = class extends Condition {
9110
- checkCondition(bgioArguments, _2, __, context) {
9133
+ checkCondition(bgioArguments, _unused, _payload, context) {
9111
9134
  return {
9112
9135
  conditionIsMet: !areThereValidMoves(
9113
9136
  bgioArguments,
@@ -9117,7 +9140,7 @@ var NoPossibleMoves = class extends Condition {
9117
9140
  }
9118
9141
  };
9119
9142
 
9120
- // src/game-factory/condition/evaluate-condition.js
9143
+ // src/game-factory/condition/evaluate-condition.ts
9121
9144
  var import_matches4 = __toESM(require_matches());
9122
9145
  var Evaluate = class extends Condition {
9123
9146
  checkCondition(bgioArguments, rule, payload, context) {
@@ -9134,11 +9157,12 @@ var Evaluate = class extends Condition {
9134
9157
  }
9135
9158
  };
9136
9159
 
9137
- // src/game-factory/condition/position-condition.js
9160
+ // src/game-factory/condition/position-condition.ts
9138
9161
  var Position = class extends Condition {
9139
- checkCondition(bgioArguments, rule, { target }) {
9162
+ checkCondition(bgioArguments, rule, conditionPayload, _newContext) {
9163
+ const target = conditionPayload.target;
9140
9164
  const parent = bgioArguments.G.bank.findParent(target);
9141
- let conditionIsMet;
9165
+ let conditionIsMet = false;
9142
9166
  if (rule.position === "First") {
9143
9167
  conditionIsMet = parent.entities.indexOf(target) === 0;
9144
9168
  }
@@ -9146,42 +9170,46 @@ var Position = class extends Condition {
9146
9170
  }
9147
9171
  };
9148
9172
 
9149
- // src/game-factory/condition/condition-factory.js
9173
+ // src/game-factory/condition/condition-factory.ts
9150
9174
  function conditionFactory(rule) {
9151
- if (rule.conditionType === "Is") {
9152
- return new Is(rule);
9153
- } else if (rule.conditionType === "Not") {
9154
- return new NotCondition(rule);
9155
- } else if (rule.conditionType === "Or") {
9156
- return new Or(rule);
9157
- } else if (rule.conditionType === "Some") {
9158
- return new SomeCondition(rule);
9159
- } else if (rule.conditionType === "Contains") {
9160
- return new ContainsCondition(rule);
9161
- } else if (rule.conditionType === "ContainsSame") {
9162
- return new ContainsSame(rule);
9163
- } else if (rule.conditionType === "Every") {
9164
- return new EveryCondition(rule);
9165
- } else if (rule.conditionType === "InLine") {
9166
- return new InLineCondition(rule);
9167
- } else if (rule.conditionType === "HasLine") {
9168
- return new HasLineCondition(rule);
9169
- } else if (rule.conditionType === "IsFull") {
9170
- return new IsFull(rule);
9171
- } else if (rule.conditionType === "Would") {
9172
- return new WouldCondition(rule);
9173
- } else if (rule.conditionType === "NoPossibleMoves") {
9174
- return new NoPossibleMoves(rule);
9175
- } else if (rule.conditionType === "Evaluate") {
9176
- return new Evaluate(rule);
9177
- } else if (rule.conditionType === "Position") {
9178
- return new Position(rule);
9179
- }
9180
- }
9181
-
9182
- // src/utils/check-conditions.js
9183
- function checkConditions(bgioArguments, rule, payload, context) {
9184
- const { conditions = [] } = rule;
9175
+ if (typeof rule !== "object" || rule === null || !("conditionType" in rule)) {
9176
+ return void 0;
9177
+ }
9178
+ const r2 = rule;
9179
+ if (r2.conditionType === "Is") {
9180
+ return new Is(r2);
9181
+ } else if (r2.conditionType === "Not") {
9182
+ return new NotCondition(r2);
9183
+ } else if (r2.conditionType === "Or") {
9184
+ return new Or(r2);
9185
+ } else if (r2.conditionType === "Some") {
9186
+ return new SomeCondition(r2);
9187
+ } else if (r2.conditionType === "Contains") {
9188
+ return new ContainsCondition(r2);
9189
+ } else if (r2.conditionType === "ContainsSame") {
9190
+ return new ContainsSame(r2);
9191
+ } else if (r2.conditionType === "Every") {
9192
+ return new EveryCondition(r2);
9193
+ } else if (r2.conditionType === "InLine") {
9194
+ return new InLineCondition(r2);
9195
+ } else if (r2.conditionType === "HasLine") {
9196
+ return new HasLineCondition(r2);
9197
+ } else if (r2.conditionType === "IsFull") {
9198
+ return new IsFull(r2);
9199
+ } else if (r2.conditionType === "Would") {
9200
+ return new WouldCondition(r2);
9201
+ } else if (r2.conditionType === "NoPossibleMoves") {
9202
+ return new NoPossibleMoves(r2);
9203
+ } else if (r2.conditionType === "Evaluate") {
9204
+ return new Evaluate(r2);
9205
+ } else if (r2.conditionType === "Position") {
9206
+ return new Position(r2);
9207
+ }
9208
+ return void 0;
9209
+ }
9210
+
9211
+ // src/utils/check-conditions.ts
9212
+ function checkConditions(bgioArguments, conditions = [], payload = {}, context = {}) {
9185
9213
  const results = [];
9186
9214
  let failedAt;
9187
9215
  for (const conditionRule of conditions) {
@@ -9200,18 +9228,18 @@ function checkConditions(bgioArguments, rule, payload, context) {
9200
9228
  };
9201
9229
  }
9202
9230
 
9203
- // src/game-factory/bank/bank-slot.js
9231
+ // src/game-factory/bank/bank-slot.ts
9204
9232
  var BankSlot = class {
9205
9233
  constructor(rule, bank) {
9206
9234
  this.bank = bank;
9207
9235
  this.rule = rule;
9208
9236
  this.pool = [];
9209
- this.remaining = +rule.count || 1;
9237
+ this.remaining = +(rule.count || 1);
9210
9238
  }
9211
9239
  getOne(bgioArguments, options, context) {
9212
9240
  return this.getMultiple(bgioArguments, 1, options, context)[0];
9213
9241
  }
9214
- getMultiple(bgioArguments, count = Infinity, options = {}, context) {
9242
+ getMultiple(bgioArguments, count = Infinity, options = {}, context = {}) {
9215
9243
  const toReturn = [];
9216
9244
  if (this.remaining === Infinity && count === Infinity) {
9217
9245
  throw new Error(`Cannot get infinite pieces from slot with infinite remaining: ${this.rule.name}`);
@@ -9236,7 +9264,10 @@ var BankSlot = class {
9236
9264
  if (options.state) {
9237
9265
  const newState = resolveProperties(bgioArguments, options.state, context);
9238
9266
  toReturn.forEach((entity) => {
9239
- entity.state = { ...entity.state, ...newState };
9267
+ entity.state = {
9268
+ ...entity.state,
9269
+ ...newState
9270
+ };
9240
9271
  });
9241
9272
  }
9242
9273
  return toReturn;
@@ -9255,7 +9286,7 @@ var BankSlot = class {
9255
9286
  };
9256
9287
  var bank_slot_default = BankSlot;
9257
9288
 
9258
- // src/game-factory/bank/bank.js
9289
+ // src/game-factory/bank/bank.ts
9259
9290
  var Bank = class {
9260
9291
  constructor(entityRules) {
9261
9292
  this.currentEntityId = 0;
@@ -9263,7 +9294,8 @@ var Bank = class {
9263
9294
  this.slots = entityRules.map((rule) => new bank_slot_default(rule, this));
9264
9295
  }
9265
9296
  createEntity(definition = {}, options) {
9266
- const entity = new registry[definition.entityType || "Entity"](
9297
+ const Ctor = registry[definition.entityType || "Entity"];
9298
+ const entity = new Ctor(
9267
9299
  {
9268
9300
  bank: this,
9269
9301
  fromBank: true,
@@ -9289,7 +9321,7 @@ var Bank = class {
9289
9321
  Object.values(this.tracker),
9290
9322
  (entity) => checkConditions(
9291
9323
  bgioArguments,
9292
- rule,
9324
+ rule.conditions,
9293
9325
  { target: entity },
9294
9326
  context
9295
9327
  ).conditionsAreMet
@@ -9328,7 +9360,7 @@ var Bank = class {
9328
9360
  return this.slots.find(
9329
9361
  (slot) => checkConditions(
9330
9362
  bgioArguments,
9331
- rule,
9363
+ rule.conditions,
9332
9364
  { target: slot },
9333
9365
  context
9334
9366
  ).conditionsAreMet
@@ -9338,7 +9370,7 @@ var Bank = class {
9338
9370
  return this.slots.filter(
9339
9371
  (slot) => checkConditions(
9340
9372
  bgioArguments,
9341
- rule,
9373
+ rule.conditions,
9342
9374
  { target: slot },
9343
9375
  context
9344
9376
  ).conditionsAreMet
@@ -9346,13 +9378,13 @@ var Bank = class {
9346
9378
  }
9347
9379
  returnToBank(bgioArguments, entity) {
9348
9380
  this.findParent(entity).remove(entity);
9349
- this.getSlot(bgioArguments, entity.rule).returnToBank(entity);
9381
+ this.getSlot(bgioArguments, entity.rule, {}).returnToBank(entity);
9350
9382
  delete this.tracker[entity.entityId];
9351
9383
  }
9352
9384
  };
9353
9385
  var bank_default = Bank;
9354
9386
 
9355
- // src/registry.js
9387
+ // src/registry.ts
9356
9388
  var registry = {
9357
9389
  Board,
9358
9390
  SpaceGroup,
@@ -9363,7 +9395,7 @@ var registry = {
9363
9395
  Entity
9364
9396
  };
9365
9397
 
9366
- // src/utils/deserialize-bgio-arguments.js
9398
+ // src/utils/deserialize-bgio-arguments.ts
9367
9399
  function deserializeBgioArguments(bgioArguments) {
9368
9400
  return {
9369
9401
  ...bgioArguments,
@@ -9371,14 +9403,15 @@ function deserializeBgioArguments(bgioArguments) {
9371
9403
  };
9372
9404
  }
9373
9405
 
9374
- // src/game-factory/move/move.js
9406
+ // src/game-factory/move/move.ts
9375
9407
  var import_core = __toESM(require_core());
9376
9408
  var Move = class {
9377
9409
  constructor(rule) {
9378
9410
  this.rule = this.transformRule(rule);
9379
9411
  }
9380
9412
  checkValidity(bgioArguments, payload, context) {
9381
- const argRuleEntries = Object.entries(this.rule.arguments ?? {});
9413
+ const moveArguments = "arguments" in this.rule && this.rule.arguments ? this.rule.arguments : {};
9414
+ const argRuleEntries = Object.entries(moveArguments);
9382
9415
  if (!argRuleEntries.every(([argName]) => {
9383
9416
  const arg = payload.arguments[argName];
9384
9417
  return arg !== void 0 && (!Array.isArray(arg) || arg.length);
@@ -9391,11 +9424,11 @@ var Move = class {
9391
9424
  const payloadArg = payload.arguments[argName];
9392
9425
  const args = Array.isArray(payloadArg) ? payloadArg : [payloadArg];
9393
9426
  const argResults = [];
9394
- for (let j2 = 0, len2 = args.length; j2 < len2; j2++) {
9427
+ for (let j2 = 0, lenj = args.length; j2 < lenj; j2++) {
9395
9428
  const arg = args[j2];
9396
9429
  const result = checkConditions(
9397
9430
  bgioArguments,
9398
- argRule,
9431
+ argRule.conditions,
9399
9432
  { target: arg },
9400
9433
  { ...context, moveArguments: payload.arguments }
9401
9434
  );
@@ -9404,7 +9437,8 @@ var Move = class {
9404
9437
  break;
9405
9438
  }
9406
9439
  }
9407
- const argConditionsAreMet = argResults.at(-1).conditionsAreMet;
9440
+ const last = argResults[argResults.length - 1];
9441
+ const argConditionsAreMet = last?.conditionsAreMet ?? false;
9408
9442
  argumentResults[argName] = {
9409
9443
  results: argResults,
9410
9444
  conditionsAreMet: argConditionsAreMet
@@ -9415,8 +9449,8 @@ var Move = class {
9415
9449
  }
9416
9450
  const moveResults = checkConditions(
9417
9451
  bgioArguments,
9418
- { conditions: this.rule.conditions },
9419
- void 0,
9452
+ this.rule.conditions,
9453
+ {},
9420
9454
  { ...context, moveArguments: payload.arguments }
9421
9455
  );
9422
9456
  return {
@@ -9431,6 +9465,7 @@ var Move = class {
9431
9465
  payload,
9432
9466
  context
9433
9467
  );
9468
+ if (conditionResults === false) return false;
9434
9469
  return conditionResults.conditionsAreMet;
9435
9470
  }
9436
9471
  doMove(bgioArguments, payload, context, { skipCheck = false } = {}) {
@@ -9441,12 +9476,10 @@ var Move = class {
9441
9476
  );
9442
9477
  const resolvedPayload = {
9443
9478
  ...payload,
9444
- arguments: Object.entries(rule.arguments ?? {}).reduce((acc, [argName, arg]) => {
9445
- return {
9446
- ...acc,
9447
- [argName]: payload?.arguments?.[argName] ?? arg
9448
- };
9449
- }, {})
9479
+ arguments: Object.entries(rule.arguments ?? {}).reduce((acc, [argName, arg]) => ({
9480
+ ...acc,
9481
+ [argName]: payload?.arguments?.[argName] ?? arg
9482
+ }), {})
9450
9483
  };
9451
9484
  if (rule.name) {
9452
9485
  bgioArguments.G._meta.previousPayloads[rule.name] = resolvedPayload;
@@ -9455,7 +9488,7 @@ var Move = class {
9455
9488
  if (!skipCheck) {
9456
9489
  conditionResults = this.checkValidity(bgioArguments, resolvedPayload, context);
9457
9490
  }
9458
- if (!skipCheck && !conditionResults.conditionsAreMet) {
9491
+ if (!skipCheck && conditionResults !== false && !conditionResults.conditionsAreMet) {
9459
9492
  return import_core.INVALID_MOVE;
9460
9493
  } else {
9461
9494
  this.do(bgioArguments, rule, resolvedPayload, context);
@@ -9465,81 +9498,100 @@ var Move = class {
9465
9498
  }
9466
9499
  return { conditionResults };
9467
9500
  }
9501
+ do(_bgioArguments, _rule, _resolvedPayload, _context) {
9502
+ throw new Error("Move#do must be implemented by subclass");
9503
+ }
9468
9504
  transformRule(rule) {
9469
9505
  const args = rule.arguments;
9470
- for (let key in args) {
9471
- const arg = args[key];
9472
- if (!arg.playerChoice) {
9473
- arg.resolveAsEntity = true;
9506
+ if (args) {
9507
+ for (const key in args) {
9508
+ const arg = args[key];
9509
+ if (arg && !arg.playerChoice) {
9510
+ arg.resolveAsEntity = true;
9511
+ }
9474
9512
  }
9475
9513
  }
9476
9514
  return rule;
9477
9515
  }
9478
9516
  };
9479
9517
 
9480
- // src/game-factory/move/move-entity.js
9518
+ // src/game-factory/move/move-entity.ts
9481
9519
  var MoveEntity = class extends Move {
9482
- do(bgioArguments, rule, { arguments: { entity, destination } }) {
9520
+ do(bgioArguments, rule, resolvedPayload) {
9521
+ const { entity, destination } = resolvedPayload.arguments;
9522
+ const g2 = bgioArguments;
9483
9523
  if (Array.isArray(entity)) {
9484
9524
  entity.forEach((e) => {
9485
- bgioArguments.G.bank.findParent(e)?.remove(e);
9525
+ g2.G.bank.findParent(e)?.remove(e);
9486
9526
  destination.placeEntity(e, rule.position);
9487
9527
  });
9488
9528
  } else {
9489
- bgioArguments.G.bank.findParent(entity)?.remove(entity);
9529
+ g2.G.bank.findParent(entity)?.remove(entity);
9490
9530
  destination.placeEntity(entity, rule.position);
9491
9531
  }
9492
9532
  }
9493
9533
  };
9494
9534
 
9495
- // src/game-factory/move/remove-entity.js
9535
+ // src/game-factory/move/remove-entity.ts
9496
9536
  var RemoveEntity = class extends Move {
9497
- do(bgioArguments, rule, { arguments: { entity } }) {
9498
- bgioArguments.G.bank.returnToBank(bgioArguments, entity);
9537
+ do(bgioArguments, _rule, resolvedPayload) {
9538
+ const { entity } = resolvedPayload.arguments;
9539
+ const bgio = bgioArguments;
9540
+ bankOf(bgio).returnToBank(bgio, entity);
9499
9541
  }
9500
9542
  };
9501
9543
 
9502
- // src/game-factory/move/place-new.js
9544
+ // src/game-factory/move/place-new.ts
9503
9545
  var PlaceNew = class extends Move {
9504
- do(bgioArguments, rule, { arguments: { destination } }, context) {
9505
- const entities = rule.matchMultiple ? bgioArguments.G.bank.getMultiple(
9506
- bgioArguments,
9546
+ do(bgioArguments, rule, resolvedPayload, context) {
9547
+ const { destination } = resolvedPayload.arguments;
9548
+ const bgio = bgioArguments;
9549
+ const r2 = rule;
9550
+ const bank = bankOf(bgio);
9551
+ const entities = r2.matchMultiple ? bank.getMultiple(
9552
+ bgio,
9507
9553
  {
9508
- ...rule.entity,
9554
+ ...r2.entity,
9509
9555
  conditions: [
9510
- ...rule.entity?.conditions || [],
9511
- ...rule.conditions || []
9556
+ ...r2.entity?.conditions || [],
9557
+ ...r2.conditions || []
9512
9558
  ]
9513
9559
  },
9514
- rule.count,
9560
+ r2.count ?? 1,
9515
9561
  context
9516
- ) : [bgioArguments.G.bank.getOne(
9517
- bgioArguments,
9562
+ ) : [bank.getOne(
9563
+ bgio,
9518
9564
  {
9519
- ...rule.entity,
9565
+ ...r2.entity,
9520
9566
  conditions: [
9521
- ...rule.entity?.conditions || [],
9522
- ...rule.conditions || []
9567
+ ...r2.entity?.conditions || [],
9568
+ ...r2.conditions || []
9523
9569
  ]
9524
9570
  },
9525
9571
  context
9526
9572
  )];
9527
9573
  entities.forEach((entity) => {
9528
- destination.placeEntity(entity, rule.position);
9574
+ destination.placeEntity(entity, r2.position);
9529
9575
  });
9530
9576
  }
9531
9577
  };
9532
9578
 
9533
- // src/game-factory/move/take-from.js
9579
+ // src/game-factory/move/take-from.ts
9534
9580
  var TakeFrom = class extends Move {
9535
- do(bgioArguments, rule, { arguments: { source, destination } }) {
9536
- destination.placeEntity(source.takeOne(rule.arguments.source.position));
9581
+ do(_bgioArguments, rule, resolvedPayload) {
9582
+ const { source, destination } = resolvedPayload.arguments;
9583
+ destination.placeEntity(
9584
+ source.takeOne(
9585
+ rule.arguments.source.position
9586
+ )
9587
+ );
9537
9588
  }
9538
9589
  };
9539
9590
 
9540
- // src/game-factory/move/set-state.js
9591
+ // src/game-factory/move/set-state.ts
9541
9592
  var SetState = class extends Move {
9542
- do(_2, __, { arguments: { entity, state } }) {
9593
+ do(_unused, _rule, resolvedPayload) {
9594
+ const { entity, state } = resolvedPayload.arguments;
9543
9595
  entity.state = {
9544
9596
  ...entity.state,
9545
9597
  [state.property]: state.value
@@ -9547,7 +9599,7 @@ var SetState = class extends Move {
9547
9599
  }
9548
9600
  };
9549
9601
 
9550
- // src/utils/do-moves.js
9602
+ // src/utils/do-moves.ts
9551
9603
  function doMoves(bgioArguments, moves = [], context) {
9552
9604
  if (!moves?.length) {
9553
9605
  return bgioArguments.G;
@@ -9562,11 +9614,12 @@ function doMoves(bgioArguments, moves = [], context) {
9562
9614
  return bgioArguments.G;
9563
9615
  }
9564
9616
 
9565
- // src/game-factory/move/set-active-players.js
9617
+ // src/game-factory/move/set-active-players.ts
9566
9618
  var SetActivePlayers = class extends Move {
9567
- do(bgioArguments, rule, _2, context) {
9568
- bgioArguments.events.setActivePlayers(rule.options);
9569
- const phaseName = bgioArguments.ctx.phase;
9619
+ do(bgioArguments, rule, _unused, context) {
9620
+ const b2 = bgioArguments;
9621
+ b2.events.setActivePlayers(rule.options);
9622
+ const phaseName = b2.ctx.phase;
9570
9623
  const stageName = rule.options.currentPlayer?.stage;
9571
9624
  const phaseOrRoot = context.game.phases?.[phaseName] ?? context.game;
9572
9625
  const stage = phaseOrRoot?.turn?.stages?.[stageName];
@@ -9581,26 +9634,28 @@ var SetActivePlayers = class extends Move {
9581
9634
  }
9582
9635
  };
9583
9636
 
9584
- // src/game-factory/move/end-turn.js
9637
+ // src/game-factory/move/end-turn.ts
9585
9638
  var EndTurn = class extends Move {
9586
9639
  do(bgioArguments) {
9587
9640
  bgioArguments.events.endTurn();
9588
9641
  }
9589
9642
  };
9590
9643
 
9591
- // src/game-factory/move/pass-turn.js
9644
+ // src/game-factory/move/pass-turn.ts
9592
9645
  var PassTurn = class extends Move {
9593
9646
  do(bgioArguments) {
9594
- if (bgioArguments.G._meta.passedPlayers.length < bgioArguments.ctx.numPlayers) {
9595
- bgioArguments.G._meta.passedPlayers.push(bgioArguments.ctx.currentPlayer);
9596
- bgioArguments.events.pass();
9647
+ const a2 = bgioArguments;
9648
+ if (a2.G._meta.passedPlayers.length < a2.ctx.numPlayers) {
9649
+ a2.G._meta.passedPlayers.push(a2.ctx.currentPlayer);
9650
+ a2.events.pass();
9597
9651
  }
9598
9652
  }
9599
9653
  };
9600
9654
 
9601
- // src/game-factory/move/for-each.js
9655
+ // src/game-factory/move/for-each.ts
9602
9656
  var ForEach = class extends Move {
9603
- do(bgioArguments, rule, { arguments: { targets } }, context) {
9657
+ do(bgioArguments, rule, resolvedPayload, context) {
9658
+ const { targets } = resolvedPayload.arguments;
9604
9659
  targets.forEach((target) => {
9605
9660
  const loopContext = {
9606
9661
  ...context,
@@ -9615,23 +9670,28 @@ var ForEach = class extends Move {
9615
9670
  }
9616
9671
  };
9617
9672
 
9618
- // src/game-factory/move/pass.js
9673
+ // src/game-factory/move/pass.ts
9619
9674
  var Pass = class extends Move {
9620
9675
  do(bgioArguments) {
9621
9676
  bgioArguments.events.endTurn();
9622
9677
  }
9623
9678
  };
9624
9679
 
9625
- // src/game-factory/move/shuffle.js
9680
+ // src/game-factory/move/shuffle.ts
9626
9681
  var Shuffle = class extends Move {
9627
- do(bgioArguments, _2, { arguments: { target } }) {
9628
- target.entities = bgioArguments.random.Shuffle(target.entities);
9682
+ do(bgioArguments, _rule, resolvedPayload) {
9683
+ const { target } = resolvedPayload.arguments;
9684
+ const b2 = bgioArguments;
9685
+ target.entities = b2.random.Shuffle(target.entities);
9629
9686
  }
9630
9687
  };
9631
9688
 
9632
- // src/game-factory/move/move-factory.js
9689
+ // src/game-factory/move/move-factory.ts
9633
9690
  function moveFactory(moveRule, game) {
9634
9691
  const moveInstance = getMoveInstance(moveRule);
9692
+ if (!moveInstance) {
9693
+ throw new Error("moveFactory: unknown moveType");
9694
+ }
9635
9695
  const compatibleMove = function(bgioArguments, serializablePayload) {
9636
9696
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
9637
9697
  const { G: G2 } = newBgioArguments;
@@ -9640,8 +9700,10 @@ function moveFactory(moveRule, game) {
9640
9700
  const moveConditionResults = moveInstance.doMove(newBgioArguments, payload, context);
9641
9701
  context.moveConditionResults = [moveConditionResults];
9642
9702
  if (moveConditionResults !== import_core2.INVALID_MOVE && moveRule.then) {
9643
- for (let automaticMoveRule of moveRule.then) {
9644
- const result = getMoveInstance(automaticMoveRule).doMove(
9703
+ for (const automaticMoveRule of moveRule.then) {
9704
+ const auto = getMoveInstance(automaticMoveRule);
9705
+ if (!auto) continue;
9706
+ const result = auto.doMove(
9645
9707
  newBgioArguments,
9646
9708
  {},
9647
9709
  { ...context }
@@ -9656,16 +9718,15 @@ function moveFactory(moveRule, game) {
9656
9718
  return compatibleMove;
9657
9719
  }
9658
9720
  function revivePayload(serializablePayload, G2) {
9659
- if (serializablePayload) {
9660
- const payload = deserialize(JSON.stringify(serializablePayload), registry);
9661
- payload.arguments = Object.entries(payload.arguments).reduce((acc, [key, argOrEntityId]) => ({
9662
- ...acc,
9663
- [key]: typeof argOrEntityId === "number" ? G2.bank.locate(argOrEntityId) : argOrEntityId
9664
- }), {});
9665
- return payload;
9666
- } else {
9667
- return serializablePayload;
9721
+ if (!serializablePayload) {
9722
+ return void 0;
9668
9723
  }
9724
+ const payload = deserialize(JSON.stringify(serializablePayload), registry);
9725
+ payload.arguments = Object.entries(payload.arguments).reduce((acc, [key, argOrEntityId]) => ({
9726
+ ...acc,
9727
+ [key]: typeof argOrEntityId === "number" ? G2.bank.locate(argOrEntityId) : argOrEntityId
9728
+ }), {});
9729
+ return payload;
9669
9730
  }
9670
9731
  function getMoveInstance(moveRule) {
9671
9732
  switch (moveRule.moveType) {
@@ -9694,13 +9755,12 @@ function getMoveInstance(moveRule) {
9694
9755
  }
9695
9756
  }
9696
9757
 
9697
- // src/game-factory/expand-game-rules.js
9698
- var import_cloneDeep = __toESM(require_cloneDeep());
9758
+ // src/game-factory/expand-game-rules.ts
9699
9759
  var import_find2 = __toESM(require_find());
9700
9760
 
9701
- // src/utils/json-transformer.js
9761
+ // src/utils/json-transformer.ts
9702
9762
  function transformJSON(data, rules) {
9703
- return JSON.parse(JSON.stringify(data), (key, value2) => {
9763
+ return JSON.parse(JSON.stringify(data), (_key, value2) => {
9704
9764
  let result = value2;
9705
9765
  for (const rule of rules) {
9706
9766
  if (rule.test(result)) {
@@ -9711,7 +9771,7 @@ function transformJSON(data, rules) {
9711
9771
  });
9712
9772
  }
9713
9773
 
9714
- // src/game-factory/expand-game-rules.js
9774
+ // src/game-factory/expand-game-rules.ts
9715
9775
  var invariantEntities = [
9716
9776
  {
9717
9777
  entityType: "Space",
@@ -9735,7 +9795,8 @@ function expandEntities(rules) {
9735
9795
  }
9736
9796
  function expandInitialPlacements(rules, entities) {
9737
9797
  if (rules.sharedBoard) {
9738
- const sharedBoardPlacements = rules.sharedBoard.map((matcher) => ({ entity: matcher, destination: { name: "sharedBoard" } }));
9798
+ const sharedBoard = rules.sharedBoard;
9799
+ const sharedBoardPlacements = sharedBoard.map((matcher) => ({ entity: matcher, destination: { name: "sharedBoard" } }));
9739
9800
  if (!rules.initialPlacements) rules.initialPlacements = [];
9740
9801
  rules.initialPlacements.unshift(...sharedBoardPlacements);
9741
9802
  }
@@ -9745,7 +9806,8 @@ function expandInitialPlacements(rules, entities) {
9745
9806
  name: "personalBoard",
9746
9807
  perPlayer: true
9747
9808
  });
9748
- const personalBoardPlacements = rules.personalBoard.map((matcher) => ({
9809
+ const personalBoard = rules.personalBoard;
9810
+ const personalBoardPlacements = personalBoard.map((matcher) => ({
9749
9811
  entity: matcher,
9750
9812
  destination: {
9751
9813
  name: "personalBoard"
@@ -9775,7 +9837,7 @@ function expandInitialPlacements(rules, entities) {
9775
9837
  conditionType: "Is",
9776
9838
  matcher: {
9777
9839
  ...matcher,
9778
- ...entityDefinition.perPlayer ? {
9840
+ ...entityDefinition?.perPlayer ? {
9779
9841
  player: {
9780
9842
  type: "contextPath",
9781
9843
  path: ["loopTarget"]
@@ -9849,21 +9911,21 @@ var simpleReplacements = [
9849
9911
  ],
9850
9912
  [
9851
9913
  "ownerOfFirstResultEntity",
9852
- // might have to more tightly couple this to HasLine condition
9853
9914
  {
9854
- "type": "contextPath",
9855
- "path": ["results", 0, "matches", 0, 0, "entities", 0, "attributes", "player"]
9915
+ type: "contextPath",
9916
+ path: ["results", 0, "matches", 0, 0, "entities", 0, "attributes", "player"]
9856
9917
  }
9857
9918
  ]
9858
9919
  ];
9859
9920
  var transformationRules = [
9860
9921
  {
9861
- test: (val) => val && typeof val === "object",
9922
+ test: (val) => Boolean(val && typeof val === "object"),
9862
9923
  replace: (val) => {
9924
+ const obj = val;
9863
9925
  keyMappings.forEach(([oldKey, newKey]) => {
9864
- if (val.hasOwnProperty(oldKey)) {
9865
- val[newKey] = val[oldKey];
9866
- delete val[oldKey];
9926
+ if (Object.prototype.hasOwnProperty.call(obj, oldKey)) {
9927
+ obj[newKey] = obj[oldKey];
9928
+ delete obj[oldKey];
9867
9929
  }
9868
9930
  });
9869
9931
  return val;
@@ -9881,22 +9943,24 @@ var transformationRules = [
9881
9943
  }
9882
9944
  },
9883
9945
  {
9884
- test: (val) => val?.conditions,
9946
+ test: (val) => Boolean(val && typeof val === "object" && val.conditions),
9885
9947
  replace: (val) => {
9886
- if (!Array.isArray(val.conditions)) {
9887
- val.conditions = [val.conditions];
9948
+ const v2 = val;
9949
+ if (!Array.isArray(v2.conditions)) {
9950
+ v2.conditions = [v2.conditions];
9888
9951
  }
9889
9952
  return val;
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
- for (let i2 = 0, len = val.conditions.length; i2 < len; i2++) {
9896
- if (!val.conditions[i2].conditionType) {
9897
- val.conditions[i2] = {
9958
+ const v2 = val;
9959
+ for (let i2 = 0, len = v2.conditions.length; i2 < len; i2++) {
9960
+ if (!v2.conditions[i2].conditionType) {
9961
+ v2.conditions[i2] = {
9898
9962
  conditionType: "Is",
9899
- matcher: val.conditions[i2]
9963
+ matcher: v2.conditions[i2]
9900
9964
  };
9901
9965
  }
9902
9966
  }
@@ -9904,18 +9968,21 @@ var transformationRules = [
9904
9968
  }
9905
9969
  },
9906
9970
  {
9907
- test: (val) => typeof val?.target === "string",
9908
- replace: (val) => ({
9909
- ...val,
9910
- target: {
9911
- conditions: [{
9912
- conditionType: "Is",
9913
- matcher: {
9914
- name: val.target
9915
- }
9916
- }]
9917
- }
9918
- })
9971
+ test: (val) => Boolean(val && typeof val === "object" && typeof val.target === "string"),
9972
+ replace: (val) => {
9973
+ const v2 = val;
9974
+ return {
9975
+ ...v2,
9976
+ target: {
9977
+ conditions: [{
9978
+ conditionType: "Is",
9979
+ matcher: {
9980
+ name: v2.target
9981
+ }
9982
+ }]
9983
+ }
9984
+ };
9985
+ }
9919
9986
  }
9920
9987
  ];
9921
9988
  function expandGameRules(gameRules) {
@@ -9942,11 +10009,14 @@ function expandGameRules(gameRules) {
9942
10009
  return rules;
9943
10010
  }
9944
10011
 
9945
- // src/utils/get-scenario-results.js
9946
- function getScenarioResults(bgioArguments, scenarios, context) {
10012
+ // src/utils/get-scenario-results.ts
10013
+ function getScenarioResults(bgioArguments, scenarios) {
9947
10014
  let match;
9948
10015
  for (const scenario of scenarios) {
9949
- const conditionResults = checkConditions(bgioArguments, scenario);
10016
+ const conditionResults = checkConditions(
10017
+ bgioArguments,
10018
+ scenario.conditions
10019
+ );
9950
10020
  if (conditionResults.conditionsAreMet) {
9951
10021
  match = { scenario, conditionResults };
9952
10022
  break;
@@ -9963,7 +10033,7 @@ function getScenarioResults(bgioArguments, scenarios, context) {
9963
10033
  }
9964
10034
  }
9965
10035
 
9966
- // src/game-factory/game-factory.js
10036
+ // src/game-factory/game-factory.ts
9967
10037
  function gameFactory(gameRules, gameName) {
9968
10038
  const game = { name: gameName };
9969
10039
  const rules = expandGameRules(gameRules);
@@ -9976,19 +10046,21 @@ function gameFactory(gameRules, gameName) {
9976
10046
  }
9977
10047
  };
9978
10048
  const entityDefinitions = expandEntityDefinitions(rules.entities, ctx);
9979
- initialState.bank = new bank_default(entityDefinitions);
9980
- initialState.sharedBoard = initialState.bank.getOne(
10049
+ const bank = new bank_default(entityDefinitions);
10050
+ initialState.bank = bank;
10051
+ initialState.sharedBoard = bank.getOne(
9981
10052
  bgioArguments,
9982
10053
  {
9983
10054
  conditions: [{
9984
10055
  conditionType: "Is",
9985
10056
  matcher: { name: "sharedBoard" }
9986
10057
  }]
9987
- }
10058
+ },
10059
+ {}
9988
10060
  );
9989
10061
  if (rules.personalBoard) {
9990
10062
  initialState.personalBoards = bgioArguments.ctx.playOrder.map(
9991
- (playerID) => initialState.bank.getOne(
10063
+ (playerID) => bank.getOne(
9992
10064
  bgioArguments,
9993
10065
  {
9994
10066
  conditions: [{
@@ -9998,13 +10070,16 @@ function gameFactory(gameRules, gameName) {
9998
10070
  player: playerID
9999
10071
  }
10000
10072
  }]
10001
- }
10073
+ },
10074
+ {}
10002
10075
  )
10003
10076
  );
10004
10077
  }
10005
10078
  rules.initialMoves?.forEach((moveRule) => {
10006
10079
  moveFactory(moveRule, game).moveInstance.doMove(
10007
- { ...bgioArguments, G: initialState }
10080
+ { ...bgioArguments, G: initialState },
10081
+ void 0,
10082
+ {}
10008
10083
  );
10009
10084
  });
10010
10085
  return JSON.parse(serialize(initialState));
@@ -10022,16 +10097,18 @@ function gameFactory(gameRules, gameName) {
10022
10097
  }), {});
10023
10098
  }
10024
10099
  if (rules.endIf) {
10100
+ const endIfRules = rules.endIf;
10025
10101
  game.endIf = (bgioArguments) => {
10026
10102
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
10027
- return getScenarioResults(newBgioArguments, rules.endIf);
10103
+ return getScenarioResults(newBgioArguments, endIfRules);
10028
10104
  };
10029
10105
  }
10030
10106
  if (!gameRules.DEBUG_DISABLE_SECRET_STATE) {
10031
10107
  game.playerView = (bgioArguments) => {
10032
10108
  const { G: G2, playerID } = deserializeBgioArguments(bgioArguments);
10033
- Object.values(G2.bank.tracker).forEach((entity) => {
10034
- if (entity.rule.contentsHiddenFrom === "All" || entity.rule.contentsHiddenFrom === "Others" && (playerID !== entity.rule.player || playerID == void 0)) {
10109
+ const tracker = G2.bank.tracker;
10110
+ Object.values(tracker).forEach((entity) => {
10111
+ if (entity.rule.contentsHiddenFrom === "All" || entity.rule.contentsHiddenFrom === "Others" && (playerID !== entity.rule.player || playerID === void 0)) {
10035
10112
  if (entity.spaces) {
10036
10113
  entity.spaces = entity.rule.hideLength ? [] : entity.spaces.map(() => G2.bank.createEntity());
10037
10114
  }
@@ -10051,12 +10128,12 @@ function expandEntityDefinitions(entities, ctx) {
10051
10128
  if (entityCopy.perPlayer) {
10052
10129
  delete entityCopy.perPlayer;
10053
10130
  if (entityCopy.variants) {
10054
- entityCopy.variants = new Array(ctx.numPlayers).fill().reduce((accu, _2, i2) => [
10131
+ entityCopy.variants = new Array(ctx.numPlayers).fill(void 0).reduce((accu, _2, i2) => [
10055
10132
  ...accu,
10056
10133
  ...entityCopy.variants.map((variant) => ({ ...variant, player: `${i2}` }))
10057
10134
  ], []);
10058
10135
  } else {
10059
- entityCopy.variants = new Array(ctx.numPlayers).fill().map((_2, i2) => ({ player: `${i2}` }));
10136
+ entityCopy.variants = new Array(ctx.numPlayers).fill(void 0).map((_2, i2) => ({ player: `${i2}` }));
10060
10137
  }
10061
10138
  }
10062
10139
  if (entityCopy.variants) {
@@ -10094,9 +10171,10 @@ function createTurn(turnRule, game) {
10094
10171
  }
10095
10172
  });
10096
10173
  }
10097
- if (turnRule.order?.playOrder === "RotateFirst") {
10098
- turnRule.order.first = () => 0;
10099
- turnRule.order.next = ({ ctx }) => (ctx.playOrderPos + 1) % ctx.numPlayers;
10174
+ const order = turnRule.order;
10175
+ if (order?.playOrder === "RotateFirst") {
10176
+ order.first = () => 0;
10177
+ order.next = ({ ctx }) => (ctx.playOrderPos + 1) % ctx.numPlayers;
10100
10178
  turn.order.playOrder = ({ ctx, G: G2 }) => {
10101
10179
  return G2._meta.isAfterFirstPhase ? [...ctx.playOrder.slice(1), ctx.playOrder[0]] : ctx.playOrder;
10102
10180
  };
@@ -10119,10 +10197,11 @@ function createPhase(phaseRule, game) {
10119
10197
  return JSON.parse(serialize(newBgioArguments.G));
10120
10198
  };
10121
10199
  if (phaseRule.endIf) {
10200
+ const phaseEndIf = phaseRule.endIf;
10122
10201
  phase.endIf = (bgioArguments) => {
10123
10202
  const newBgioArguments = deserializeBgioArguments(bgioArguments);
10124
10203
  if (newBgioArguments.G._meta.currentPhaseHasBeenSetUp) {
10125
- const result = getScenarioResults(newBgioArguments, phaseRule.endIf);
10204
+ const result = getScenarioResults(newBgioArguments, phaseEndIf);
10126
10205
  if (result) {
10127
10206
  return result;
10128
10207
  }
@@ -27006,21 +27085,24 @@ function SocketIO({ server, socketOpts } = {}) {
27006
27085
  var import_lodash4 = __toESM(require_lodash());
27007
27086
  var import_rfc69024 = __toESM(require_rfc6902());
27008
27087
 
27009
- // src/utils/prepare-payload.js
27088
+ // src/utils/prepare-payload.ts
27010
27089
  function preparePayload(payload) {
27011
- if (payload?.arguments) {
27012
- const payloadCopy = { ...payload };
27013
- payloadCopy.arguments = Object.entries(payloadCopy.arguments).reduce((acc, [key, argument]) => ({
27014
- ...acc,
27015
- [key]: argument.abstract ? argument : argument.entityId
27016
- }), {});
27090
+ const p2 = payload;
27091
+ if (p2?.arguments) {
27092
+ const payloadCopy = {
27093
+ ...p2,
27094
+ arguments: Object.entries(p2.arguments).reduce((acc, [key, argument]) => ({
27095
+ ...acc,
27096
+ [key]: argument.abstract ? argument : argument.entityId
27097
+ }), {})
27098
+ };
27017
27099
  return JSON.parse(serialize(payloadCopy, { deduplicateInstances: false }));
27018
27100
  } else {
27019
27101
  return payload;
27020
27102
  }
27021
27103
  }
27022
27104
 
27023
- // src/utils/get-steps.js
27105
+ // src/utils/get-steps.ts
27024
27106
  var argNamesMap = {
27025
27107
  PlaceNew: ["destination"],
27026
27108
  RemoveEntity: ["entity"],
@@ -27029,13 +27111,15 @@ var argNamesMap = {
27029
27111
  SetState: ["entity", "state"]
27030
27112
  };
27031
27113
  function getSteps(bgioState, moveRule) {
27032
- return argNamesMap[moveRule.moveType].filter((argName) => moveRule.arguments[argName].playerChoice).map((argName) => ({
27114
+ const names = argNamesMap[moveRule.moveType];
27115
+ if (!names) return [];
27116
+ return names.filter((argName) => moveRule.arguments[argName]?.playerChoice).map((argName) => ({
27033
27117
  argName,
27034
27118
  getClickable: argName === "state" ? () => moveRule.arguments[argName].possibleValues.map((value2) => ({
27035
27119
  abstract: true,
27036
27120
  ...moveRule.arguments[argName],
27037
27121
  value: value2
27038
- })) : (context) => bgioState.G.bank.findAll(
27122
+ })) : (context) => bankOf(bgioState).findAll(
27039
27123
  bgioState,
27040
27124
  moveRule.arguments[argName],
27041
27125
  context
@@ -27043,12 +27127,11 @@ function getSteps(bgioState, moveRule) {
27043
27127
  }));
27044
27128
  }
27045
27129
 
27046
- // src/utils/create-payload.js
27047
- function createPayload(bgioState, moveRule, targets, context) {
27130
+ // src/utils/create-payload.ts
27131
+ function createPayload(bgioState, moveRule, targets, _context) {
27048
27132
  const argNames = getSteps(
27049
27133
  bgioState,
27050
- moveRule,
27051
- context
27134
+ moveRule
27052
27135
  ).map((s2) => s2.argName);
27053
27136
  return {
27054
27137
  arguments: targets.reduce((acc, target, i2) => ({
@@ -27058,11 +27141,11 @@ function createPayload(bgioState, moveRule, targets, context) {
27058
27141
  };
27059
27142
  }
27060
27143
 
27061
- // src/client/client.js
27144
+ // src/client/client.ts
27062
27145
  var Client2 = class {
27063
27146
  constructor(options) {
27064
27147
  this.options = options;
27065
- this.game = options.boardgameIOGame || gameFactory(JSON.parse(options.gameRules), options.gameName);
27148
+ this.game = options.boardgameIOGame || gameFactory(options.gameRules, options.gameName ?? "");
27066
27149
  if (!options.boardgameIOGame) {
27067
27150
  this.moveBuilder = { targets: [], stepIndex: 0, eliminatedMoves: [] };
27068
27151
  this.optimisticWinner = null;
@@ -27086,7 +27169,7 @@ var Client2 = class {
27086
27169
  game: this.game,
27087
27170
  multiplayer,
27088
27171
  matchID,
27089
- playerID,
27172
+ playerID: playerID ?? void 0,
27090
27173
  credentials,
27091
27174
  numPlayers,
27092
27175
  debug
@@ -27096,8 +27179,9 @@ var Client2 = class {
27096
27179
  this.client.start();
27097
27180
  return this;
27098
27181
  } catch (error2) {
27099
- console.error("Failed to join game:", error2?.message ?? error2);
27100
- if (error2?.stack) console.error(error2.stack);
27182
+ const err = error2;
27183
+ console.error("Failed to join game:", err?.message ?? error2);
27184
+ if (err?.stack) console.error(err.stack);
27101
27185
  }
27102
27186
  }
27103
27187
  update() {
@@ -27140,7 +27224,12 @@ var Client2 = class {
27140
27224
  return;
27141
27225
  }
27142
27226
  const remainingMoveEntries = Object.entries(_possibleMoveMeta).filter(([name]) => !newEliminated.includes(name));
27143
- if (isMoveCompleted(state, _wrappedMoves, remainingMoveEntries, this.moveBuilder.stepIndex)) {
27227
+ if (isMoveCompleted(
27228
+ state,
27229
+ _wrappedMoves,
27230
+ remainingMoveEntries,
27231
+ this.moveBuilder.stepIndex
27232
+ )) {
27144
27233
  const [moveName] = remainingMoveEntries[0];
27145
27234
  const move = _wrappedMoves[moveName];
27146
27235
  const payload = createPayload(
@@ -27188,7 +27277,10 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27188
27277
  const _possibleMoveMeta = {};
27189
27278
  const allClickable = /* @__PURE__ */ new Set();
27190
27279
  Object.entries(moves).filter(([moveName]) => !eliminatedMoves.includes(moveName)).forEach(([moveName, move]) => {
27191
- const moveRule = resolveProperties(bgioState, { ...move.moveInstance.rule, moveName });
27280
+ const moveRule = resolveProperties(bgioState, {
27281
+ ...move.moveInstance.rule,
27282
+ moveName
27283
+ });
27192
27284
  const context = {
27193
27285
  moveInstance: move.moveInstance,
27194
27286
  moveArguments: moveRule.arguments
@@ -27196,10 +27288,23 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27196
27288
  const targets = moveBuilder.targets.map(
27197
27289
  (t2) => t2.abstract ? t2 : bgioState.G.bank.locate(t2.entityId)
27198
27290
  );
27199
- const payload = createPayload(bgioState, moveRule, targets, context);
27291
+ const payload = createPayload(
27292
+ bgioState,
27293
+ moveRule,
27294
+ targets,
27295
+ context
27296
+ );
27200
27297
  context.moveArguments = { ...context.moveArguments, ...payload.arguments };
27201
- const moveIsAllowed = checkConditions(bgioState, moveRule, {}, context).conditionsAreMet;
27202
- const moveSteps = getSteps(bgioState, moveRule);
27298
+ const moveIsAllowed = checkConditions(
27299
+ bgioState,
27300
+ moveRule.conditions,
27301
+ {},
27302
+ context
27303
+ ).conditionsAreMet;
27304
+ const moveSteps = getSteps(
27305
+ bgioState,
27306
+ moveRule
27307
+ );
27203
27308
  const clickableForMove = new Set(
27204
27309
  moveIsAllowed && moveSteps?.[stepIndex]?.getClickable(context) || []
27205
27310
  );
@@ -27209,11 +27314,19 @@ function getPossibleMoves(bgioState, moves, moveBuilder) {
27209
27314
  return { _possibleMoveMeta, allClickable };
27210
27315
  }
27211
27316
  function isMoveCompleted(state, moves, remainingMoveEntries, stepIndex) {
27212
- return remainingMoveEntries.length === 1 && getSteps(state, moves[remainingMoveEntries[0][0]].moveInstance.rule).length === stepIndex + 1;
27317
+ return remainingMoveEntries.length === 1 && getSteps(
27318
+ state,
27319
+ moves[remainingMoveEntries[0][0]].moveInstance.rule
27320
+ ).length === stepIndex + 1;
27213
27321
  }
27214
27322
  function getWinnerAfterMove(state, game, moveInstance, movePayload) {
27215
- const simulatedG = simulateMove(state, preparePayload(movePayload), { moveInstance });
27216
- return game.endIf?.({ ...state, G: JSON.parse(serialize(simulatedG)) });
27323
+ const simulatedG = simulateMove(
27324
+ state,
27325
+ preparePayload(movePayload),
27326
+ { moveInstance }
27327
+ );
27328
+ const endIf = game.endIf;
27329
+ return endIf?.({ ...state, G: JSON.parse(serialize(simulatedG)) });
27217
27330
  }
27218
27331
  export {
27219
27332
  Client2 as Client,