@series-inc/rundot-syncplay 5.23.0-beta.7

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 (264) hide show
  1. package/README.md +610 -0
  2. package/dist/animation.d.ts +119 -0
  3. package/dist/animation.js +488 -0
  4. package/dist/asset-cooking.d.ts +82 -0
  5. package/dist/asset-cooking.js +364 -0
  6. package/dist/authority-room.d.ts +217 -0
  7. package/dist/authority-room.js +701 -0
  8. package/dist/bot-documents.d.ts +115 -0
  9. package/dist/bot-documents.js +549 -0
  10. package/dist/bot-primitives.d.ts +152 -0
  11. package/dist/bot-primitives.js +472 -0
  12. package/dist/browser.d.ts +57 -0
  13. package/dist/browser.js +53 -0
  14. package/dist/canonical.d.ts +12 -0
  15. package/dist/canonical.js +288 -0
  16. package/dist/certification.d.ts +455 -0
  17. package/dist/certification.js +1855 -0
  18. package/dist/chaos-certification.d.ts +56 -0
  19. package/dist/chaos-certification.js +1397 -0
  20. package/dist/cjs/animation.js +495 -0
  21. package/dist/cjs/asset-cooking.js +372 -0
  22. package/dist/cjs/authority-room.js +704 -0
  23. package/dist/cjs/bot-documents.js +556 -0
  24. package/dist/cjs/bot-primitives.js +482 -0
  25. package/dist/cjs/browser.js +96 -0
  26. package/dist/cjs/canonical.js +299 -0
  27. package/dist/cjs/certification.js +1860 -0
  28. package/dist/cjs/chaos-certification.js +1402 -0
  29. package/dist/cjs/collections.js +36 -0
  30. package/dist/cjs/collision.js +96 -0
  31. package/dist/cjs/commands.js +987 -0
  32. package/dist/cjs/config-bundle.js +491 -0
  33. package/dist/cjs/creator.js +30 -0
  34. package/dist/cjs/deterministic-primitives.js +134 -0
  35. package/dist/cjs/deterministic-session.js +1410 -0
  36. package/dist/cjs/ecs-lite.js +155 -0
  37. package/dist/cjs/effects-adapter.js +97 -0
  38. package/dist/cjs/engine-complete.js +2297 -0
  39. package/dist/cjs/engine-core-proof.js +70 -0
  40. package/dist/cjs/engine-parity-matrix.js +874 -0
  41. package/dist/cjs/engine-parity.js +3183 -0
  42. package/dist/cjs/engine-runtime.js +3141 -0
  43. package/dist/cjs/errors.js +22 -0
  44. package/dist/cjs/events.js +247 -0
  45. package/dist/cjs/examples/counter-duel.js +157 -0
  46. package/dist/cjs/examples/fixed-arena.js +368 -0
  47. package/dist/cjs/index.js +229 -0
  48. package/dist/cjs/input-authority.js +150 -0
  49. package/dist/cjs/input-button.js +256 -0
  50. package/dist/cjs/input-timeline.js +418 -0
  51. package/dist/cjs/instant-replay.js +66 -0
  52. package/dist/cjs/lag-compensation3d.js +837 -0
  53. package/dist/cjs/local-authority-server-runner.js +1121 -0
  54. package/dist/cjs/local-authority-wire.js +1497 -0
  55. package/dist/cjs/local-authority.js +817 -0
  56. package/dist/cjs/local-ws-adapter.js +150 -0
  57. package/dist/cjs/match-log.js +61 -0
  58. package/dist/cjs/math.js +157 -0
  59. package/dist/cjs/mock-network-adapter.js +26 -0
  60. package/dist/cjs/movement.js +703 -0
  61. package/dist/cjs/movement3d.js +1246 -0
  62. package/dist/cjs/multiclient-authority.js +308 -0
  63. package/dist/cjs/multiplayer-service.js +434 -0
  64. package/dist/cjs/navigation.js +347 -0
  65. package/dist/cjs/navmesh.js +1437 -0
  66. package/dist/cjs/networked-client.js +691 -0
  67. package/dist/cjs/networked-input-authority.js +443 -0
  68. package/dist/cjs/node.js +47 -0
  69. package/dist/cjs/number-lab.js +78 -0
  70. package/dist/cjs/offline-session.js +370 -0
  71. package/dist/cjs/package.json +1 -0
  72. package/dist/cjs/pause-resume.js +43 -0
  73. package/dist/cjs/physics-cert.js +426 -0
  74. package/dist/cjs/physics2d.js +751 -0
  75. package/dist/cjs/physics3d.js +1996 -0
  76. package/dist/cjs/prediction-culling.js +203 -0
  77. package/dist/cjs/protocol-lab.js +1299 -0
  78. package/dist/cjs/r3f-render-adapter.js +209 -0
  79. package/dist/cjs/random.js +59 -0
  80. package/dist/cjs/replay-bundle.js +1598 -0
  81. package/dist/cjs/replay-inspect.js +236 -0
  82. package/dist/cjs/replay-scoring.js +68 -0
  83. package/dist/cjs/replay.js +356 -0
  84. package/dist/cjs/reports.js +181 -0
  85. package/dist/cjs/rollback-history.js +251 -0
  86. package/dist/cjs/runtime-guards.js +111 -0
  87. package/dist/cjs/sample-lab.js +145 -0
  88. package/dist/cjs/sample-scenes.js +752 -0
  89. package/dist/cjs/schema-artifacts.js +359 -0
  90. package/dist/cjs/schema-codegen.js +544 -0
  91. package/dist/cjs/schema-dsl-binary.js +655 -0
  92. package/dist/cjs/schema.js +319 -0
  93. package/dist/cjs/sdk-offline.js +99 -0
  94. package/dist/cjs/session-promotion.js +74 -0
  95. package/dist/cjs/session-snapshot.js +265 -0
  96. package/dist/cjs/session-wire.js +216 -0
  97. package/dist/cjs/signals.js +103 -0
  98. package/dist/cjs/sparse-set.js +169 -0
  99. package/dist/cjs/synctest.js +136 -0
  100. package/dist/cjs/system-lifecycle.js +286 -0
  101. package/dist/cjs/timers.js +61 -0
  102. package/dist/cjs/tools/static-checker.js +1468 -0
  103. package/dist/cjs/types.js +2 -0
  104. package/dist/cjs/venus-mp-budget.js +125 -0
  105. package/dist/cjs/ws-frame.js +255 -0
  106. package/dist/cli.d.ts +2 -0
  107. package/dist/cli.js +11379 -0
  108. package/dist/collections.d.ts +9 -0
  109. package/dist/collections.js +30 -0
  110. package/dist/collision.d.ts +25 -0
  111. package/dist/collision.js +85 -0
  112. package/dist/commands.d.ts +137 -0
  113. package/dist/commands.js +977 -0
  114. package/dist/config-bundle.d.ts +89 -0
  115. package/dist/config-bundle.js +483 -0
  116. package/dist/creator.d.ts +20 -0
  117. package/dist/creator.js +11 -0
  118. package/dist/deterministic-primitives.d.ts +59 -0
  119. package/dist/deterministic-primitives.js +126 -0
  120. package/dist/deterministic-session.d.ts +197 -0
  121. package/dist/deterministic-session.js +1401 -0
  122. package/dist/ecs-lite.d.ts +26 -0
  123. package/dist/ecs-lite.js +152 -0
  124. package/dist/effects-adapter.d.ts +21 -0
  125. package/dist/effects-adapter.js +94 -0
  126. package/dist/engine-complete.d.ts +45 -0
  127. package/dist/engine-complete.js +2292 -0
  128. package/dist/engine-core-proof.d.ts +26 -0
  129. package/dist/engine-core-proof.js +66 -0
  130. package/dist/engine-parity-matrix.d.ts +300 -0
  131. package/dist/engine-parity-matrix.js +869 -0
  132. package/dist/engine-parity.d.ts +74 -0
  133. package/dist/engine-parity.js +3178 -0
  134. package/dist/engine-runtime.d.ts +351 -0
  135. package/dist/engine-runtime.js +3123 -0
  136. package/dist/errors.d.ts +11 -0
  137. package/dist/errors.js +17 -0
  138. package/dist/events.d.ts +45 -0
  139. package/dist/events.js +242 -0
  140. package/dist/examples/counter-duel.d.ts +43 -0
  141. package/dist/examples/counter-duel.js +150 -0
  142. package/dist/examples/fixed-arena.d.ts +110 -0
  143. package/dist/examples/fixed-arena.js +356 -0
  144. package/dist/index.d.ts +101 -0
  145. package/dist/index.js +66 -0
  146. package/dist/input-authority.d.ts +82 -0
  147. package/dist/input-authority.js +147 -0
  148. package/dist/input-button.d.ts +36 -0
  149. package/dist/input-button.js +249 -0
  150. package/dist/input-timeline.d.ts +65 -0
  151. package/dist/input-timeline.js +412 -0
  152. package/dist/instant-replay.d.ts +59 -0
  153. package/dist/instant-replay.js +62 -0
  154. package/dist/lag-compensation3d.d.ts +146 -0
  155. package/dist/lag-compensation3d.js +827 -0
  156. package/dist/local-authority-server-runner.d.ts +79 -0
  157. package/dist/local-authority-server-runner.js +1118 -0
  158. package/dist/local-authority-wire.d.ts +142 -0
  159. package/dist/local-authority-wire.js +1477 -0
  160. package/dist/local-authority.d.ts +160 -0
  161. package/dist/local-authority.js +810 -0
  162. package/dist/local-ws-adapter.d.ts +14 -0
  163. package/dist/local-ws-adapter.js +146 -0
  164. package/dist/match-log.d.ts +74 -0
  165. package/dist/match-log.js +57 -0
  166. package/dist/math.d.ts +41 -0
  167. package/dist/math.js +154 -0
  168. package/dist/mock-network-adapter.d.ts +13 -0
  169. package/dist/mock-network-adapter.js +23 -0
  170. package/dist/movement.d.ts +155 -0
  171. package/dist/movement.js +694 -0
  172. package/dist/movement3d.d.ts +195 -0
  173. package/dist/movement3d.js +1238 -0
  174. package/dist/multiclient-authority.d.ts +30 -0
  175. package/dist/multiclient-authority.js +305 -0
  176. package/dist/multiplayer-service.d.ts +153 -0
  177. package/dist/multiplayer-service.js +429 -0
  178. package/dist/navigation.d.ts +91 -0
  179. package/dist/navigation.js +338 -0
  180. package/dist/navmesh.d.ts +236 -0
  181. package/dist/navmesh.js +1423 -0
  182. package/dist/networked-client.d.ts +124 -0
  183. package/dist/networked-client.js +688 -0
  184. package/dist/networked-input-authority.d.ts +51 -0
  185. package/dist/networked-input-authority.js +439 -0
  186. package/dist/node.d.ts +22 -0
  187. package/dist/node.js +19 -0
  188. package/dist/number-lab.d.ts +15 -0
  189. package/dist/number-lab.js +75 -0
  190. package/dist/offline-session.d.ts +2 -0
  191. package/dist/offline-session.js +367 -0
  192. package/dist/pause-resume.d.ts +48 -0
  193. package/dist/pause-resume.js +40 -0
  194. package/dist/physics-cert.d.ts +40 -0
  195. package/dist/physics-cert.js +389 -0
  196. package/dist/physics2d.d.ts +142 -0
  197. package/dist/physics2d.js +741 -0
  198. package/dist/physics3d.d.ts +285 -0
  199. package/dist/physics3d.js +1979 -0
  200. package/dist/prediction-culling.d.ts +34 -0
  201. package/dist/prediction-culling.js +200 -0
  202. package/dist/protocol-lab.d.ts +115 -0
  203. package/dist/protocol-lab.js +1295 -0
  204. package/dist/r3f-render-adapter.d.ts +61 -0
  205. package/dist/r3f-render-adapter.js +203 -0
  206. package/dist/random.d.ts +13 -0
  207. package/dist/random.js +55 -0
  208. package/dist/replay-bundle.d.ts +150 -0
  209. package/dist/replay-bundle.js +1586 -0
  210. package/dist/replay-inspect.d.ts +60 -0
  211. package/dist/replay-inspect.js +228 -0
  212. package/dist/replay-scoring.d.ts +28 -0
  213. package/dist/replay-scoring.js +65 -0
  214. package/dist/replay.d.ts +17 -0
  215. package/dist/replay.js +351 -0
  216. package/dist/reports.d.ts +176 -0
  217. package/dist/reports.js +174 -0
  218. package/dist/rollback-history.d.ts +46 -0
  219. package/dist/rollback-history.js +247 -0
  220. package/dist/runtime-guards.d.ts +1 -0
  221. package/dist/runtime-guards.js +108 -0
  222. package/dist/sample-lab.d.ts +32 -0
  223. package/dist/sample-lab.js +134 -0
  224. package/dist/sample-scenes.d.ts +86 -0
  225. package/dist/sample-scenes.js +745 -0
  226. package/dist/schema-artifacts.d.ts +49 -0
  227. package/dist/schema-artifacts.js +356 -0
  228. package/dist/schema-codegen.d.ts +21 -0
  229. package/dist/schema-codegen.js +538 -0
  230. package/dist/schema-dsl-binary.d.ts +75 -0
  231. package/dist/schema-dsl-binary.js +648 -0
  232. package/dist/schema.d.ts +87 -0
  233. package/dist/schema.js +315 -0
  234. package/dist/sdk-offline.d.ts +34 -0
  235. package/dist/sdk-offline.js +96 -0
  236. package/dist/session-promotion.d.ts +26 -0
  237. package/dist/session-promotion.js +70 -0
  238. package/dist/session-snapshot.d.ts +95 -0
  239. package/dist/session-snapshot.js +255 -0
  240. package/dist/session-wire.d.ts +89 -0
  241. package/dist/session-wire.js +211 -0
  242. package/dist/signals.d.ts +31 -0
  243. package/dist/signals.js +99 -0
  244. package/dist/sparse-set.d.ts +34 -0
  245. package/dist/sparse-set.js +165 -0
  246. package/dist/synctest.d.ts +31 -0
  247. package/dist/synctest.js +133 -0
  248. package/dist/system-lifecycle.d.ts +72 -0
  249. package/dist/system-lifecycle.js +281 -0
  250. package/dist/timers.d.ts +17 -0
  251. package/dist/timers.js +53 -0
  252. package/dist/tools/index.d.ts +4 -0
  253. package/dist/tools/index.js +4 -0
  254. package/dist/tools/static-checker.d.ts +31 -0
  255. package/dist/tools/static-checker.js +1462 -0
  256. package/dist/tools/vite-plugin.d.ts +69 -0
  257. package/dist/tools/vite-plugin.js +203 -0
  258. package/dist/types.d.ts +148 -0
  259. package/dist/types.js +1 -0
  260. package/dist/venus-mp-budget.d.ts +29 -0
  261. package/dist/venus-mp-budget.js +122 -0
  262. package/dist/ws-frame.d.ts +49 -0
  263. package/dist/ws-frame.js +247 -0
  264. package/package.json +169 -0
