@reicek/neataptic-ts 0.1.21 → 0.1.22

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 (223) hide show
  1. package/.github/agents/boundary-mapper.agent.md +29 -0
  2. package/.github/agents/docs-scout.agent.md +29 -0
  3. package/.github/agents/plan-scout.agent.md +29 -0
  4. package/.github/agents/solid-split.agent.md +138 -0
  5. package/.github/copilot-instructions.md +103 -0
  6. package/package.json +6 -3
  7. package/plans/ES2023 migration +13 -8
  8. package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
  9. package/plans/Interactive_Examples_and_Learning_Path.md +10 -2
  10. package/plans/Memory_Optimization.md +3 -3
  11. package/plans/README.md +63 -0
  12. package/plans/Roadmap.md +15 -3
  13. package/plans/asciiMaze_SOLID_split.done.md +130 -0
  14. package/plans/flappy_bird_SOLID_split.done.md +67 -0
  15. package/scripts/assets/theme.css +221 -34
  16. package/scripts/copy-examples.mjs +9 -5
  17. package/scripts/export-onnx.mjs +3 -3
  18. package/scripts/generate-bench-tables.mjs +10 -10
  19. package/scripts/generate-bench-tables.ts +10 -10
  20. package/scripts/generate-docs.ts +1415 -449
  21. package/scripts/render-docs-html.ts +15 -8
  22. package/src/README.md +101 -223
  23. package/src/architecture/README.md +57 -185
  24. package/src/architecture/layer/README.md +38 -38
  25. package/src/architecture/network/README.md +33 -31
  26. package/src/architecture/network/activate/README.md +77 -77
  27. package/src/architecture/network/connect/README.md +15 -13
  28. package/src/architecture/network/deterministic/README.md +7 -7
  29. package/src/architecture/network/evolve/README.md +44 -44
  30. package/src/architecture/network/gating/README.md +20 -20
  31. package/src/architecture/network/genetic/README.md +51 -51
  32. package/src/architecture/network/mutate/README.md +97 -97
  33. package/src/architecture/network/onnx/README.md +264 -264
  34. package/src/architecture/network/prune/README.md +39 -39
  35. package/src/architecture/network/remove/README.md +26 -26
  36. package/src/architecture/network/serialize/README.md +56 -56
  37. package/src/architecture/network/slab/README.md +61 -61
  38. package/src/architecture/network/standalone/README.md +24 -24
  39. package/src/architecture/network/stats/README.md +9 -9
  40. package/src/architecture/network/topology/README.md +46 -46
  41. package/src/architecture/network/training/README.md +21 -21
  42. package/src/methods/README.md +9 -87
  43. package/src/multithreading/README.md +8 -77
  44. package/src/multithreading/workers/README.md +2 -2
  45. package/src/multithreading/workers/browser/README.md +0 -6
  46. package/src/multithreading/workers/node/README.md +0 -3
  47. package/src/neat/README.md +562 -568
  48. package/src/utils/README.md +18 -18
  49. package/test/examples/asciiMaze/README.md +59 -59
  50. package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +14 -9
  51. package/test/examples/asciiMaze/browser-entry/README.md +196 -0
  52. package/test/examples/asciiMaze/browser-entry/browser-entry.abort.services.ts +95 -0
  53. package/test/examples/asciiMaze/browser-entry/browser-entry.constants.ts +23 -0
  54. package/test/examples/asciiMaze/browser-entry/browser-entry.curriculum.services.ts +115 -0
  55. package/test/examples/asciiMaze/browser-entry/browser-entry.globals.services.ts +106 -0
  56. package/test/examples/asciiMaze/browser-entry/browser-entry.host.services.ts +157 -0
  57. package/test/examples/asciiMaze/browser-entry/browser-entry.services.ts +14 -0
  58. package/test/examples/asciiMaze/browser-entry/browser-entry.ts +129 -0
  59. package/test/examples/asciiMaze/browser-entry/browser-entry.types.ts +120 -0
  60. package/test/examples/asciiMaze/browser-entry/browser-entry.utils.ts +98 -0
  61. package/test/examples/asciiMaze/browser-entry.ts +10 -576
  62. package/test/examples/asciiMaze/dashboardManager/README.md +276 -0
  63. package/test/examples/asciiMaze/dashboardManager/archive/README.md +16 -0
  64. package/test/examples/asciiMaze/dashboardManager/archive/dashboardManager.archive.services.ts +267 -0
  65. package/test/examples/asciiMaze/dashboardManager/dashboardManager.constants.ts +35 -0
  66. package/test/examples/asciiMaze/dashboardManager/dashboardManager.services.ts +103 -0
  67. package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +181 -0
  68. package/test/examples/asciiMaze/dashboardManager/dashboardManager.types.ts +267 -0
  69. package/test/examples/asciiMaze/dashboardManager/dashboardManager.utils.ts +254 -0
  70. package/test/examples/asciiMaze/dashboardManager/live/README.md +14 -0
  71. package/test/examples/asciiMaze/dashboardManager/live/dashboardManager.live.services.ts +264 -0
  72. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +47 -0
  73. package/test/examples/asciiMaze/dashboardManager/telemetry/dashboardManager.telemetry.services.ts +513 -0
  74. package/test/examples/asciiMaze/dashboardManager.ts +13 -2335
  75. package/test/examples/asciiMaze/evolutionEngine/README.md +1058 -0
  76. package/test/examples/asciiMaze/evolutionEngine/curriculumPhase.ts +90 -0
  77. package/test/examples/asciiMaze/evolutionEngine/engineState.constants.ts +36 -0
  78. package/test/examples/asciiMaze/evolutionEngine/engineState.ts +58 -513
  79. package/test/examples/asciiMaze/evolutionEngine/engineState.types.ts +212 -0
  80. package/test/examples/asciiMaze/evolutionEngine/engineState.utils.ts +301 -0
  81. package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +445 -0
  82. package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +81 -50
  83. package/test/examples/asciiMaze/evolutionEngine/optionsAndSetup.ts +2 -4
  84. package/test/examples/asciiMaze/evolutionEngine/populationDynamics.ts +17 -33
  85. package/test/examples/asciiMaze/evolutionEngine/populationPruning.ts +1 -1
  86. package/test/examples/asciiMaze/evolutionEngine/rngAndTiming.ts +1 -2
  87. package/test/examples/asciiMaze/evolutionEngine/sampling.ts +1 -1
  88. package/test/examples/asciiMaze/evolutionEngine/scratchPools.ts +2 -5
  89. package/test/examples/asciiMaze/evolutionEngine/setupHelpers.ts +30 -37
  90. package/test/examples/asciiMaze/evolutionEngine/telemetryMetrics.ts +16 -58
  91. package/test/examples/asciiMaze/evolutionEngine/trainingWarmStart.ts +2 -2
  92. package/test/examples/asciiMaze/evolutionEngine.ts +55 -55
  93. package/test/examples/asciiMaze/fitness.ts +2 -2
  94. package/test/examples/asciiMaze/fitness.types.ts +65 -0
  95. package/test/examples/asciiMaze/interfaces.ts +64 -1352
  96. package/test/examples/asciiMaze/mazeMovement/README.md +356 -0
  97. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +49 -0
  98. package/test/examples/asciiMaze/mazeMovement/finalization/mazeMovement.finalization.ts +138 -0
  99. package/test/examples/asciiMaze/mazeMovement/mazeMovement.constants.ts +101 -0
  100. package/test/examples/asciiMaze/mazeMovement/mazeMovement.services.ts +230 -0
  101. package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +299 -0
  102. package/test/examples/asciiMaze/mazeMovement/mazeMovement.types.ts +185 -0
  103. package/test/examples/asciiMaze/mazeMovement/mazeMovement.utils.ts +153 -0
  104. package/test/examples/asciiMaze/mazeMovement/policy/README.md +91 -0
  105. package/test/examples/asciiMaze/mazeMovement/policy/mazeMovement.policy.ts +467 -0
  106. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +95 -0
  107. package/test/examples/asciiMaze/mazeMovement/runtime/mazeMovement.runtime.ts +354 -0
  108. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +124 -0
  109. package/test/examples/asciiMaze/mazeMovement/shaping/mazeMovement.shaping.ts +459 -0
  110. package/test/examples/asciiMaze/mazeMovement.ts +12 -2978
  111. package/test/examples/flappy_bird/Trace-20260309T191949.json +24124 -0
  112. package/test/examples/flappy_bird/browser-entry/README.md +1129 -0
  113. package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +4 -324
  114. package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +6 -399
  115. package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +1 -717
  116. package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
  117. package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +15 -893
  118. package/test/examples/flappy_bird/browser-entry/host/README.md +307 -0
  119. package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
  120. package/test/examples/flappy_bird/browser-entry/host/host.ts +562 -6
  121. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +274 -0
  122. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +31 -0
  123. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +360 -0
  124. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +117 -0
  125. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +63 -0
  126. package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +250 -0
  127. package/test/examples/flappy_bird/browser-entry/network-view/README.md +399 -0
  128. package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +255 -0
  129. package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +802 -7
  130. package/test/examples/flappy_bird/browser-entry/playback/README.md +684 -0
  131. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +277 -0
  132. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +770 -0
  133. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +178 -0
  134. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +107 -0
  135. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +518 -0
  136. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +117 -0
  137. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +233 -0
  138. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +211 -0
  139. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.ts +48 -0
  140. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.types.ts +212 -0
  141. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +81 -0
  142. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.cache.services.ts +96 -0
  143. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.constants.ts +62 -0
  144. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +244 -0
  145. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.ts +53 -0
  146. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.types.ts +68 -0
  147. package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.utils.ts +100 -0
  148. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +310 -0
  149. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +92 -0
  150. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +272 -0
  151. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +39 -0
  152. package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +493 -0
  153. package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +1 -1
  154. package/test/examples/flappy_bird/browser-entry/playback/playback.frame-render.service.ts +4 -0
  155. package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +44 -0
  156. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +39 -122
  157. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +272 -0
  158. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +62 -0
  159. package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
  160. package/test/examples/flappy_bird/browser-entry/playback/playback.ts +409 -8
  161. package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +4 -12
  162. package/test/examples/flappy_bird/browser-entry/runtime/README.md +235 -0
  163. package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +45 -0
  164. package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +81 -0
  165. package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +74 -0
  166. package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
  167. package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +36 -0
  168. package/test/examples/flappy_bird/browser-entry/visualization/README.md +557 -0
  169. package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +110 -0
  170. package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +957 -19
  171. package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +138 -3
  172. package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +3 -27
  173. package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +1 -23
  174. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +156 -0
  175. package/test/examples/flappy_bird/constants/README.md +1179 -0
  176. package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
  177. package/test/examples/flappy_bird/constants/constants.palette.ts +7 -0
  178. package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
  179. package/test/examples/flappy_bird/environment/README.md +143 -0
  180. package/test/examples/flappy_bird/environment/environment.observation.utils.ts +1 -19
  181. package/test/examples/flappy_bird/environment/environment.step.service.ts +3 -66
  182. package/test/examples/flappy_bird/evaluation/README.md +130 -0
  183. package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +1 -1
  184. package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +5 -375
  185. package/test/examples/flappy_bird/evaluation/rollout/README.md +291 -0
  186. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +30 -0
  187. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +58 -0
  188. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +310 -0
  189. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +56 -0
  190. package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +368 -0
  191. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +618 -0
  192. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +7 -7
  193. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +364 -0
  194. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +14 -0
  195. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +4 -201
  196. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +184 -345
  197. package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +291 -0
  198. package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +5 -0
  199. package/test/examples/flappy_bird/simulation-shared/README.md +417 -0
  200. package/test/examples/flappy_bird/simulation-shared/observation/README.md +183 -0
  201. package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +301 -0
  202. package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +9 -0
  203. package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +59 -0
  204. package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +5 -403
  205. package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +20 -6
  206. package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +23 -8
  207. package/test/examples/flappy_bird/trainer/README.md +563 -0
  208. package/test/examples/flappy_bird/trainer/evaluation/README.md +199 -0
  209. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +9 -0
  210. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +73 -0
  211. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +165 -0
  212. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +25 -0
  213. package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +161 -0
  214. package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
  215. package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
  216. package/test/examples/flappy_bird/trainer/trainer.report.service.ts +126 -0
  217. package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
  218. package/test/examples/flappy_bird/trainer/trainer.ts +11 -553
  219. package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +0 -12
  220. package/test/examples/flappy_bird/environment/environment.ts +0 -7
  221. package/test/examples/flappy_bird/evaluation/evaluation.ts +0 -7
  222. package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +0 -15
  223. package/test/examples/flappy_bird/trainer/trainer.statistics.utils.ts +0 -78
