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
@@ -0,0 +1,449 @@
1
+ /**
2
+ * B.A.G.E.L. (Board-based Automated Game Engine Language) types.
3
+ * Subset inferred from the built-in example games.
4
+ *
5
+ * Semantic notes:
6
+ * - EntityAttributes<TRule> = entity rule merged with its default state (runtime view).
7
+ * - displayProperties lists keys of that merged type; UI shows those attribute values.
8
+ * - EntityMatcher is matched against EntityAttributes (lodash-style) at runtime.
9
+ */
10
+
11
+ // ---------------------------------------------------------------------------
12
+ // Value references (resolved at runtime from context, game state, or expressions)
13
+ // ---------------------------------------------------------------------------
14
+
15
+ export type PathSegment = string | number | { flatten: boolean; map?: string[] };
16
+
17
+ export type ValueRef =
18
+ | CtxPathRef
19
+ | ContextPathRef
20
+ | GamePathRef
21
+ | ExpressionRef
22
+ | RelativeCoordinatesRef
23
+ | CoordinatesRef
24
+ | RelativePathRef
25
+ | ParentRef
26
+ | MapRef
27
+ | MapMaxRef
28
+ | PickRef
29
+ | CountRef;
30
+
31
+ export interface CtxPathRef {
32
+ type: "ctxPath";
33
+ path: (string | number)[];
34
+ }
35
+
36
+ export interface ContextPathRef {
37
+ type: "contextPath";
38
+ path: PathSegment[];
39
+ }
40
+
41
+ export interface GamePathRef {
42
+ type: "gamePath";
43
+ path: (string | number)[];
44
+ }
45
+
46
+ export interface ExpressionRef {
47
+ type: "expression";
48
+ expression: string;
49
+ arguments: Record<string, ValueRef>;
50
+ }
51
+
52
+ export interface RelativeCoordinatesRef {
53
+ type: "relativeCoordinates";
54
+ target?: ValueRef;
55
+ location: [number, number] | ValueRef;
56
+ }
57
+
58
+ export interface CoordinatesRef {
59
+ type: "coordinates";
60
+ target?: ValueRef;
61
+ }
62
+
63
+ export interface RelativePathRef {
64
+ type: "relativePath";
65
+ target: ValueRef | TargetSelector;
66
+ path: (string | number)[];
67
+ }
68
+
69
+ export interface ParentRef {
70
+ type: "parent";
71
+ target?: ValueRef;
72
+ }
73
+
74
+ export interface MapRef {
75
+ type: "map";
76
+ targets: ValueRef | TargetSelector;
77
+ mapping: ValueRef | CountRef;
78
+ }
79
+
80
+ export interface MapMaxRef {
81
+ type: "mapMax";
82
+ targets: ValueRef;
83
+ mapping: ValueRef | CountRef;
84
+ }
85
+
86
+ export interface PickRef {
87
+ type: "pick";
88
+ target: ValueRef | TargetSelector;
89
+ properties: string[];
90
+ }
91
+
92
+ export interface CountRef {
93
+ type: "count";
94
+ conditions: Condition[];
95
+ }
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // Conditions (recursive; matched against entity rule merged with state)
99
+ // ---------------------------------------------------------------------------
100
+
101
+ export type Condition =
102
+ | ConditionShorthandString
103
+ | ConditionShorthandEntityType
104
+ | ConditionTyped;
105
+
106
+ export type ConditionShorthandString = "isEmpty" | "isCurrentPlayer";
107
+
108
+ export interface ConditionShorthandEntityType {
109
+ entityType: "Space";
110
+ }
111
+
112
+ export type ConditionTyped =
113
+ | ConditionHasLine
114
+ | ConditionIsFull
115
+ | ConditionNoPossibleMoves
116
+ | ConditionPosition
117
+ | ConditionContainsSame
118
+ | ConditionIs
119
+ | ConditionContains
120
+ | ConditionNot
121
+ | ConditionOr
122
+ | ConditionSome
123
+ | ConditionEvery
124
+ | ConditionInLine
125
+ | ConditionEvaluate;
126
+
127
+ export interface TargetSelector {
128
+ matchMultiple?: boolean;
129
+ conditions: Condition[];
130
+ }
131
+
132
+ export interface LineSequenceStep {
133
+ minCount?: number;
134
+ conditions: Condition[];
135
+ }
136
+
137
+ export interface ConditionHasLine {
138
+ conditionType: "HasLine";
139
+ target: string;
140
+ sequence: LineSequenceStep[];
141
+ }
142
+
143
+ export interface ConditionIsFull {
144
+ conditionType: "IsFull";
145
+ target: string;
146
+ }
147
+
148
+ export interface ConditionNoPossibleMoves {
149
+ conditionType: "NoPossibleMoves";
150
+ }
151
+
152
+ export interface ConditionPosition {
153
+ conditionType: "Position";
154
+ position: "First";
155
+ }
156
+
157
+ export interface ConditionContainsSame {
158
+ conditionType: "ContainsSame";
159
+ properties: string[];
160
+ }
161
+
162
+ export interface ConditionIs {
163
+ conditionType: "Is";
164
+ target?: ValueRef | TargetSelector | string;
165
+ matcher?: Record<string, unknown>;
166
+ entity?: ValueRef;
167
+ }
168
+
169
+ export interface ConditionContains {
170
+ conditionType: "Contains";
171
+ target?: ValueRef | TargetSelector | string;
172
+ conditions?: Condition[];
173
+ }
174
+
175
+ export interface ConditionNot {
176
+ conditionType: "Not";
177
+ target?: ValueRef | TargetSelector | string;
178
+ conditions: Condition[];
179
+ }
180
+
181
+ export interface ConditionOr {
182
+ conditionType: "Or";
183
+ conditions: Condition[];
184
+ }
185
+
186
+ export interface ConditionSome {
187
+ conditionType: "Some";
188
+ target: TargetSelector;
189
+ conditions: Condition[];
190
+ }
191
+
192
+ export interface ConditionEvery {
193
+ conditionType: "Every";
194
+ target: TargetSelector;
195
+ conditions: Condition[];
196
+ }
197
+
198
+ export interface ConditionInLine {
199
+ conditionType: "InLine";
200
+ target?: ValueRef;
201
+ sequence: LineSequenceStep[];
202
+ }
203
+
204
+ export interface ConditionEvaluate {
205
+ conditionType: "Evaluate";
206
+ expression: string;
207
+ arguments: Record<string, ValueRef>;
208
+ }
209
+
210
+ // ---------------------------------------------------------------------------
211
+ // Entities: rule + state merged = runtime attributes
212
+ // ---------------------------------------------------------------------------
213
+
214
+ /** Runtime view: entity rule merged with its default state. Used for display and matching. */
215
+ export type EntityAttributes<TRule extends EntityRule> = TRule &
216
+ (TRule extends { state?: infer S } ? (S extends object ? S : object) : object);
217
+
218
+ /** Keys that can appear on any entity's merged attributes (for matchers over unknown entity type). */
219
+ export type EntityAttributeKey =
220
+ | keyof EntityAttributes<EntityGrid>
221
+ | keyof EntityAttributes<EntitySpace>
222
+ | keyof EntityAttributes<EntityGeneric>
223
+ | keyof EntityAttributes<EntityBoard>;
224
+
225
+ /** Matcher compared against EntityAttributes at runtime. Keys are attribute keys; values may be refs. */
226
+ export type EntityMatcher<A extends object = Record<EntityAttributeKey, unknown>> = Partial<
227
+ { [K in keyof A]: A[K] | ValueRef }
228
+ > & { name?: string };
229
+
230
+ export interface EntityBoard extends EntityCommon {
231
+ entityType: "Board";
232
+ }
233
+
234
+ export type Entity = EntityGrid | EntitySpace | EntityGeneric | EntityBoard;
235
+
236
+ export interface EntityCommon {
237
+ name: string;
238
+ perPlayer?: boolean;
239
+ count?: number | "Infinity";
240
+ state?: Record<string, unknown>;
241
+ contentsHiddenFrom?: "All" | "Others";
242
+ /** Expanded into separate entity definitions at setup (see game-factory). */
243
+ variants?: Array<Record<string, unknown>>;
244
+ }
245
+
246
+ export interface EntityGrid extends EntityCommon {
247
+ entityType: "Grid";
248
+ width: number;
249
+ height: number;
250
+ /** Property names to show in UI; values read from EntityAttributes<EntityGrid>. */
251
+ displayProperties?: (keyof EntityAttributes<EntityGrid>)[];
252
+ }
253
+
254
+ export interface EntitySpace extends EntityCommon {
255
+ entityType: "Space";
256
+ /** Property names to show in UI; values read from EntityAttributes<EntitySpace>. */
257
+ displayProperties?: (keyof EntityAttributes<EntitySpace>)[];
258
+ }
259
+
260
+ export interface EntityGeneric extends EntityCommon {
261
+ entityType?: undefined;
262
+ /** Property names to show in UI; values read from EntityAttributes<EntityGeneric> (rule merged with state). */
263
+ displayProperties?: (keyof EntityAttributes<EntityGeneric>)[];
264
+ }
265
+
266
+ export type EntityRule = EntityGrid | EntitySpace | EntityGeneric | EntityBoard;
267
+
268
+ // ---------------------------------------------------------------------------
269
+ // Moves
270
+ // ---------------------------------------------------------------------------
271
+
272
+ export type MoveDefinition =
273
+ | MovePlaceNew
274
+ | MoveMoveEntity
275
+ | MoveRemoveEntity
276
+ | MoveTakeFrom
277
+ | MoveSetState
278
+ | MoveSetActivePlayers
279
+ | MoveEndTurn
280
+ | MovePassTurn
281
+ | MoveForEach
282
+ | MoveShuffle
283
+ | MovePass;
284
+
285
+ export type MoveRule = MoveDefinition;
286
+
287
+ export interface MoveCommon {
288
+ /** Set when a move is registered under a key (e.g. from `createMoves`). */
289
+ name?: string;
290
+ conditions?: Condition[];
291
+ then?: MoveDefinition[];
292
+ }
293
+
294
+ export interface MovePlaceNew extends MoveCommon {
295
+ moveType: "PlaceNew";
296
+ matchMultiple?: boolean;
297
+ entity: { conditions?: Condition[]; [k: string]: unknown };
298
+ arguments: {
299
+ destination: Record<string, unknown>;
300
+ [k: string]: unknown;
301
+ };
302
+ }
303
+
304
+ export interface MoveMoveEntity extends MoveCommon {
305
+ moveType: "MoveEntity";
306
+ position?: "First";
307
+ arguments: {
308
+ entity: Record<string, unknown>;
309
+ destination: Record<string, unknown>;
310
+ [k: string]: unknown;
311
+ };
312
+ }
313
+
314
+ export interface MoveRemoveEntity extends MoveCommon {
315
+ moveType: "RemoveEntity";
316
+ arguments: { entity: ValueRef | Record<string, unknown>; [k: string]: unknown };
317
+ }
318
+
319
+ export interface MoveTakeFrom extends MoveCommon {
320
+ moveType: "TakeFrom";
321
+ arguments: {
322
+ source: Record<string, unknown>;
323
+ destination: Record<string, unknown>;
324
+ [k: string]: unknown;
325
+ };
326
+ }
327
+
328
+ export interface StateUpdate {
329
+ property: string;
330
+ value?: unknown;
331
+ possibleValues?: unknown[];
332
+ playerChoice?: boolean;
333
+ }
334
+
335
+ export interface MoveSetState extends MoveCommon {
336
+ moveType: "SetState";
337
+ arguments: {
338
+ entity: ValueRef | Record<string, unknown>;
339
+ state: StateUpdate;
340
+ [k: string]: unknown;
341
+ };
342
+ }
343
+
344
+ export interface MoveSetActivePlayers extends MoveCommon {
345
+ moveType: "SetActivePlayers";
346
+ options: Record<string, { stage?: string; [k: string]: unknown }>;
347
+ }
348
+
349
+ export interface MoveEndTurn extends MoveCommon {
350
+ moveType: "EndTurn";
351
+ }
352
+
353
+ export interface MovePassTurn extends MoveCommon {
354
+ moveType: "PassTurn";
355
+ }
356
+
357
+ export interface MovePass extends MoveCommon {
358
+ moveType: "Pass";
359
+ }
360
+
361
+ export interface MoveForEach extends MoveCommon {
362
+ moveType: "ForEach";
363
+ arguments: { targets: ValueRef | Record<string, unknown>; [k: string]: unknown };
364
+ move: MoveDefinition;
365
+ }
366
+
367
+ export interface MoveShuffle extends MoveCommon {
368
+ moveType: "Shuffle";
369
+ arguments: { target: Record<string, unknown>; [k: string]: unknown };
370
+ }
371
+
372
+ // ---------------------------------------------------------------------------
373
+ // Turn, stages, phases, end rules
374
+ // ---------------------------------------------------------------------------
375
+
376
+ export interface TurnConfig {
377
+ minMoves?: number;
378
+ maxMoves?: number;
379
+ initialMoves?: MoveDefinition[];
380
+ activePlayers?: Record<string, string>;
381
+ stages?: Record<string, StageConfig>;
382
+ order?: { playOrder?: "RotateFirst" };
383
+ }
384
+
385
+ export interface StageConfig {
386
+ initialMoves?: MoveDefinition[];
387
+ moves?: Record<string, MoveDefinition>;
388
+ }
389
+
390
+ export interface PhaseConfig {
391
+ start?: boolean;
392
+ next?: string;
393
+ turn?: TurnConfig;
394
+ moves?: Record<string, MoveDefinition>;
395
+ initialMoves?: MoveDefinition[];
396
+ endIf?: EndRule[];
397
+ }
398
+
399
+ export interface EndRule {
400
+ conditions: Condition[];
401
+ result?: {
402
+ winner?: string | ValueRef;
403
+ winners?: ValueRef;
404
+ draw?: boolean;
405
+ [k: string]: unknown;
406
+ };
407
+ }
408
+
409
+ // ---------------------------------------------------------------------------
410
+ // Initial placement
411
+ // ---------------------------------------------------------------------------
412
+
413
+ export interface InitialPlacement {
414
+ entity: Record<string, unknown>;
415
+ destination: { index?: number; name?: string };
416
+ }
417
+
418
+ // ---------------------------------------------------------------------------
419
+ // Game config (top level)
420
+ // ---------------------------------------------------------------------------
421
+
422
+ export interface BagelGame {
423
+ entities: Entity[];
424
+ sharedBoard?: EntityMatcher<EntityAttributes<Entity>>[];
425
+ personalBoard?: EntityMatcher<EntityAttributes<Entity>>[];
426
+ initialPlacements?: InitialPlacement[];
427
+ numPlayers?: number;
428
+ minPlayers?: number;
429
+ maxPlayers?: number;
430
+ turn?: TurnConfig;
431
+ moves?: Record<string, MoveDefinition>;
432
+ initialMoves?: MoveDefinition[];
433
+ phases?: Record<string, PhaseConfig>;
434
+ endIf?: EndRule[];
435
+ }
436
+
437
+ /** Rule object passed to `gameFactory` (engine-specific extensions on top of BagelGame). */
438
+ export type GameFactoryInput = BagelGame & {
439
+ DEBUG_DISABLE_SECRET_STATE?: boolean;
440
+ };
441
+
442
+ /**
443
+ * Rules after {@link expandGameRules}: invariant entities merged, default turn/sharedBoard,
444
+ * initial placements expanded into moves; `initialPlacements` is removed.
445
+ */
446
+ export type ExpandedGameRules = Omit<GameFactoryInput, "entities" | "turn" | "initialPlacements"> & {
447
+ entities: Entity[];
448
+ turn: TurnConfig;
449
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Subpath used by this package; @types/boardgame.io may not cover `dist/cjs/core.js`.
3
+ */
4
+ declare module "@mnbroatch/boardgame.io/dist/cjs/core.js" {
5
+ /** Sentinel returned by moves to signal an illegal move. */
6
+ export const INVALID_MOVE: unique symbol;
7
+ }
@@ -0,0 +1,70 @@
1
+ export type {
2
+ BagelGame,
3
+ GameFactoryInput,
4
+ ExpandedGameRules,
5
+ PathSegment,
6
+ ValueRef,
7
+ CtxPathRef,
8
+ ContextPathRef,
9
+ GamePathRef,
10
+ ExpressionRef,
11
+ RelativeCoordinatesRef,
12
+ CoordinatesRef,
13
+ RelativePathRef,
14
+ ParentRef,
15
+ MapRef,
16
+ MapMaxRef,
17
+ PickRef,
18
+ CountRef,
19
+ Condition,
20
+ ConditionShorthandString,
21
+ ConditionShorthandEntityType,
22
+ ConditionTyped,
23
+ TargetSelector,
24
+ LineSequenceStep,
25
+ ConditionHasLine,
26
+ ConditionIsFull,
27
+ ConditionNoPossibleMoves,
28
+ ConditionPosition,
29
+ ConditionContainsSame,
30
+ ConditionIs,
31
+ ConditionContains,
32
+ ConditionNot,
33
+ ConditionOr,
34
+ ConditionSome,
35
+ ConditionEvery,
36
+ ConditionInLine,
37
+ ConditionEvaluate,
38
+ EntityAttributes,
39
+ EntityAttributeKey,
40
+ EntityMatcher,
41
+ Entity,
42
+ EntityBoard,
43
+ EntityCommon,
44
+ EntityGrid,
45
+ EntitySpace,
46
+ EntityGeneric,
47
+ EntityRule,
48
+ MoveDefinition,
49
+ MoveRule,
50
+ MoveCommon,
51
+ MovePlaceNew,
52
+ MoveMoveEntity,
53
+ MoveRemoveEntity,
54
+ MoveTakeFrom,
55
+ StateUpdate,
56
+ MoveSetState,
57
+ MoveSetActivePlayers,
58
+ MoveEndTurn,
59
+ MovePassTurn,
60
+ MovePass,
61
+ MoveForEach,
62
+ MoveShuffle,
63
+ TurnConfig,
64
+ StageConfig,
65
+ PhaseConfig,
66
+ EndRule,
67
+ InitialPlacement,
68
+ } from "./bagel-types.js";
69
+
70
+ export type { RuleWithConditions } from "./rule-with-conditions.js";
@@ -0,0 +1,9 @@
1
+ import type { Condition } from "./bagel-types.js";
2
+
3
+ /**
4
+ * Rule-shaped object that may carry a `conditions` array (moves, move arguments,
5
+ * entity/slot rules, scenarios, composite conditions).
6
+ */
7
+ export type RuleWithConditions = {
8
+ conditions?: Condition[];
9
+ } & Record<string, unknown>;