@@ -0,0 +1,482 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDeterministicBotBlackboard = createDeterministicBotBlackboard;
4
+ exports.getBlackboardValue = getBlackboardValue;
5
+ exports.tickDeterministicHfsm = tickDeterministicHfsm;
6
+ exports.tickDeterministicBehaviorTree = tickDeterministicBehaviorTree;
7
+ exports.tickDeterministicBehaviorTreeWithMemory = tickDeterministicBehaviorTreeWithMemory;
8
+ exports.selectDeterministicUtility = selectDeterministicUtility;
9
+ exports.cookDeterministicBotAsset = cookDeterministicBotAsset;
10
+ exports.runDeterministicBotSimulation = runDeterministicBotSimulation;
11
+ const canonical_js_1 = require("./canonical.js");
12
+ function createDeterministicBotBlackboard(entries) {
13
+ const sorted = [...entries].sort((left, right) => compareStrings(left.key, right.key));
14
+ const duplicate = sorted.find((entry, index) => index > 0 && entry.key === sorted[index - 1].key);
15
+ if (duplicate !== undefined) {
16
+ throw new Error(`Duplicate blackboard key ${duplicate.key}`);
17
+ }
18
+ return {
19
+ entries: sorted,
20
+ hash: (0, canonical_js_1.defaultChecksum)(sorted),
21
+ };
22
+ }
23
+ function getBlackboardValue(blackboard, key) {
24
+ return blackboard.entries.find((entry) => entry.key === key)?.value;
25
+ }
26
+ function tickDeterministicHfsm(definition, agent, blackboard) {
27
+ const states = new Map(definition.states.map((state) => [state.id, state]));
28
+ const current = states.get(agent.state);
29
+ if (current === undefined) {
30
+ throw new Error(`Unknown HFSM state ${agent.state}`);
31
+ }
32
+ const transition = definition.transitions
33
+ .filter((candidate) => candidate.from === agent.state || candidate.from === current.parent)
34
+ .sort(compareTransitions)
35
+ .find((candidate) => getBlackboardValue(blackboard, candidate.whenKey) === candidate.equals);
36
+ const nextState = transition?.to ?? agent.state;
37
+ const next = states.get(nextState);
38
+ if (next === undefined) {
39
+ throw new Error(`Unknown HFSM transition target ${nextState}`);
40
+ }
41
+ const actionLog = next.action === undefined ? agent.actionLog : [...agent.actionLog, next.action];
42
+ return {
43
+ state: nextState,
44
+ transitionsTaken: agent.transitionsTaken + (transition === undefined ? 0 : 1),
45
+ actionLog,
46
+ };
47
+ }
48
+ function tickDeterministicBehaviorTree(node, blackboard) {
49
+ const visitedNodeIds = [];
50
+ const actions = [];
51
+ const status = evaluateBehaviorTree(node, blackboard, visitedNodeIds, actions);
52
+ return {
53
+ status,
54
+ actions,
55
+ visitedNodeIds,
56
+ };
57
+ }
58
+ function tickDeterministicBehaviorTreeWithMemory(node, blackboard, memory = { runningNodeIds: [], completedRunningNodeIds: [] }) {
59
+ const visitedNodeIds = [];
60
+ const actions = [];
61
+ const resumedNodeIds = [];
62
+ const serviceActions = [];
63
+ const serviceNodeIds = [];
64
+ const nextMemory = {
65
+ runningNodeIds: [...memory.runningNodeIds].sort(compareStrings),
66
+ completedRunningNodeIds: [...memory.completedRunningNodeIds].sort(compareStrings),
67
+ };
68
+ const status = evaluateBehaviorTreeWithMemory(node, blackboard, visitedNodeIds, actions, resumedNodeIds, serviceActions, serviceNodeIds, nextMemory);
69
+ return {
70
+ status,
71
+ actions,
72
+ visitedNodeIds,
73
+ memory: {
74
+ runningNodeIds: nextMemory.runningNodeIds.sort(compareStrings),
75
+ completedRunningNodeIds: nextMemory.completedRunningNodeIds.sort(compareStrings),
76
+ },
77
+ resumedNodeIds: resumedNodeIds.sort(compareStrings),
78
+ serviceActions,
79
+ serviceNodeIds: serviceNodeIds.sort(compareStrings),
80
+ };
81
+ }
82
+ function selectDeterministicUtility(considerations, blackboard) {
83
+ const scores = considerations
84
+ .map((consideration) => {
85
+ const baseScore = scoreUtilityInput(getBlackboardValue(blackboard, consideration.inputKey), consideration.min, consideration.max, consideration.weight, consideration.curve ?? 'linear');
86
+ const nestedScore = (consideration.nested ?? []).reduce((sum, nested) => sum + scoreUtilityInput(getBlackboardValue(blackboard, nested.inputKey), nested.min, nested.max, nested.weight, nested.curve ?? 'linear'), 0);
87
+ const momentumValue = consideration.momentumKey === undefined ? undefined : getBlackboardValue(blackboard, consideration.momentumKey);
88
+ const momentumScore = typeof momentumValue === 'number'
89
+ ? Math.trunc(momentumValue * (consideration.momentum ?? 0))
90
+ : momentumValue === true ? Math.trunc(consideration.momentum ?? 0) : 0;
91
+ const cooldownValue = consideration.cooldownKey === undefined ? undefined : getBlackboardValue(blackboard, consideration.cooldownKey);
92
+ const cooldownPenalty = typeof cooldownValue === 'number' && cooldownValue > 0
93
+ ? Math.trunc(cooldownValue * (consideration.cooldownPenalty ?? 1_000))
94
+ : cooldownValue === true ? Math.trunc(consideration.cooldownPenalty ?? 1_000) : 0;
95
+ const score = baseScore + nestedScore + momentumScore + (consideration.rank ?? 0) - cooldownPenalty;
96
+ return { id: consideration.id, score, baseScore, nestedScore, momentumScore, cooldownPenalty };
97
+ })
98
+ .sort((left, right) => right.score - left.score || compareStrings(left.id, right.id));
99
+ const selectedScore = scores[0];
100
+ const selected = considerations.find((consideration) => consideration.id === selectedScore.id);
101
+ if (selected === undefined) {
102
+ throw new Error('Utility selector requires at least one consideration');
103
+ }
104
+ return {
105
+ action: selected.action,
106
+ considerationId: selected.id,
107
+ score: selectedScore.score,
108
+ scores,
109
+ };
110
+ }
111
+ function cookDeterministicBotAsset(source) {
112
+ const cooked = {
113
+ id: source.id,
114
+ hfsm: source.hfsm === undefined ? undefined : normalizeHfsm(source.hfsm),
115
+ behaviorTree: source.behaviorTree === undefined ? undefined : normalizeBehaviorTree(source.behaviorTree),
116
+ utility: source.utility === undefined
117
+ ? undefined
118
+ : [...source.utility].sort((left, right) => compareStrings(left.id, right.id)),
119
+ };
120
+ const bytes = (0, canonical_js_1.canonicalStringify)(cooked);
121
+ return {
122
+ id: source.id,
123
+ bytes,
124
+ hash: (0, canonical_js_1.defaultChecksum)(bytes),
125
+ };
126
+ }
127
+ function runDeterministicBotSimulation(players, frames, seed, restoreFrame = -1) {
128
+ const hfsm = defaultHfsm();
129
+ const tree = defaultBehaviorTree();
130
+ const utility = defaultUtility();
131
+ const cooked = cookDeterministicBotAsset({ id: 'bot.default', hfsm, behaviorTree: tree, utility });
132
+ let bots = Array.from({ length: players }, (_, slot) => ({
133
+ slot,
134
+ lane: slot % 4 === 0 ? 'human' : 'bot',
135
+ hp: 10,
136
+ hfsm: { state: hfsm.initialState, transitionsTaken: 0, actionLog: [] },
137
+ target: (slot + 1) % players,
138
+ utility: 0,
139
+ utilityScoreBreakdown: [],
140
+ behaviorActions: [],
141
+ behaviorServiceActions: [],
142
+ behaviorStatus: 'success',
143
+ visitedBehaviorNodes: [],
144
+ behaviorMemory: { runningNodeIds: [], completedRunningNodeIds: [] },
145
+ }));
146
+ let snapshot = bots;
147
+ let hfsmTransitions = 0;
148
+ let behaviorTreeTicks = 0;
149
+ let behaviorRunningTicks = 0;
150
+ let behaviorResumeTicks = 0;
151
+ let behaviorDecoratorTicks = 0;
152
+ let behaviorServiceTicks = 0;
153
+ let utilitySelections = 0;
154
+ let utilityCurveSelections = 0;
155
+ let utilityNestedSelections = 0;
156
+ let utilityMomentumSelections = 0;
157
+ let utilityCooldownSuppressions = 0;
158
+ let humanInputSlots = 0;
159
+ let botInputSlots = 0;
160
+ for (let frame = 0; frame < frames; frame += 1) {
161
+ if (frame === restoreFrame) {
162
+ snapshot = (0, canonical_js_1.cloneCanonical)(bots);
163
+ }
164
+ if (restoreFrame >= 0 && frame === restoreFrame + 6) {
165
+ bots = (0, canonical_js_1.cloneCanonical)(snapshot);
166
+ for (let replay = restoreFrame; replay < frame; replay += 1) {
167
+ bots = stepBotFrame(bots, replay, seed, hfsm, tree, utility);
168
+ }
169
+ }
170
+ bots = stepBotFrame(bots, frame, seed, hfsm, tree, utility);
171
+ hfsmTransitions += bots.reduce((sum, bot) => sum + bot.hfsm.transitionsTaken, 0);
172
+ behaviorTreeTicks += bots.length;
173
+ behaviorRunningTicks += bots.filter((bot) => bot.behaviorStatus === 'running').length;
174
+ behaviorResumeTicks += bots.filter((bot) => bot.behaviorMemory.completedRunningNodeIds.length > 0).length;
175
+ behaviorDecoratorTicks += bots.filter((bot) => bot.visitedBehaviorNodes.includes('maybe-patrol')).length;
176
+ behaviorServiceTicks += bots.filter((bot) => bot.behaviorServiceActions.length > 0).length;
177
+ utilitySelections += bots.filter((bot) => bot.utility > 5_000).length;
178
+ utilityCurveSelections += bots.filter((bot) => bot.utilityScoreBreakdown.some((score) => score.baseScore !== 0)).length;
179
+ utilityNestedSelections += bots.filter((bot) => bot.utilityScoreBreakdown.some((score) => score.nestedScore !== 0)).length;
180
+ utilityMomentumSelections += bots.filter((bot) => bot.utilityScoreBreakdown.some((score) => score.momentumScore !== 0)).length;
181
+ utilityCooldownSuppressions += bots.filter((bot) => bot.utilityScoreBreakdown.some((score) => score.cooldownPenalty > 0)).length;
182
+ humanInputSlots += bots.filter((bot) => bot.lane === 'human').length;
183
+ botInputSlots += bots.filter((bot) => bot.lane === 'bot').length;
184
+ }
185
+ const blackboard = createDeterministicBotBlackboard(bots.map((bot) => ({
186
+ key: `slot:${bot.slot.toString().padStart(3, '0')}`,
187
+ value: `${bot.hfsm.state}:${bot.target}`,
188
+ })));
189
+ return {
190
+ checksum: (0, canonical_js_1.defaultChecksum)(bots),
191
+ blackboardHash: blackboard.hash,
192
+ cookedBotHash: cooked.hash,
193
+ styles: 'behavior-tree,hfsm,utility',
194
+ hfsmTransitions,
195
+ behaviorTreeTicks,
196
+ behaviorRunningTicks,
197
+ behaviorResumeTicks,
198
+ behaviorDecoratorTicks,
199
+ behaviorServiceTicks,
200
+ utilitySelections,
201
+ utilityCurveSelections,
202
+ utilityNestedSelections,
203
+ utilityMomentumSelections,
204
+ utilityCooldownSuppressions,
205
+ botReplacementSlots: bots.filter((bot) => bot.lane === 'bot' && bot.slot >= Math.floor(players / 2)).length,
206
+ humanInputSlots,
207
+ botInputSlots,
208
+ mixedHumanBotLanes: humanInputSlots > 0 && botInputSlots > 0,
209
+ };
210
+ }
211
+ function stepBotFrame(bots, frame, seed, hfsm, tree, utility) {
212
+ return bots.map((bot) => {
213
+ const threat = (seed + frame + bot.slot) % 10;
214
+ const health = Math.max(0, bot.hp - ((frame + bot.slot) % 17 === 0 ? 1 : 0));
215
+ const blackboard = createDeterministicBotBlackboard([
216
+ { key: 'health', value: health },
217
+ { key: 'hasTarget', value: true },
218
+ { key: 'threat', value: threat },
219
+ { key: 'ammo', value: 5 - ((frame + bot.slot) % 5) },
220
+ { key: 'lastActionAttack', value: bot.utility > 5_000 },
221
+ { key: 'attackCooldown', value: (frame + bot.slot) % 11 === 0 ? 2 : 0 },
222
+ { key: 'frame', value: frame },
223
+ ]);
224
+ const nextHfsm = tickDeterministicHfsm(hfsm, bot.hfsm, blackboard);
225
+ const treeTick = tickDeterministicBehaviorTreeWithMemory(tree, blackboard, bot.behaviorMemory);
226
+ const selected = selectDeterministicUtility(utility, blackboard);
227
+ return {
228
+ slot: bot.slot,
229
+ lane: bot.lane,
230
+ hp: health,
231
+ hfsm: nextHfsm,
232
+ target: (bot.slot + 1 + (selected.action === 'flank' ? 1 : 0)) % bots.length,
233
+ utility: selected.score,
234
+ utilityScoreBreakdown: selected.scores,
235
+ behaviorActions: treeTick.actions,
236
+ behaviorServiceActions: treeTick.serviceActions,
237
+ behaviorStatus: treeTick.status,
238
+ visitedBehaviorNodes: treeTick.visitedNodeIds,
239
+ behaviorMemory: treeTick.memory,
240
+ };
241
+ });
242
+ }
243
+ function evaluateBehaviorTree(node, blackboard, visitedNodeIds, actions) {
244
+ visitedNodeIds.push(node.id);
245
+ if (node.type === 'condition') {
246
+ return getBlackboardValue(blackboard, node.key) === node.equals ? 'success' : 'failure';
247
+ }
248
+ if (node.type === 'action') {
249
+ actions.push(node.action);
250
+ return node.status ?? 'success';
251
+ }
252
+ if (node.type === 'decorator') {
253
+ const status = evaluateBehaviorTree(node.child, blackboard, visitedNodeIds, actions);
254
+ if (node.mode === 'force-success') {
255
+ return 'success';
256
+ }
257
+ if (node.mode === 'force-failure') {
258
+ return 'failure';
259
+ }
260
+ if (status === 'success') {
261
+ return 'failure';
262
+ }
263
+ if (status === 'failure') {
264
+ return 'success';
265
+ }
266
+ return 'running';
267
+ }
268
+ if (node.type === 'sequence') {
269
+ for (const child of node.children) {
270
+ const status = evaluateBehaviorTree(child, blackboard, visitedNodeIds, actions);
271
+ if (status !== 'success') {
272
+ return status;
273
+ }
274
+ }
275
+ return 'success';
276
+ }
277
+ for (const child of node.children) {
278
+ const status = evaluateBehaviorTree(child, blackboard, visitedNodeIds, actions);
279
+ if (status !== 'failure') {
280
+ return status;
281
+ }
282
+ }
283
+ return 'failure';
284
+ }
285
+ function evaluateBehaviorTreeWithMemory(node, blackboard, visitedNodeIds, actions, resumedNodeIds, serviceActions, serviceNodeIds, memory) {
286
+ visitedNodeIds.push(node.id);
287
+ runBehaviorTreeServices(node, blackboard, serviceActions, serviceNodeIds);
288
+ if (node.type === 'condition') {
289
+ return getBlackboardValue(blackboard, node.key) === node.equals ? 'success' : 'failure';
290
+ }
291
+ if (node.type === 'action') {
292
+ actions.push(node.action);
293
+ if (node.status !== 'running') {
294
+ removeRunningNode(memory, node.id);
295
+ return node.status ?? 'success';
296
+ }
297
+ if (memory.runningNodeIds.includes(node.id)) {
298
+ removeRunningNode(memory, node.id);
299
+ if (!memory.completedRunningNodeIds.includes(node.id)) {
300
+ memory.completedRunningNodeIds.push(node.id);
301
+ }
302
+ resumedNodeIds.push(node.id);
303
+ return 'success';
304
+ }
305
+ if (!memory.completedRunningNodeIds.includes(node.id)) {
306
+ memory.runningNodeIds.push(node.id);
307
+ return 'running';
308
+ }
309
+ return 'success';
310
+ }
311
+ if (node.type === 'decorator') {
312
+ const status = evaluateBehaviorTreeWithMemory(node.child, blackboard, visitedNodeIds, actions, resumedNodeIds, serviceActions, serviceNodeIds, memory);
313
+ if (node.mode === 'force-success') {
314
+ return 'success';
315
+ }
316
+ if (node.mode === 'force-failure') {
317
+ return 'failure';
318
+ }
319
+ if (status === 'success') {
320
+ return 'failure';
321
+ }
322
+ if (status === 'failure') {
323
+ return 'success';
324
+ }
325
+ return 'running';
326
+ }
327
+ if (node.type === 'sequence') {
328
+ for (const child of node.children) {
329
+ const status = evaluateBehaviorTreeWithMemory(child, blackboard, visitedNodeIds, actions, resumedNodeIds, serviceActions, serviceNodeIds, memory);
330
+ if (status !== 'success') {
331
+ return status;
332
+ }
333
+ }
334
+ return 'success';
335
+ }
336
+ for (const child of node.children) {
337
+ const status = evaluateBehaviorTreeWithMemory(child, blackboard, visitedNodeIds, actions, resumedNodeIds, serviceActions, serviceNodeIds, memory);
338
+ if (status !== 'failure') {
339
+ return status;
340
+ }
341
+ }
342
+ return 'failure';
343
+ }
344
+ function runBehaviorTreeServices(node, blackboard, serviceActions, serviceNodeIds) {
345
+ const frame = getBlackboardValue(blackboard, 'frame');
346
+ const frameNumber = typeof frame === 'number' ? frame : 0;
347
+ for (const service of [...(node.services ?? [])].sort((left, right) => compareStrings(left.id, right.id))) {
348
+ if (service.intervalFrames <= 0) {
349
+ throw new Error(`Behavior service ${service.id} interval must be positive`);
350
+ }
351
+ if (frameNumber % service.intervalFrames === 0) {
352
+ serviceActions.push(service.action);
353
+ serviceNodeIds.push(`service:${service.id}`);
354
+ }
355
+ }
356
+ }
357
+ function scoreUtilityInput(value, min, max, weight, curve) {
358
+ const numericValue = typeof value === 'number' ? value : value === true ? max : min;
359
+ const clamped = Math.max(min, Math.min(max, numericValue));
360
+ const range = Math.max(1, max - min);
361
+ const linear = Math.trunc(((clamped - min) * 1_000) / range);
362
+ const curved = curve === 'inverse'
363
+ ? 1_000 - linear
364
+ : curve === 'quadratic'
365
+ ? Math.trunc((linear * linear) / 1_000)
366
+ : curve === 'step'
367
+ ? linear >= 500 ? 1_000 : 0
368
+ : linear;
369
+ return Math.trunc(curved * weight);
370
+ }
371
+ function removeRunningNode(memory, nodeId) {
372
+ memory.runningNodeIds = memory.runningNodeIds.filter((id) => id !== nodeId);
373
+ }
374
+ function normalizeHfsm(definition) {
375
+ return {
376
+ initialState: definition.initialState,
377
+ states: [...definition.states].sort((left, right) => compareStrings(left.id, right.id)),
378
+ transitions: [...definition.transitions].sort(compareTransitions),
379
+ };
380
+ }
381
+ function normalizeBehaviorTree(node) {
382
+ if (node.type === 'action' || node.type === 'condition') {
383
+ return { ...node, services: normalizeBehaviorServices(node.services) };
384
+ }
385
+ if (node.type === 'decorator') {
386
+ return { ...node, services: normalizeBehaviorServices(node.services), child: normalizeBehaviorTree(node.child) };
387
+ }
388
+ return {
389
+ ...node,
390
+ services: normalizeBehaviorServices(node.services),
391
+ children: node.children.map(normalizeBehaviorTree),
392
+ };
393
+ }
394
+ function normalizeBehaviorServices(services) {
395
+ if (services === undefined) {
396
+ return undefined;
397
+ }
398
+ return [...services].sort((left, right) => compareStrings(left.id, right.id));
399
+ }
400
+ function compareTransitions(left, right) {
401
+ return compareStrings(`${left.from}:${left.whenKey}:${left.to}`, `${right.from}:${right.whenKey}:${right.to}`);
402
+ }
403
+ function compareStrings(left, right) {
404
+ return left < right ? -1 : left > right ? 1 : 0;
405
+ }
406
+ function defaultHfsm() {
407
+ return {
408
+ initialState: 'idle',
409
+ states: [
410
+ { id: 'idle', action: 'wait' },
411
+ { id: 'seek', action: 'move' },
412
+ { id: 'attack', parent: 'seek', action: 'fire' },
413
+ { id: 'retreat', action: 'fallback' },
414
+ ],
415
+ transitions: [
416
+ { from: 'idle', to: 'seek', whenKey: 'hasTarget', equals: true },
417
+ { from: 'seek', to: 'attack', whenKey: 'threat', equals: 7 },
418
+ { from: 'attack', to: 'retreat', whenKey: 'health', equals: 3 },
419
+ { from: 'retreat', to: 'seek', whenKey: 'health', equals: 8 },
420
+ ],
421
+ };
422
+ }
423
+ function defaultBehaviorTree() {
424
+ return {
425
+ id: 'root',
426
+ type: 'selector',
427
+ services: [{ id: 'root-targeting-service', action: 'update-target', intervalFrames: 3 }],
428
+ children: [
429
+ {
430
+ id: 'attack-sequence',
431
+ type: 'sequence',
432
+ children: [
433
+ { id: 'has-target', type: 'condition', key: 'hasTarget', equals: true },
434
+ {
435
+ id: 'maybe-patrol',
436
+ type: 'decorator',
437
+ mode: 'force-success',
438
+ child: { id: 'patrol-if-calm', type: 'condition', key: 'threat', equals: 0 },
439
+ },
440
+ {
441
+ id: 'windup-if-danger',
442
+ type: 'selector',
443
+ children: [
444
+ {
445
+ id: 'danger-windup',
446
+ type: 'sequence',
447
+ children: [
448
+ { id: 'is-dangerous', type: 'condition', key: 'threat', equals: 9 },
449
+ { id: 'windup-action', type: 'action', action: 'windup', status: 'running' },
450
+ ],
451
+ },
452
+ { id: 'ready-action', type: 'action', action: 'ready' },
453
+ ],
454
+ },
455
+ { id: 'attack-action', type: 'action', action: 'attack' },
456
+ ],
457
+ },
458
+ { id: 'idle-action', type: 'action', action: 'idle' },
459
+ ],
460
+ };
461
+ }
462
+ function defaultUtility() {
463
+ return [
464
+ {
465
+ id: 'attack',
466
+ inputKey: 'threat',
467
+ action: 'attack',
468
+ min: 0,
469
+ max: 9,
470
+ weight: 7,
471
+ rank: 2,
472
+ curve: 'quadratic',
473
+ momentumKey: 'lastActionAttack',
474
+ momentum: 2_000,
475
+ cooldownKey: 'attackCooldown',
476
+ cooldownPenalty: 3_000,
477
+ nested: [{ id: 'ammo-ready', inputKey: 'ammo', min: 0, max: 5, weight: 2, curve: 'step' }],
478
+ },
479
+ { id: 'flank', inputKey: 'threat', action: 'flank', min: 0, max: 9, weight: 6, rank: 1, curve: 'linear' },
480
+ { id: 'retreat', inputKey: 'health', action: 'retreat', min: 0, max: 10, weight: 5, curve: 'inverse' },
481
+ ];
482
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createSyncplayClient = exports.stepDeterministicButton = exports.runDeterministicDescriptorButtonFixture = exports.runDeterministicButtonFixture = exports.deterministicButtonInitialState = exports.interpolateDeterministicRenderVec2 = exports.interpolateDeterministicRenderNumber = exports.createDeterministicR3fRenderAdapter = exports.createDeterministicR3fAdapter = exports.runFixedArenaExample = exports.projectFixedArenaRenderState = exports.projectFixedArenaReferenceView = exports.fixedArenaStep = exports.fixedArenaDefaultInput = exports.createInitialFixedArenaState = exports.createFixedArenaDescriptor = exports.labStep = exports.labDefaultInput = exports.hydrateLabInput = exports.runDeterministicEngineCoreNumericProof = exports.runNumberLab = exports.createSyncplayGameRuntime = exports.createSyncplayOfflineRuntime = exports.createOfflineSession = exports.verifyDeterministicReplay = exports.verifyReplay = void 0;
18
+ var replay_js_1 = require("./replay.js");
19
+ Object.defineProperty(exports, "verifyReplay", { enumerable: true, get: function () { return replay_js_1.verifyReplay; } });
20
+ var replay_js_2 = require("./replay.js");
21
+ Object.defineProperty(exports, "verifyDeterministicReplay", { enumerable: true, get: function () { return replay_js_2.verifyReplayWithDescriptor; } });
22
+ var offline_session_js_1 = require("./offline-session.js");
23
+ Object.defineProperty(exports, "createOfflineSession", { enumerable: true, get: function () { return offline_session_js_1.createOfflineSession; } });
24
+ var sdk_offline_js_1 = require("./sdk-offline.js");
25
+ Object.defineProperty(exports, "createSyncplayOfflineRuntime", { enumerable: true, get: function () { return sdk_offline_js_1.createSyncplayOfflineRuntime; } });
26
+ var sdk_offline_js_2 = require("./sdk-offline.js");
27
+ Object.defineProperty(exports, "createSyncplayGameRuntime", { enumerable: true, get: function () { return sdk_offline_js_2.createSyncplayOfflineRuntime; } });
28
+ var number_lab_js_1 = require("./number-lab.js");
29
+ Object.defineProperty(exports, "runNumberLab", { enumerable: true, get: function () { return number_lab_js_1.runNumberLab; } });
30
+ var engine_core_proof_js_1 = require("./engine-core-proof.js");
31
+ Object.defineProperty(exports, "runDeterministicEngineCoreNumericProof", { enumerable: true, get: function () { return engine_core_proof_js_1.runDeterministicEngineCoreNumericProof; } });
32
+ var sample_lab_js_1 = require("./sample-lab.js");
33
+ Object.defineProperty(exports, "hydrateLabInput", { enumerable: true, get: function () { return sample_lab_js_1.hydrateLabInput; } });
34
+ Object.defineProperty(exports, "labDefaultInput", { enumerable: true, get: function () { return sample_lab_js_1.labDefaultInput; } });
35
+ Object.defineProperty(exports, "labStep", { enumerable: true, get: function () { return sample_lab_js_1.labStep; } });
36
+ var fixed_arena_js_1 = require("./examples/fixed-arena.js");
37
+ Object.defineProperty(exports, "createFixedArenaDescriptor", { enumerable: true, get: function () { return fixed_arena_js_1.createFixedArenaDescriptor; } });
38
+ Object.defineProperty(exports, "createInitialFixedArenaState", { enumerable: true, get: function () { return fixed_arena_js_1.createInitialFixedArenaState; } });
39
+ Object.defineProperty(exports, "fixedArenaDefaultInput", { enumerable: true, get: function () { return fixed_arena_js_1.fixedArenaDefaultInput; } });
40
+ Object.defineProperty(exports, "fixedArenaStep", { enumerable: true, get: function () { return fixed_arena_js_1.fixedArenaStep; } });
41
+ Object.defineProperty(exports, "projectFixedArenaReferenceView", { enumerable: true, get: function () { return fixed_arena_js_1.projectFixedArenaReferenceView; } });
42
+ Object.defineProperty(exports, "projectFixedArenaRenderState", { enumerable: true, get: function () { return fixed_arena_js_1.projectFixedArenaRenderState; } });
43
+ Object.defineProperty(exports, "runFixedArenaExample", { enumerable: true, get: function () { return fixed_arena_js_1.runFixedArenaExample; } });
44
+ var r3f_render_adapter_js_1 = require("./r3f-render-adapter.js");
45
+ Object.defineProperty(exports, "createDeterministicR3fAdapter", { enumerable: true, get: function () { return r3f_render_adapter_js_1.createDeterministicR3fRenderAdapter; } });
46
+ Object.defineProperty(exports, "createDeterministicR3fRenderAdapter", { enumerable: true, get: function () { return r3f_render_adapter_js_1.createDeterministicR3fRenderAdapter; } });
47
+ Object.defineProperty(exports, "interpolateDeterministicRenderNumber", { enumerable: true, get: function () { return r3f_render_adapter_js_1.interpolateDeterministicRenderNumber; } });
48
+ Object.defineProperty(exports, "interpolateDeterministicRenderVec2", { enumerable: true, get: function () { return r3f_render_adapter_js_1.interpolateDeterministicRenderVec2; } });
49
+ __exportStar(require("./animation.js"), exports);
50
+ __exportStar(require("./asset-cooking.js"), exports);
51
+ __exportStar(require("./bot-documents.js"), exports);
52
+ __exportStar(require("./bot-primitives.js"), exports);
53
+ __exportStar(require("./canonical.js"), exports);
54
+ __exportStar(require("./collections.js"), exports);
55
+ __exportStar(require("./commands.js"), exports);
56
+ __exportStar(require("./config-bundle.js"), exports);
57
+ __exportStar(require("./deterministic-session.js"), exports);
58
+ __exportStar(require("./effects-adapter.js"), exports);
59
+ __exportStar(require("./engine-runtime.js"), exports);
60
+ __exportStar(require("./events.js"), exports);
61
+ var input_button_js_1 = require("./input-button.js");
62
+ Object.defineProperty(exports, "deterministicButtonInitialState", { enumerable: true, get: function () { return input_button_js_1.deterministicButtonInitialState; } });
63
+ Object.defineProperty(exports, "runDeterministicButtonFixture", { enumerable: true, get: function () { return input_button_js_1.runDeterministicButtonFixture; } });
64
+ Object.defineProperty(exports, "runDeterministicDescriptorButtonFixture", { enumerable: true, get: function () { return input_button_js_1.runDeterministicDescriptorButtonFixture; } });
65
+ Object.defineProperty(exports, "stepDeterministicButton", { enumerable: true, get: function () { return input_button_js_1.stepDeterministicButton; } });
66
+ __exportStar(require("./input-timeline.js"), exports);
67
+ __exportStar(require("./instant-replay.js"), exports);
68
+ __exportStar(require("./pause-resume.js"), exports);
69
+ __exportStar(require("./session-promotion.js"), exports);
70
+ __exportStar(require("./lag-compensation3d.js"), exports);
71
+ __exportStar(require("./local-authority.js"), exports);
72
+ __exportStar(require("./local-authority-wire.js"), exports);
73
+ __exportStar(require("./input-authority.js"), exports);
74
+ __exportStar(require("./session-wire.js"), exports);
75
+ __exportStar(require("./session-snapshot.js"), exports);
76
+ __exportStar(require("./authority-room.js"), exports);
77
+ __exportStar(require("./networked-client.js"), exports);
78
+ __exportStar(require("./math.js"), exports);
79
+ var multiplayer_service_js_1 = require("./multiplayer-service.js");
80
+ Object.defineProperty(exports, "createSyncplayClient", { enumerable: true, get: function () { return multiplayer_service_js_1.createSyncplayClient; } });
81
+ __exportStar(require("./movement.js"), exports);
82
+ __exportStar(require("./movement3d.js"), exports);
83
+ __exportStar(require("./navigation.js"), exports);
84
+ __exportStar(require("./navmesh.js"), exports);
85
+ __exportStar(require("./collision.js"), exports);
86
+ __exportStar(require("./physics2d.js"), exports);
87
+ __exportStar(require("./physics3d.js"), exports);
88
+ __exportStar(require("./replay-bundle.js"), exports);
89
+ __exportStar(require("./schema.js"), exports);
90
+ __exportStar(require("./schema-artifacts.js"), exports);
91
+ __exportStar(require("./schema-codegen.js"), exports);
92
+ __exportStar(require("./schema-dsl-binary.js"), exports);
93
+ __exportStar(require("./signals.js"), exports);
94
+ __exportStar(require("./sparse-set.js"), exports);
95
+ __exportStar(require("./sample-scenes.js"), exports);
96
+ __exportStar(require("./system-lifecycle.js"), exports);