@@ -41,9 +41,15 @@ export const FLAPPY_NETWORK_GRAPH_RIGHT_PADDING_PX = 20;
41
41
  /** Graph-bottom padding for network visualization content. */
42
42
  export const FLAPPY_NETWORK_GRAPH_BOTTOM_PADDING_PX = 18;
43
43
 
44
+ /** Minimum drawable graph dimension after padding is removed. */
45
+ export const FLAPPY_NETWORK_MIN_DRAWABLE_SIZE_PX = 1;
46
+
44
47
  /** Gap between graph body and floating legend panel. */
45
48
  export const FLAPPY_NETWORK_LEGEND_GRAPH_GAP_PX = 10;
46
49
 
50
+ /** Ratio used to decide whether the legend occupies the right half of the canvas. */
51
+ export const FLAPPY_NETWORK_LEGEND_RIGHT_SIDE_THRESHOLD_RATIO = 0.5;
52
+
47
53
  /** Inner node-layout padding inside drawable network region. */
48
54
  export const FLAPPY_NETWORK_NODE_LAYOUT_PADDING_PX = 2;
49
55
 
@@ -161,6 +167,9 @@ export const FLAPPY_NETWORK_HEADER_FONT_SIZE_PX = 11;
161
167
  /** Extra pixel allowance above label baseline for minimum node-height readability. */
