@drmxrcy/tcg-core 0.0.0-202602060542

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 (157) hide show
  1. package/README.md +882 -0
  2. package/package.json +58 -0
  3. package/src/__tests__/alpha-clash-engine-definition.test.ts +319 -0
  4. package/src/__tests__/createMockAlphaClashGame.ts +462 -0
  5. package/src/__tests__/createMockGrandArchiveGame.ts +373 -0
  6. package/src/__tests__/createMockGundamGame.ts +379 -0
  7. package/src/__tests__/createMockLorcanaGame.ts +328 -0
  8. package/src/__tests__/createMockOnePieceGame.ts +429 -0
  9. package/src/__tests__/createMockRiftboundGame.ts +462 -0
  10. package/src/__tests__/grand-archive-engine-definition.test.ts +118 -0
  11. package/src/__tests__/gundam-engine-definition.test.ts +110 -0
  12. package/src/__tests__/integration-complete-game.test.ts +508 -0
  13. package/src/__tests__/integration-network-sync.test.ts +469 -0
  14. package/src/__tests__/lorcana-engine-definition.test.ts +100 -0
  15. package/src/__tests__/move-enumeration.test.ts +725 -0
  16. package/src/__tests__/multiplayer-engine.test.ts +555 -0
  17. package/src/__tests__/one-piece-engine-definition.test.ts +114 -0
  18. package/src/__tests__/riftbound-engine-definition.test.ts +124 -0
  19. package/src/actions/action-definition.test.ts +201 -0
  20. package/src/actions/action-definition.ts +122 -0
  21. package/src/actions/action-timing.test.ts +490 -0
  22. package/src/actions/action-timing.ts +257 -0
  23. package/src/cards/card-definition.test.ts +268 -0
  24. package/src/cards/card-definition.ts +27 -0
  25. package/src/cards/card-instance.test.ts +422 -0
  26. package/src/cards/card-instance.ts +49 -0
  27. package/src/cards/computed-properties.test.ts +530 -0
  28. package/src/cards/computed-properties.ts +84 -0
  29. package/src/cards/conditional-modifiers.test.ts +390 -0
  30. package/src/cards/modifiers.test.ts +286 -0
  31. package/src/cards/modifiers.ts +51 -0
  32. package/src/engine/MULTIPLAYER.md +425 -0
  33. package/src/engine/__tests__/rule-engine-flow.test.ts +348 -0
  34. package/src/engine/__tests__/rule-engine-history.test.ts +535 -0
  35. package/src/engine/__tests__/rule-engine-moves.test.ts +488 -0
  36. package/src/engine/__tests__/rule-engine.test.ts +366 -0
  37. package/src/engine/index.ts +14 -0
  38. package/src/engine/multiplayer-engine.example.ts +571 -0
  39. package/src/engine/multiplayer-engine.ts +409 -0
  40. package/src/engine/rule-engine.test.ts +286 -0
  41. package/src/engine/rule-engine.ts +1539 -0
  42. package/src/engine/tracker-system.ts +172 -0
  43. package/src/examples/__tests__/coin-flip-game.test.ts +641 -0
  44. package/src/filtering/card-filter.test.ts +230 -0
  45. package/src/filtering/card-filter.ts +91 -0
  46. package/src/filtering/card-query.test.ts +901 -0
  47. package/src/filtering/card-query.ts +273 -0
  48. package/src/filtering/filter-matching.test.ts +944 -0
  49. package/src/filtering/filter-matching.ts +315 -0
  50. package/src/flow/SERIALIZATION.md +428 -0
  51. package/src/flow/__tests__/flow-definition.test.ts +427 -0
  52. package/src/flow/__tests__/flow-manager.test.ts +756 -0
  53. package/src/flow/__tests__/flow-serialization.test.ts +565 -0
  54. package/src/flow/flow-definition.ts +453 -0
  55. package/src/flow/flow-manager.ts +1044 -0
  56. package/src/flow/index.ts +35 -0
  57. package/src/game-definition/__tests__/game-definition-validation.test.ts +359 -0
  58. package/src/game-definition/__tests__/game-definition.test.ts +291 -0
  59. package/src/game-definition/__tests__/move-definitions.test.ts +328 -0
  60. package/src/game-definition/game-definition.ts +261 -0
  61. package/src/game-definition/index.ts +28 -0
  62. package/src/game-definition/move-definitions.ts +188 -0
  63. package/src/game-definition/validation.ts +183 -0
  64. package/src/history/history-manager.test.ts +497 -0
  65. package/src/history/history-manager.ts +312 -0
  66. package/src/history/history-operations.ts +122 -0
  67. package/src/history/index.ts +9 -0
  68. package/src/history/types.ts +255 -0
  69. package/src/index.ts +32 -0
  70. package/src/logging/index.ts +27 -0
  71. package/src/logging/log-formatter.ts +187 -0
  72. package/src/logging/logger.ts +276 -0
  73. package/src/logging/types.ts +148 -0
  74. package/src/moves/create-move.test.ts +331 -0
  75. package/src/moves/create-move.ts +64 -0
  76. package/src/moves/move-enumeration.ts +228 -0
  77. package/src/moves/move-executor.test.ts +431 -0
  78. package/src/moves/move-executor.ts +195 -0
  79. package/src/moves/move-system.test.ts +380 -0
  80. package/src/moves/move-system.ts +463 -0
  81. package/src/moves/standard-moves.ts +231 -0
  82. package/src/operations/card-operations.test.ts +236 -0
  83. package/src/operations/card-operations.ts +116 -0
  84. package/src/operations/card-registry-impl.test.ts +251 -0
  85. package/src/operations/card-registry-impl.ts +70 -0
  86. package/src/operations/card-registry.test.ts +234 -0
  87. package/src/operations/card-registry.ts +106 -0
  88. package/src/operations/counter-operations.ts +152 -0
  89. package/src/operations/game-operations.test.ts +280 -0
  90. package/src/operations/game-operations.ts +140 -0
  91. package/src/operations/index.ts +24 -0
  92. package/src/operations/operations-impl.test.ts +354 -0
  93. package/src/operations/operations-impl.ts +468 -0
  94. package/src/operations/zone-operations.test.ts +295 -0
  95. package/src/operations/zone-operations.ts +223 -0
  96. package/src/rng/seeded-rng.test.ts +339 -0
  97. package/src/rng/seeded-rng.ts +123 -0
  98. package/src/targeting/index.ts +48 -0
  99. package/src/targeting/target-definition.test.ts +273 -0
  100. package/src/targeting/target-definition.ts +37 -0
  101. package/src/targeting/target-dsl.ts +279 -0
  102. package/src/targeting/target-resolver.ts +486 -0
  103. package/src/targeting/target-validation.test.ts +994 -0
  104. package/src/targeting/target-validation.ts +286 -0
  105. package/src/telemetry/events.ts +202 -0
  106. package/src/telemetry/index.ts +21 -0
  107. package/src/telemetry/telemetry-manager.ts +127 -0
  108. package/src/telemetry/types.ts +68 -0
  109. package/src/testing/__tests__/testing-utilities-integration.test.ts +161 -0
  110. package/src/testing/index.ts +88 -0
  111. package/src/testing/test-assertions.test.ts +341 -0
  112. package/src/testing/test-assertions.ts +256 -0
  113. package/src/testing/test-card-factory.test.ts +228 -0
  114. package/src/testing/test-card-factory.ts +111 -0
  115. package/src/testing/test-context-factory.ts +187 -0
  116. package/src/testing/test-end-assertions.test.ts +262 -0
  117. package/src/testing/test-end-assertions.ts +95 -0
  118. package/src/testing/test-engine-builder.test.ts +389 -0
  119. package/src/testing/test-engine-builder.ts +46 -0
  120. package/src/testing/test-flow-assertions.test.ts +284 -0
  121. package/src/testing/test-flow-assertions.ts +115 -0
  122. package/src/testing/test-player-builder.test.ts +132 -0
  123. package/src/testing/test-player-builder.ts +46 -0
  124. package/src/testing/test-replay-assertions.test.ts +356 -0
  125. package/src/testing/test-replay-assertions.ts +164 -0
  126. package/src/testing/test-rng-helpers.test.ts +260 -0
  127. package/src/testing/test-rng-helpers.ts +190 -0
  128. package/src/testing/test-state-builder.test.ts +373 -0
  129. package/src/testing/test-state-builder.ts +99 -0
  130. package/src/testing/test-zone-factory.test.ts +295 -0
  131. package/src/testing/test-zone-factory.ts +224 -0
  132. package/src/types/branded-utils.ts +54 -0
  133. package/src/types/branded.test.ts +175 -0
  134. package/src/types/branded.ts +33 -0
  135. package/src/types/index.ts +8 -0
  136. package/src/types/state.test.ts +198 -0
  137. package/src/types/state.ts +154 -0
  138. package/src/validation/card-type-guards.test.ts +242 -0
  139. package/src/validation/card-type-guards.ts +179 -0
  140. package/src/validation/index.ts +40 -0
  141. package/src/validation/schema-builders.test.ts +403 -0
  142. package/src/validation/schema-builders.ts +345 -0
  143. package/src/validation/type-guard-builder.test.ts +216 -0
  144. package/src/validation/type-guard-builder.ts +109 -0
  145. package/src/validation/validator-builder.test.ts +375 -0
  146. package/src/validation/validator-builder.ts +273 -0
  147. package/src/zones/index.ts +28 -0
  148. package/src/zones/zone-factory.test.ts +183 -0
  149. package/src/zones/zone-factory.ts +44 -0
  150. package/src/zones/zone-operations.test.ts +800 -0
  151. package/src/zones/zone-operations.ts +306 -0
  152. package/src/zones/zone-state-helpers.test.ts +337 -0
  153. package/src/zones/zone-state-helpers.ts +128 -0
  154. package/src/zones/zone-visibility.test.ts +156 -0
  155. package/src/zones/zone-visibility.ts +36 -0
  156. package/src/zones/zone.test.ts +186 -0
  157. package/src/zones/zone.ts +66 -0