162
168
  export const FLAPPY_NETWORK_MIN_NODE_HEIGHT_LABEL_EXTRA_PX = 4;
163
169
 
170
+ /** Minimum fit-based node height before width and label constraints are applied. */
171
+ export const FLAPPY_NETWORK_MIN_NODE_FIT_HEIGHT_PX = 4;
172
+
164
173
  /**
165
174
  * Layer-fit divisor used when deriving max node height from dense layer stacks.
166
175
  *
@@ -215,3 +224,18 @@ export const FLAPPY_NETWORK_INPUT_GROUP_LABEL_FONT_WEIGHT = 700;
215
224
 
216
225
  /** Text color for vertical input-group labels on neon backgrounds. */
217
226
  export const FLAPPY_NETWORK_INPUT_GROUP_LABEL_TEXT_COLOR = '#000000';
227
+
228
+ /** Placeholder label used when the network has no hidden layers. */
229
+ export const FLAPPY_NETWORK_EMPTY_HIDDEN_LAYER_LABEL = '-';
230
+
231
+ /** Prefix used when hidden-layer counts are inferred rather than declared. */
232
+ export const FLAPPY_NETWORK_INFERRED_HIDDEN_LAYER_PREFIX = '~';
233
+
234
+ /** Separator used between hidden-layer sizes inside architecture labels. */
235
+ export const FLAPPY_NETWORK_HIDDEN_LAYER_SEPARATOR = ' - ';
236
+
237
+ /** Separator used between architecture columns in the compact header label. */
238
+ export const FLAPPY_NETWORK_ARCHITECTURE_COLUMN_SEPARATOR = ' | ';
239
+
240
+ /** Line separator used by the two-line architecture label block. */
241
+ export const FLAPPY_NETWORK_ARCHITECTURE_LINE_SEPARATOR = '\n';
@@ -22,6 +22,13 @@ export const FLAPPY_NEON_PALETTE = {
22
22
  hudAccent: '#ff9a2e',
23
23
  hudPanelBackground: '#000000',
24
24
  hudPanelBorder: '#0fb5ff',
25
+ horizonLine: '#0a8ea0',
26
+ horizonGlow: 'rgba(10, 142, 160, 0.95)',
27
+ groundGridLine: '#0a8ea0',
28
+ groundGridGlow: 'rgba(10, 142, 160, 0.9)',
29
+ groundGridFog: 'rgba(10, 142, 160, 0.55)',
30
+ groundGridPulseFill: '#8ef3ff',
31
+ groundGridPulseGlow: 'rgba(142, 243, 255, 0.92)',
25
32
  } as const;
26
33
 
27
34
  /** Neon bird palette for per-agent render color assignment. */
@@ -10,6 +10,42 @@ import { FLAPPY_WORLD_HEIGHT_PX } from './constants.world';
10
10
  /** Width of one repeated starfield tile (pixels). */
11
11
  export const FLAPPY_STARFIELD_TILE_WIDTH_PX = 512;
12
12
 
13
+ /** Minimum positive dimension allowed for generated starfield canvases. */
14
+ export const FLAPPY_STARFIELD_MIN_DIMENSION_PX = 1;
15
+
16
+ /** Zero pixel origin used for starfield canvas clears and draws. */
17
+ export const FLAPPY_STARFIELD_ORIGIN_PX = 0;
18
+
19
+ /** Canvas rendering context identifier used for starfield tile generation. */
20
+ export const FLAPPY_STARFIELD_CANVAS_CONTEXT_ID = '2d';
21
+
22
+ /** Composite mode used for normal starfield canvas drawing passes. */
23
+ export const FLAPPY_STARFIELD_COMPOSITE_SOURCE_OVER = 'source-over';
24
+
25
+ /** Transparent shadow reset value used after glow drawing. */
26
+ export const FLAPPY_STARFIELD_TRANSPARENT_SHADOW_COLOR = 'transparent';
27
+
28
+ /** Default fully opaque alpha restored after tile generation. */
29
+ export const FLAPPY_STARFIELD_FULL_ALPHA = 1;
30
+
31
+ /** Blur reset value used after the star glow pass. */
32
+ export const FLAPPY_STARFIELD_NO_BLUR_PX = 0;
33
+
34
+ /** Inclusive range offset used when converting size bounds into random spans. */
35
+ export const FLAPPY_STARFIELD_INCLUSIVE_RANGE_OFFSET = 1;
36
+
37
+ /** Divisor that normalizes unsigned 32-bit RNG state into the unit interval. */
38
+ export const FLAPPY_STARFIELD_UNSIGNED_NORMALIZATION_DIVISOR = 0x1_0000_0000;
39
+
40
+ /** Primary left-shift used by the xorshift32 random transition. */
41
+ export const FLAPPY_STARFIELD_XORSHIFT_LEFT_SHIFT_PRIMARY = 13;
42
+
43
+ /** Middle right-shift used by the xorshift32 random transition. */
44
+ export const FLAPPY_STARFIELD_XORSHIFT_RIGHT_SHIFT = 17;
45
+
46
+ /** Final left-shift used by the xorshift32 random transition. */
47
+ export const FLAPPY_STARFIELD_XORSHIFT_LEFT_SHIFT_FINAL = 5;
48
+
13
49
  /** Height of one repeated starfield tile (pixels). */
14
50
  export const FLAPPY_STARFIELD_TILE_HEIGHT_PX = FLAPPY_WORLD_HEIGHT_PX;
15
51
 
@@ -17,10 +53,49 @@ export const FLAPPY_STARFIELD_TILE_HEIGHT_PX = FLAPPY_WORLD_HEIGHT_PX;
17
53
  export const FLAPPY_STARFIELD_CYAN_FILL_STYLE = 'rgba(95, 255, 255, 1)';
18
54
 
19
55
  /** Horizontal scroll ratio for the farthest parallax layer. */