@@ -0,0 +1,172 @@
1
+ import type { PlayerId } from "../types/branded";
2
+
3
+ /**
4
+ * Configuration for the tracker system
5
+ */
6
+ export type TrackerConfig = {
7
+ /** Trackers that reset at the end of each turn */
8
+ perTurn?: string[];
9
+ /** Trackers that reset at the end of specific phases */
10
+ perPhase?: Record<string, string[]>;
11
+ /** Whether trackers are per-player or global */
12
+ perPlayer?: boolean;
13
+ };
14
+
15
+ /**
16
+ * Internal storage for tracker state
17
+ */
18
+ type TrackerState = Map<string, Set<PlayerId | "global">>;
19
+
20
+ /**
21
+ * System for managing boolean flags that automatically reset based on turn/phase boundaries.
22
+ * Useful for tracking "has done X this turn" style game state.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const trackers = new TrackerSystem({
27
+ * perTurn: ["hasDrawnCard", "hasPlayedResource"],
28
+ * perPhase: {
29
+ * main: ["hasAttacked"]
30
+ * },
31
+ * perPlayer: true
32
+ * });
33
+ *
34
+ * // In a move:
35
+ * if (!trackers.check("hasDrawnCard", playerId)) {
36
+ * // Draw card
37
+ * trackers.mark("hasDrawnCard", playerId);
38
+ * }
39
+ *
40
+ * // At turn end:
41
+ * trackers.resetTurn();
42
+ * ```
43
+ */
44
+ export class TrackerSystem {
45
+ private state: TrackerState = new Map();
46
+ private config: TrackerConfig;
47
+
48
+ constructor(config: TrackerConfig = {}) {
49
+ this.config = {
50
+ perPlayer: config.perPlayer ?? true,
51
+ perTurn: config.perTurn ?? [],
52
+ perPhase: config.perPhase ?? {},
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Check if a tracker is marked for a player or globally
58
+ */
59
+ public check(name: string, playerId?: PlayerId): boolean {
60
+ const key = this.getKey(playerId);
61
+ const trackerSet = this.state.get(name);
62
+ return trackerSet ? trackerSet.has(key) : false;
63
+ }
64
+
65
+ /**
66
+ * Mark a tracker as true for a player or globally
67
+ */
68
+ public mark(name: string, playerId?: PlayerId): void {
69
+ const key = this.getKey(playerId);
70
+ if (!this.state.has(name)) {
71
+ this.state.set(name, new Set());
72
+ }
73
+ this.state.get(name)?.add(key);
74
+ }
75
+
76
+ /**
77
+ * Unmark a tracker (set to false) for a player or globally
78
+ */
79
+ public unmark(name: string, playerId?: PlayerId): void {
80
+ const key = this.getKey(playerId);
81
+ this.state.get(name)?.delete(key);
82
+ }
83
+
84
+ /**
85
+ * Reset all turn-scoped trackers
86
+ * Supports wildcard patterns (e.g., "quested:*" matches "quested:card-123", "quested:card-456", etc.)
87
+ */
88
+ public resetTurn(): void {
89
+ for (const pattern of this.config.perTurn ?? []) {
90
+ if (pattern.endsWith("*")) {
91
+ // Wildcard pattern - delete all trackers matching the prefix
92
+ const prefix = pattern.slice(0, -1); // Remove the "*"
93
+ const keysToDelete: string[] = [];
94
+ for (const trackerName of this.state.keys()) {
95
+ if (trackerName.startsWith(prefix)) {
96
+ keysToDelete.push(trackerName);
97
+ }
98
+ }
99
+ for (const key of keysToDelete) {
100
+ this.state.delete(key);
101
+ }
102
+ } else {
103
+ // Exact match - delete specific tracker
104
+ this.state.delete(pattern);
105
+ }
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Reset all trackers for a specific phase
111
+ * Supports wildcard patterns (e.g., "action:*" matches "action:move", "action:attack", etc.)
112
+ */
113
+ public resetPhase(phaseName: string): void {
114
+ const phaseTrackers = this.config.perPhase?.[phaseName] ?? [];
115
+ for (const pattern of phaseTrackers) {
116
+ if (pattern.endsWith("*")) {
117
+ // Wildcard pattern - delete all trackers matching the prefix
118
+ const prefix = pattern.slice(0, -1); // Remove the "*"
119
+ const keysToDelete: string[] = [];
120
+ for (const trackerName of this.state.keys()) {
121
+ if (trackerName.startsWith(prefix)) {
122
+ keysToDelete.push(trackerName);
123
+ }
124
+ }
125
+ for (const key of keysToDelete) {
126
+ this.state.delete(key);
127
+ }
128
+ } else {
129
+ // Exact match - delete specific tracker
130
+ this.state.delete(pattern);
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Reset all trackers (useful for game reset)
137
+ */
138
+ public resetAll(): void {
139
+ this.state.clear();
140
+ }
141
+
142
+ /**
143
+ * Get the storage key for a player or global tracker
144
+ */
145
+ private getKey(playerId?: PlayerId): PlayerId | "global" {
146
+ if (this.config.perPlayer && playerId) {
147
+ return playerId;
148
+ }
149
+ return "global";
150
+ }
151
+
152
+ /**
153
+ * Get all currently marked trackers (for debugging/serialization)
154
+ */
155
+ public getState(): Record<string, (PlayerId | "global")[]> {
156
+ const result: Record<string, (PlayerId | "global")[]> = {};
157
+ for (const [name, playerSet] of this.state.entries()) {
158
+ result[name] = Array.from(playerSet);
159
+ }
160
+ return result;
161
+ }
162
+
163
+ /**
164
+ * Restore tracker state (for deserialization)
165
+ */
166
+ public setState(state: Record<string, (PlayerId | "global")[]>): void {
167
+ this.state.clear();
168
+ for (const [name, players] of Object.entries(state)) {
169
+ this.state.set(name, new Set(players));
170
+ }
171
+ }
172
+ }