20
- export const FLAPPY_STARFIELD_FAR_SCROLL_RATIO = 0.08;
56
+ export const FLAPPY_STARFIELD_FAR_SCROLL_RATIO = 0.03;
21
57
 
22
58
  /** Horizontal scroll ratio for the middle parallax layer. */
23
- export const FLAPPY_STARFIELD_MID_SCROLL_RATIO = 0.12;
59
+ export const FLAPPY_STARFIELD_MID_SCROLL_RATIO = 0.04;
24
60
 
25
61
  /** Horizontal scroll ratio for the nearest parallax layer. */
26
- export const FLAPPY_STARFIELD_NEAR_SCROLL_RATIO = 0.18;
62
+ export const FLAPPY_STARFIELD_NEAR_SCROLL_RATIO = 0.05;
63
+
64
+ /**
65
+ * Declarative layer specs for the default starfield parallax bands.
66
+ *
67
+ * Keeping the layer recipe in data form makes it easier to swap the lower
68
+ * segment to a different parallax family without changing the tile builder.
69
+ */
70
+ export const FLAPPY_STARFIELD_LAYER_SPECS = [
71
+ {
72
+ seed: 1_337,
73
+ scrollRatio: FLAPPY_STARFIELD_FAR_SCROLL_RATIO,
74
+ starCount: 35,
75
+ minSizePx: 1,
76
+ maxSizePx: 2,
77
+ minAlpha: 0.08,
78
+ maxAlpha: 0.22,
79
+ blurPx: 4,
80
+ },
81
+ {
82
+ seed: 2_777,
83
+ scrollRatio: FLAPPY_STARFIELD_MID_SCROLL_RATIO,
84
+ starCount: 28,
85
+ minSizePx: 1,
86
+ maxSizePx: 3,
87
+ minAlpha: 0.1,
88
+ maxAlpha: 0.28,
89
+ blurPx: 6,
90
+ },
91
+ {
92
+ seed: 4_242,
93
+ scrollRatio: FLAPPY_STARFIELD_NEAR_SCROLL_RATIO,
94
+ starCount: 23,
95
+ minSizePx: 2,
96
+ maxSizePx: 4,
97
+ minAlpha: 0.12,
98
+ maxAlpha: 0.34,
99
+ blurPx: 8,
100
+ },
101
+ ] as const;
@@ -0,0 +1,143 @@
1
+ # environment
2
+
3
+ ## environment/environment.types.ts
4
+
5
+ ### FlappyBird
6
+
7
+ Bird kinematic state for one simulation frame.
8
+
9
+ ### FlappyDifficultyScale
10
+
11
+ Difficulty scale used by the curriculum scheduler.
12
+
13
+ - `0` means easiest profile (wide gaps, slower pipes).
14
+ - `1` means fully adaptive profile based on passed pipes.
15
+
16
+ ### FlappyGameState
17
+
18
+ Full simulation state for one Flappy episode.
19
+
20
+ ### FlappyObservationFeatures
21
+
22
+ Structured observation features used to build the neural-network input vector.
23
+
24
+ Re-exported from shared simulation utilities so trainer and browser paths
25
+ stay synchronized as the observation schema evolves.
26
+
27
+ ### FlappyPipe
28
+
29
+ Pipe obstacle definition.
30
+
31
+ Pipes move from right to left. The bird scores once per pipe when the pipe
32
+ completely crosses the bird x-position.
33
+
34
+ ## environment/environment.constants.ts
35
+
36
+ ### FLAPPY_ENVIRONMENT_DEFAULT_CONTROL_SUBSTEPS_PER_FRAME
37
+
38
+ ### FLAPPY_ENVIRONMENT_DEFAULT_DIFFICULTY_SCALE
39
+
40
+ ### FLAPPY_ENVIRONMENT_MAX_FRAMES_PER_EPISODE
41
+
42
+ ## environment/environment.step.service.ts
43
+
44
+ ### stepFlappyState
45
+
46
+ `(state: import("test/examples/flappy_bird/environment/environment.types").FlappyGameState, rng: import("test/examples/flappy_bird/rng").FlappyRng, flap: boolean, difficultyScale: number) => void`
47
+
48
+ Advance the simulation by one frame.
49
+
50
+ Parameters:
51
+
52
+ - `state` - - Mutable state object to update in-place.
53
+ - `rng` - - Random source used to spawn pipes.
54
+ - `flap` - - If true, applies an upward velocity impulse.
55
+ - `difficultyScale` - - Curriculum difficulty scale in [0, 1].
56
+
57
+ ### stepFlappyStateWithControlSubsteps
58
+
59
+ `(state: import("test/examples/flappy_bird/environment/environment.types").FlappyGameState, rng: import("test/examples/flappy_bird/rng").FlappyRng, shouldFlapForSubstep: () => boolean, difficultyScale: number, controlSubstepsPerFrame: number) => void`
60
+
61
+ Advance one logical frame using multiple control/physics substeps.
62
+
63
+ This allows policies to react multiple times before `frameIndex` advances,
64
+ improving responsiveness in high-difficulty scenarios.
65
+
66
+ Parameters:
67
+
68
+ - `state` - - Mutable state object to update in-place.
69
+ - `rng` - - Random source used to spawn pipes.
70
+ - `shouldFlapForSubstep` - - Callback deciding flap action per substep.
71
+ - `difficultyScale` - - Curriculum difficulty scale in [0, 1].
72
+ - `controlSubstepsPerFrame` - - Number of substeps to run this frame.
73
+
74
+ Returns: Nothing.
75
+
76
+ ## environment/environment.state.service.ts
77
+
78
+ ### createInitialFlappyState
79
+
80
+ `(rng: import("test/examples/flappy_bird/rng").FlappyRng) => import("test/examples/flappy_bird/environment/environment.types").FlappyGameState`
81
+
82
+ Create a fresh Flappy Bird episode state.
83
+
84
+ Parameters:
85
+
86
+ - `rng` - - Random source used to generate initial pipe configuration.
87
+
88
+ Returns: Initial state for one deterministic rollout.
89
+
90
+ ## environment/environment.collision.utils.ts
91
+
92
+ ### updateCollisionAndProgressState
93
+
94
+ `(state: import("test/examples/flappy_bird/environment/environment.types").FlappyGameState) => void`
95
+
96
+ Apply out-of-bounds, pipe-collision, and pass-credit rules for one substep.
97
+
98
+ Parameters:
99
+
100
+ - `state` - - Mutable simulation state to update in-place.
101
+
102
+ ## environment/environment.observation.utils.ts
103
+
104
+ ### getFlappyObservation
105
+
106
+ `(state: import("test/examples/flappy_bird/environment/environment.types").FlappyGameState, difficultyScale: number) => number[]`
107
+
108
+ Generate the network observation vector for the current state.
109
+
110
+ Observation (12 numbers):
111
+
112
+ 1. bird y position normalized to [0, 1]
113
+ 2. bird vertical velocity normalized to [-1, 1]
114
+ 3. distance to next pipe normalized to [0, 1]
115
+ 4. delta (bird y - gap center y) normalized to [-1, 1]
116
+ 5. next pipe gap top normalized to [0, 1]
117
+ 6. next pipe gap bottom normalized to [0, 1]
118
+ 7. distance to second pipe normalized to [0, 1]
119
+ 8. delta to second gap center normalized to [-1, 1]
120
+ 9. time-to-next-pipe closeness normalized to [0, 1]
121
+ 10. signed clearance relative to next gap normalized to [-1, 1]
122
+ 11. required vertical velocity toward next gap center normalized to [-1, 1]
123
+ 12. gap-center transition (next to second) normalized to [-1, 1]
124
+
125
+ Parameters:
126
+
127
+ - `state` - - Current state.
128
+ - `difficultyScale` - - Curriculum difficulty scale in [0, 1].
129
+
130
+ Returns: Input vector for the neural network.
131
+
132
+ ### getFlappyObservationFeatures
133
+
134
+ `(state: import("test/examples/flappy_bird/environment/environment.types").FlappyGameState, difficultyScale: number) => import("test/examples/flappy_bird/simulation-shared/simulation-shared.types").SharedObservationFeatures`
135
+
136
+ Resolve structured observation features for policy input and reward shaping.
137
+
138
+ Parameters:
139
+
140
+ - `state` - - Current state.
141
+ - `difficultyScale` - - Curriculum difficulty scale in [0, 1].
142
+
143
+ Returns: Named feature object.
@@ -61,7 +61,7 @@ export function getFlappyObservationFeatures(
61
61
  state: FlappyGameState,
62
62
  difficultyScale: FlappyDifficultyScale = FLAPPY_ENVIRONMENT_DEFAULT_DIFFICULTY_SCALE,
63
63
  ): FlappyObservationFeatures {
64
- const difficultyProfile = resolveDifficultyProfile(
64
+ const difficultyProfile = resolveAdaptiveDifficultyProfile(
65
65
  state.pipesPassed,
66
66
  difficultyScale,
67
67
  );
@@ -84,21 +84,3 @@ export function getFlappyObservationFeatures(
84
84
  normalizationEpsilon: FLAPPY_NORMALIZATION_EPSILON,
85
85
  });
86
86
  }
87
-
88
- /**
89
- * Resolves adaptive difficulty parameters from current progress.
90
- *
91
- * @param pipesPassed - Number of pipes passed by the active bird.
92
- * @param difficultyScale - Curriculum difficulty scale in [0, 1].
93
- * @returns Runtime difficulty profile.
94
- */
95
- function resolveDifficultyProfile(
96
- pipesPassed: number,
97
- difficultyScale: FlappyDifficultyScale = FLAPPY_ENVIRONMENT_DEFAULT_DIFFICULTY_SCALE,
98
- ): {
99
- pipeGapPx: number;
100
- pipeSpeedPxPerFrame: number;
101
- pipeSpawnIntervalFrames: number;
102
- } {
103
- return resolveAdaptiveDifficultyProfile(pipesPassed, difficultyScale);
104
- }
@@ -70,7 +70,7 @@ export function stepFlappyStateWithControlSubsteps(
70
70
  ): void {
71
71
  if (state.done) return;
72
72
 
73
- const difficultyProfile = resolveDifficultyProfile(
73
+ const difficultyProfile = resolveAdaptiveDifficultyProfile(
74
74
  state.pipesPassed,
75
75
  difficultyScale,
76
76
  );
@@ -105,12 +105,12 @@ export function stepFlappyStateWithControlSubsteps(
105
105
 
106
106
  state.framesUntilNextPipeSpawn -= substepDelta;
107
107
  if (state.framesUntilNextPipeSpawn <= 0) {
108
- const nextGapSizePx = resolveLocalNextSpawnGapSize(
108
+ const nextGapSizePx = resolveNextSpawnGapSize(
109
109
  state.lastSpawnedPipeGapPx,
110
110
  difficultyProfile,
111
111
  rng,
112
112
  );
113
- const nextSpawnIntervalFrames = resolveLocalNextSpawnIntervalFrames(
113
+ const nextSpawnIntervalFrames = resolveNextSpawnIntervalFrames(
114
114
  state.lastSpawnedPipeSpawnIntervalFrames,
115
115
  difficultyProfile,
116
116
  );
@@ -145,66 +145,3 @@ export function stepFlappyStateWithControlSubsteps(
145
145
  state.doneReason = 'timeout';
146
146
  }
147
147
  }
148
-
149
- /**
150
- * Resolves adaptive difficulty parameters from current progress.
151
- *
152
- * @param pipesPassed - Number of pipes passed by the active bird.
153
- * @param difficultyScale - Curriculum difficulty scale in [0, 1].
154
- * @returns Runtime difficulty profile.
155
- */
156
- function resolveDifficultyProfile(
157
- pipesPassed: number,
158
- difficultyScale: FlappyDifficultyScale = FLAPPY_ENVIRONMENT_DEFAULT_DIFFICULTY_SCALE,
159
- ): {
160
- pipeGapPx: number;
161
- pipeSpeedPxPerFrame: number;
162
- pipeSpawnIntervalFrames: number;
163
- } {
164
- return resolveAdaptiveDifficultyProfile(pipesPassed, difficultyScale);
165
- }
166
-
167
- /**
168
- * Resolve the next spawned pipe gap with progressive wide-to-hard shrink and jitter.
169
- *
170
- * @param previousSpawnGapPx - Most recently spawned gap size.
171
- * @param difficultyProfile - Current adaptive profile.
172
- * @param rng - Random source.
173
- * @returns Gap size for the next pipe.
174
- */
175
- function resolveLocalNextSpawnGapSize(
176
- previousSpawnGapPx: number | undefined,
177
- difficultyProfile: {
178
- pipeGapPx: number;
179
- pipeSpeedPxPerFrame: number;
180
- pipeSpawnIntervalFrames: number;
181
- },
182
- rng: FlappyRng,
183
- ): number {
184
- return resolveNextSpawnGapSize(
185
- previousSpawnGapPx,
186
- difficultyProfile as SharedDifficultyProfile,
187
- rng,
188
- );
189
- }
190
-
191
- /**
192
- * Resolve the next spawned pipe interval with progressive wide-to-hard shrink.
193
- *
194
- * @param previousSpawnIntervalFrames - Most recently spawned interval.
195
- * @param difficultyProfile - Current adaptive profile.
196
- * @returns Spawn interval for the next pipe.
197
- */
198
- function resolveLocalNextSpawnIntervalFrames(
199
- previousSpawnIntervalFrames: number | undefined,
200
- difficultyProfile: {
201
- pipeGapPx: number;
202
- pipeSpeedPxPerFrame: number;
203
- pipeSpawnIntervalFrames: number;
204
- },
205
- ): number {
206
- return resolveNextSpawnIntervalFrames(
207
- previousSpawnIntervalFrames,
208
- difficultyProfile as SharedDifficultyProfile,
209
- );
210
- }
@@ -0,0 +1,130 @@
1
+ # evaluation
2
+
3
+ ## evaluation/evaluation.types.ts
4
+
5
+ ### FlappyEpisodeResult
6
+
7
+ Summary metrics for a single Flappy episode rollout.
8
+
9
+ ### FlappyNetworkLike
10
+
11
+ Minimal network contract required by Flappy evaluation.
12
+
13
+ ### FlappyRolloutOptions
14
+
15
+ Runtime controls for one rollout evaluation.
16
+
17
+ ### FlappySeedBatchEvaluation
18
+
19
+ Aggregate statistics from evaluating one network across shared seeds.
20
+
21
+ ## evaluation/evaluation.constants.ts
22
+
23
+ ### evaluation.constants
24
+
25
+ Default difficulty scale for rollouts when caller does not provide one.
26
+
27
+ ### FLAPPY_EVALUATION_DEFAULT_DIFFICULTY_SCALE
28
+
29
+ ### FLAPPY_EVALUATION_DEFAULT_EARLY_TERMINATION_CONSECUTIVE_FRAMES
30
+
31
+ ### FLAPPY_EVALUATION_DEFAULT_EARLY_TERMINATION_GRACE_FRAMES
32
+
33
+ ### FLAPPY_EVALUATION_DEFAULT_PIPE_PROGRESS_TARGET
34
+
35
+ ### FLAPPY_EVALUATION_DENSE_SHAPING_FRAMES_NORMALIZER
36
+
37
+ ### FLAPPY_EVALUATION_NORMALIZED_DENSE_WEIGHT
38
+
39
+ ### FLAPPY_EVALUATION_NORMALIZED_PROGRESS_WEIGHT
40
+
41
+ ### FLAPPY_EVALUATION_NORMALIZED_SURVIVAL_WEIGHT
42
+
43
+ ### FLAPPY_EVALUATION_NORMALIZED_TERMINAL_WEIGHT
44
+
45
+ ### FLAPPY_EVALUATION_ROBUST_STDDEV_PENALTY
46
+
47
+ ### FLAPPY_EVALUATION_SEED_MIX_MULTIPLIER_A
48
+
49
+ ### FLAPPY_EVALUATION_SEED_MIX_MULTIPLIER_B
50
+
51
+ ### FLAPPY_EVALUATION_SEED_MIX_XOR_SALT
52
+
53
+ ### FLAPPY_EVALUATION_UNRECOVERABLE_ABOVE_GAP_DELTA
54
+
55
+ ### FLAPPY_EVALUATION_UNRECOVERABLE_BELOW_GAP_DELTA
56
+
57
+ ### FLAPPY_EVALUATION_UNRECOVERABLE_CLEARANCE_THRESHOLD
58
+
59
+ ### FLAPPY_EVALUATION_UNRECOVERABLE_FALLING_VELOCITY
60
+
61
+ ### FLAPPY_EVALUATION_UNRECOVERABLE_RISING_VELOCITY
62
+
63
+ ## evaluation/evaluation.rollout.service.ts
64
+
65
+ ### evaluation.rollout.service
66
+
67
+ Public rollout compatibility facade.
68
+
69
+ Keeping this file at the evaluation layer preserves the established import
70
+ path while the actual rollout orchestration lives behind the dedicated
71
+ rollout-owned module boundary.
72
+
73
+ ### rolloutEpisode
74
+
75
+ `(network: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyNetworkLike, rolloutOptions: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyRolloutOptions) => import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyEpisodeResult`
76
+
77
+ Roll out an episode and return details.
78
+
79
+ Parameters:
80
+
81
+ - `network` - - Genome/network to evaluate.
82
+ - `rolloutOptions` - - Optional rollout controls.
83
+
84
+ Returns: Episode result details.
85
+
86
+ ## evaluation/evaluation.seed.utils.ts
87
+
88
+ ### mixGenomeEvaluationSeed
89
+
90
+ `(genomeId: number) => number`
91
+
92
+ Mixes a genome identifier into a stable uint32 rollout seed.
93
+
94
+ This keeps evaluation deterministic per genome while still spreading nearby
95
+ genome ids across the RNG state space to reduce correlated rollouts.
96
+
97
+ Parameters:
98
+
99
+ - `genomeId` - - Genome id from NEAT bookkeeping.
100
+
101
+ Returns: Mixed uint32 seed.
102
+
103
+ ## evaluation/evaluation.fitness.utils.ts
104
+
105
+ ### evaluateFlappyFitness
106
+
107
+ `(network: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyNetworkLike, rolloutOptions: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyRolloutOptions) => number`
108
+
109
+ Evaluate a network on a single deterministic Flappy Bird episode.
110
+
111
+ Parameters:
112
+
113
+ - `network` - - Genome/network to evaluate.
114
+ - `rolloutOptions` - - Optional rollout controls.
115
+
116
+ Returns: Fitness score (higher is better).
117
+
118
+ ### evaluateFlappyFitnessAcrossSeeds
119
+
120
+ `(network: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyNetworkLike, sharedSeeds: readonly number[], rolloutOptions: import("test/examples/flappy_bird/evaluation/evaluation.types").FlappyRolloutOptions) => import("test/examples/flappy_bird/evaluation/evaluation.types").FlappySeedBatchEvaluation`
121
+
122
+ Evaluate a network on a shared batch of deterministic seeds.
123
+
124
+ Parameters:
125
+
126
+ - `network` - - Genome/network to evaluate.
127
+ - `sharedSeeds` - - Shared deterministic seeds used for all genomes.
128
+ - `rolloutOptions` - - Optional rollout controls.
129
+
130
+ Returns: Robust aggregate metrics for selection/ranking.
@@ -9,7 +9,7 @@ import {
9
9
  computeMean,
10
10
  computePercentile,
11
11
  computePopulationStandardDeviation,
12
- } from './evaluation.statistics.utils';
12
+ } from '../flappy.simulation.shared.utils';
13
13
 
14
14
  /**
15
15
  * Evaluate a network on a single deterministic Flappy Bird episode.