cuju-render 0.1.0__py3-none-any.whl

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 (382) hide show
  1. cuju/render/__init__.py +759 -0
  2. cuju/render/__main__.py +1065 -0
  3. cuju/render/_export/__init__.py +3 -0
  4. cuju/render/_export/feed.py +542 -0
  5. cuju/render/_export/sizes.py +157 -0
  6. cuju/render/_export/video.py +1618 -0
  7. cuju/render/_export/video_jobs.py +408 -0
  8. cuju/render/_format/__init__.py +3 -0
  9. cuju/render/_format/annotations.py +235 -0
  10. cuju/render/_format/codec.py +307 -0
  11. cuju/render/_format/keep.py +121 -0
  12. cuju/render/_format/recording.py +860 -0
  13. cuju/render/_format/writer.py +54 -0
  14. cuju/render/_guide/__init__.py +3 -0
  15. cuju/render/_guide/doctor.py +523 -0
  16. cuju/render/_guide/help.py +62 -0
  17. cuju/render/_guide/tutorial.py +254 -0
  18. cuju/render/_http/__init__.py +3 -0
  19. cuju/render/_http/commands.py +57 -0
  20. cuju/render/_http/headers.py +103 -0
  21. cuju/render/_http/launch.py +500 -0
  22. cuju/render/_http/launchers.py +408 -0
  23. cuju/render/_http/pwa.py +128 -0
  24. cuju/render/_http/server.py +2105 -0
  25. cuju/render/_http/window.py +360 -0
  26. cuju/render/_moments/__init__.py +3 -0
  27. cuju/render/_moments/captions.py +284 -0
  28. cuju/render/_moments/events.py +1123 -0
  29. cuju/render/_moments/search.py +694 -0
  30. cuju/render/_packages/__init__.py +3 -0
  31. cuju/render/_packages/glsl.py +746 -0
  32. cuju/render/_packages/loudness.py +334 -0
  33. cuju/render/_packages/pack.py +1959 -0
  34. cuju/render/_packages/presentation.py +1376 -0
  35. cuju/render/_packages/vocabulary.py +609 -0
  36. cuju/render/_playing/__init__.py +3 -0
  37. cuju/render/_playing/achievements.py +463 -0
  38. cuju/render/_playing/bench.py +609 -0
  39. cuju/render/_playing/challenges.py +1813 -0
  40. cuju/render/_playing/demo.py +323 -0
  41. cuju/render/_playing/draw.py +211 -0
  42. cuju/render/_playing/errors.py +20 -0
  43. cuju/render/_playing/game.py +645 -0
  44. cuju/render/_playing/limits.py +339 -0
  45. cuju/render/_playing/play.py +926 -0
  46. cuju/render/_playing/policy_worker.py +250 -0
  47. cuju/render/_playing/strict.py +810 -0
  48. cuju/render/_registry/__init__.py +3 -0
  49. cuju/render/_registry/clips.py +394 -0
  50. cuju/render/_registry/joints.py +108 -0
  51. cuju/render/_registry/teams.py +2058 -0
  52. cuju/render/_store/__init__.py +3 -0
  53. cuju/render/_store/home.py +70 -0
  54. cuju/render/_store/library.py +604 -0
  55. cuju/render/_store/samples.py +163 -0
  56. cuju/render/_text/__init__.py +3 -0
  57. cuju/render/_text/languages.py +637 -0
  58. cuju/render/_text/messages.py +1396 -0
  59. cuju/render/_tournaments/__init__.py +3 -0
  60. cuju/render/_tournaments/results.py +547 -0
  61. cuju/render/_tournaments/tournament.py +2742 -0
  62. cuju/render/_tournaments/tournament_cli.py +587 -0
  63. cuju/render/_tournaments/tournament_runner.py +1975 -0
  64. cuju/render/_version.py +6 -0
  65. cuju/render/_watch/__init__.py +3 -0
  66. cuju/render/_watch/grid.py +265 -0
  67. cuju/render/_watch/live.py +664 -0
  68. cuju/render/_watch/notebook.py +79 -0
  69. cuju/render/_watch/show.py +171 -0
  70. cuju/render/samples/sample-11v11.cjr +0 -0
  71. cuju/render/samples/sample-5v5.cjr +0 -0
  72. cuju/render/samples/teams/starter/main.py +33 -0
  73. cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
  74. cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
  75. cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
  76. cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
  77. cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
  78. cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
  79. cuju/render/web/assets/adboard_polygon.webp +0 -0
  80. cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
  81. cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
  82. cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
  83. cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
  84. cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
  85. cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
  86. cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
  87. cuju/render/web/assets/ball.glb +0 -0
  88. cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
  89. cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
  90. cuju/render/web/assets/challenges/corner.mp4 +0 -0
  91. cuju/render/web/assets/challenges/corner.webp +0 -0
  92. cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
  93. cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
  94. cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
  95. cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
  96. cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
  97. cuju/render/web/assets/challenges/empty_goal.webp +0 -0
  98. cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
  99. cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
  100. cuju/render/web/assets/challenges/manifest.json +375 -0
  101. cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
  102. cuju/render/web/assets/challenges/one_on_one.webp +0 -0
  103. cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
  104. cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
  105. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
  106. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
  107. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
  108. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
  109. cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
  110. cuju/render/web/assets/challenges/run_to_score.webp +0 -0
  111. cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
  112. cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
  113. cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
  114. cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
  115. cuju/render/web/assets/crowd.webp +0 -0
  116. cuju/render/web/assets/crowd_normal.webp +0 -0
  117. cuju/render/web/assets/cuju-logo-384.png +0 -0
  118. cuju/render/web/assets/cuju-logo.png +0 -0
  119. cuju/render/web/assets/cuju-logo.svg +46 -0
  120. cuju/render/web/assets/cuju-mark-light.svg +33 -0
  121. cuju/render/web/assets/cuju-mark.svg +33 -0
  122. cuju/render/web/assets/goal.glb +0 -0
  123. cuju/render/web/assets/grass.webp +0 -0
  124. cuju/render/web/assets/hair_black.png +0 -0
  125. cuju/render/web/assets/hair_blonde.png +0 -0
  126. cuju/render/web/assets/hair_brown.png +0 -0
  127. cuju/render/web/assets/hair_darkblonde.png +0 -0
  128. cuju/render/web/assets/hair_long01.glb +0 -0
  129. cuju/render/web/assets/hair_long02.glb +0 -0
  130. cuju/render/web/assets/hair_medium01.glb +0 -0
  131. cuju/render/web/assets/hair_red.png +0 -0
  132. cuju/render/web/assets/hair_short01.glb +0 -0
  133. cuju/render/web/assets/hair_short02.glb +0 -0
  134. cuju/render/web/assets/icons/cuju-192.png +0 -0
  135. cuju/render/web/assets/icons/cuju-512.png +0 -0
  136. cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
  137. cuju/render/web/assets/kit_goalkeeper.webp +0 -0
  138. cuju/render/web/assets/kit_mask.png +0 -0
  139. cuju/render/web/assets/kit_normal.webp +0 -0
  140. cuju/render/web/assets/manifest.json +601 -0
  141. cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
  142. cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
  143. cuju/render/web/assets/models/kaykit-knight.glb +0 -0
  144. cuju/render/web/assets/models/kaykit-knight.json +23 -0
  145. cuju/render/web/assets/models/kaykit-mage.glb +0 -0
  146. cuju/render/web/assets/models/kaykit-mage.json +23 -0
  147. cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
  148. cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
  149. cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
  150. cuju/render/web/assets/models/kaykit-ranger.json +23 -0
  151. cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
  152. cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
  153. cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
  154. cuju/render/web/assets/models/kaykit-rogue.json +23 -0
  155. cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
  156. cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
  157. cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
  158. cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
  159. cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
  160. cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
  161. cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
  162. cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
  163. cuju/render/web/assets/pitch.webp +0 -0
  164. cuju/render/web/assets/pitch_normal.webp +0 -0
  165. cuju/render/web/assets/player.glb +0 -0
  166. cuju/render/web/assets/shoe.webp +0 -0
  167. cuju/render/web/assets/shoe_sole.png +0 -0
  168. cuju/render/web/assets/skin_01.png +0 -0
  169. cuju/render/web/assets/skin_02.png +0 -0
  170. cuju/render/web/assets/skin_03.png +0 -0
  171. cuju/render/web/assets/skin_04.png +0 -0
  172. cuju/render/web/assets/sounds/applause.ogg +0 -0
  173. cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
  174. cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
  175. cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
  176. cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
  177. cuju/render/web/assets/sounds/city-horn.ogg +0 -0
  178. cuju/render/web/assets/sounds/city-loop.ogg +0 -0
  179. cuju/render/web/assets/sounds/city-siren.ogg +0 -0
  180. cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
  181. cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
  182. cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
  183. cuju/render/web/assets/sounds/gulls.ogg +0 -0
  184. cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
  185. cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
  186. cuju/render/web/assets/sounds/sounds.json +46 -0
  187. cuju/render/web/assets/sounds/space-beep.ogg +0 -0
  188. cuju/render/web/assets/sounds/space-hum.ogg +0 -0
  189. cuju/render/web/assets/sounds/space-radio.ogg +0 -0
  190. cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
  191. cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
  192. cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
  193. cuju/render/web/easy.css +357 -0
  194. cuju/render/web/export.html +23 -0
  195. cuju/render/web/feed.css +262 -0
  196. cuju/render/web/feed.html +28 -0
  197. cuju/render/web/flat.css +120 -0
  198. cuju/render/web/home.css +837 -0
  199. cuju/render/web/index.html +373 -0
  200. cuju/render/web/js/boot.js +50 -0
  201. cuju/render/web/js/broadcast/audio.js +2141 -0
  202. cuju/render/web/js/broadcast/celebrate.js +1238 -0
  203. cuju/render/web/js/broadcast/decisions.js +609 -0
  204. cuju/render/web/js/broadcast/hud.js +352 -0
  205. cuju/render/web/js/broadcast/show.js +3614 -0
  206. cuju/render/web/js/broadcast/transition.js +2231 -0
  207. cuju/render/web/js/broadcast/voices.js +153 -0
  208. cuju/render/web/js/capture.js +101 -0
  209. cuju/render/web/js/core/accessibility.js +90 -0
  210. cuju/render/web/js/core/api.js +429 -0
  211. cuju/render/web/js/core/comfort.js +135 -0
  212. cuju/render/web/js/core/i18n.js +705 -0
  213. cuju/render/web/js/core/icons.js +167 -0
  214. cuju/render/web/js/core/input-settings.js +156 -0
  215. cuju/render/web/js/core/keys.js +277 -0
  216. cuju/render/web/js/core/language-ui.js +125 -0
  217. cuju/render/web/js/core/menu.js +853 -0
  218. cuju/render/web/js/core/names.js +113 -0
  219. cuju/render/web/js/core/page-structure.js +110 -0
  220. cuju/render/web/js/core/scenarios.js +109 -0
  221. cuju/render/web/js/core/spoilers.js +236 -0
  222. cuju/render/web/js/core/typeahead.js +38 -0
  223. cuju/render/web/js/export/dom-picture.js +330 -0
  224. cuju/render/web/js/export/export-host.js +97 -0
  225. cuju/render/web/js/export/feed-dialog.js +191 -0
  226. cuju/render/web/js/export/feed-params.js +266 -0
  227. cuju/render/web/js/export/feed.js +363 -0
  228. cuju/render/web/js/export/mp4-mux.js +295 -0
  229. cuju/render/web/js/export/photo-core.js +313 -0
  230. cuju/render/web/js/export/photo.js +1314 -0
  231. cuju/render/web/js/export/safe-frame.js +59 -0
  232. cuju/render/web/js/export/size-fields.js +103 -0
  233. cuju/render/web/js/export/sizes.js +178 -0
  234. cuju/render/web/js/export/video-boot.js +55 -0
  235. cuju/render/web/js/export/video-browser.js +325 -0
  236. cuju/render/web/js/export/video-export.js +417 -0
  237. cuju/render/web/js/export/video-plan.js +207 -0
  238. cuju/render/web/js/export/video-range.js +185 -0
  239. cuju/render/web/js/export/webm-mux.js +198 -0
  240. cuju/render/web/js/feed-boot.js +151 -0
  241. cuju/render/web/js/feed-frame.js +101 -0
  242. cuju/render/web/js/help/doctor.js +488 -0
  243. cuju/render/web/js/help/firstrun.js +379 -0
  244. cuju/render/web/js/help/help-center.js +438 -0
  245. cuju/render/web/js/help/install-offer.js +164 -0
  246. cuju/render/web/js/help/install-state.js +104 -0
  247. cuju/render/web/js/help/lessons-core.js +207 -0
  248. cuju/render/web/js/help/lessons.js +463 -0
  249. cuju/render/web/js/help/palette.js +584 -0
  250. cuju/render/web/js/help/pwa.js +257 -0
  251. cuju/render/web/js/help/tour-core.js +241 -0
  252. cuju/render/web/js/help/tour.js +461 -0
  253. cuju/render/web/js/main.js +2513 -0
  254. cuju/render/web/js/pages/draw.js +188 -0
  255. cuju/render/web/js/pages/fieldpage.js +530 -0
  256. cuju/render/web/js/pages/home.js +521 -0
  257. cuju/render/web/js/pages/matches.js +779 -0
  258. cuju/render/web/js/pages/moments-ui.js +359 -0
  259. cuju/render/web/js/pages/queue-filters.js +63 -0
  260. cuju/render/web/js/pages/recording-groups.js +80 -0
  261. cuju/render/web/js/pages/recordings.js +1069 -0
  262. cuju/render/web/js/play/bench.js +347 -0
  263. cuju/render/web/js/play/challenges.js +1302 -0
  264. cuju/render/web/js/play/medals.js +127 -0
  265. cuju/render/web/js/play/play.js +1953 -0
  266. cuju/render/web/js/play/teasers.js +196 -0
  267. cuju/render/web/js/play/touch.js +350 -0
  268. cuju/render/web/js/play/tournament-layout.js +487 -0
  269. cuju/render/web/js/play/tournament-results.js +441 -0
  270. cuju/render/web/js/play/tournament-strict.js +560 -0
  271. cuju/render/web/js/play/tournament.js +2585 -0
  272. cuju/render/web/js/players/animate.js +972 -0
  273. cuju/render/web/js/players/clips.js +224 -0
  274. cuju/render/web/js/players/kaykit.js +162 -0
  275. cuju/render/web/js/players/kits.js +676 -0
  276. cuju/render/web/js/players/number-patch.js +82 -0
  277. cuju/render/web/js/players/players.js +2694 -0
  278. cuju/render/web/js/players/recolor.js +893 -0
  279. cuju/render/web/js/players/retarget.js +325 -0
  280. cuju/render/web/js/players/rig-numbers.js +174 -0
  281. cuju/render/web/js/presentation/animator.js +231 -0
  282. cuju/render/web/js/presentation/assign.js +85 -0
  283. cuju/render/web/js/presentation/behaviors.js +440 -0
  284. cuju/render/web/js/presentation/budget.js +209 -0
  285. cuju/render/web/js/presentation/catalog.js +1674 -0
  286. cuju/render/web/js/presentation/clocks.js +72 -0
  287. cuju/render/web/js/presentation/commands.js +301 -0
  288. cuju/render/web/js/presentation/contract.js +240 -0
  289. cuju/render/web/js/presentation/effects.js +904 -0
  290. cuju/render/web/js/presentation/flash.js +605 -0
  291. cuju/render/web/js/presentation/freeze-worklet.js +22 -0
  292. cuju/render/web/js/presentation/glsl.js +464 -0
  293. cuju/render/web/js/presentation/host.js +323 -0
  294. cuju/render/web/js/presentation/index.js +2066 -0
  295. cuju/render/web/js/presentation/loudness-worklet.js +235 -0
  296. cuju/render/web/js/presentation/loudness.js +740 -0
  297. cuju/render/web/js/presentation/moments.js +536 -0
  298. cuju/render/web/js/presentation/post.js +327 -0
  299. cuju/render/web/js/presentation/preview.js +180 -0
  300. cuju/render/web/js/presentation/protocol.js +174 -0
  301. cuju/render/web/js/presentation/reach.js +158 -0
  302. cuju/render/web/js/presentation/rigging.js +130 -0
  303. cuju/render/web/js/presentation/sandbox.js +157 -0
  304. cuju/render/web/js/presentation/shaders.js +235 -0
  305. cuju/render/web/js/presentation/stage.js +402 -0
  306. cuju/render/web/js/presentation/teamaudio.js +722 -0
  307. cuju/render/web/js/presentation/tracks.js +197 -0
  308. cuju/render/web/js/presentation/values.js +81 -0
  309. cuju/render/web/js/recording/annotation-data.js +203 -0
  310. cuju/render/web/js/recording/captions.js +491 -0
  311. cuju/render/web/js/recording/codec.js +185 -0
  312. cuju/render/web/js/recording/decode-worker.js +70 -0
  313. cuju/render/web/js/recording/decode.js +94 -0
  314. cuju/render/web/js/recording/episodes.js +46 -0
  315. cuju/render/web/js/recording/format.js +461 -0
  316. cuju/render/web/js/recording/live.js +348 -0
  317. cuju/render/web/js/recording/moments-query.js +59 -0
  318. cuju/render/web/js/recording/moments.js +149 -0
  319. cuju/render/web/js/recording/pose.js +86 -0
  320. cuju/render/web/js/recording/timeline.js +275 -0
  321. cuju/render/web/js/teams/art.js +50 -0
  322. cuju/render/web/js/teams/clip-editor.js +293 -0
  323. cuju/render/web/js/teams/editor.js +1979 -0
  324. cuju/render/web/js/teams/library.js +344 -0
  325. cuju/render/web/js/teams/painter.js +633 -0
  326. cuju/render/web/js/teams/surprise-ui.js +195 -0
  327. cuju/render/web/js/teams/surprise.js +497 -0
  328. cuju/render/web/js/teams/team-check.js +127 -0
  329. cuju/render/web/js/watch/annotations.js +270 -0
  330. cuju/render/web/js/watch/flat.js +366 -0
  331. cuju/render/web/js/watch/grid.js +436 -0
  332. cuju/render/web/js/watch/pitch2d.js +289 -0
  333. cuju/render/web/js/watch/player-tools.js +192 -0
  334. cuju/render/web/js/watch/presets.js +201 -0
  335. cuju/render/web/js/world/arenas.js +997 -0
  336. cuju/render/web/js/world/ball.js +204 -0
  337. cuju/render/web/js/world/cameras.js +982 -0
  338. cuju/render/web/js/world/crowd.js +376 -0
  339. cuju/render/web/js/world/field.js +227 -0
  340. cuju/render/web/js/world/framing.js +145 -0
  341. cuju/render/web/js/world/occlusion.js +48 -0
  342. cuju/render/web/js/world/pitch.js +703 -0
  343. cuju/render/web/js/world/scene.js +395 -0
  344. cuju/render/web/js/world/sky.js +325 -0
  345. cuju/render/web/js/world/stadium.js +1262 -0
  346. cuju/render/web/js/world/vendor-sky.js +367 -0
  347. cuju/render/web/js/world/weather.js +264 -0
  348. cuju/render/web/languages/en.json +4750 -0
  349. cuju/render/web/lessons.json +137 -0
  350. cuju/render/web/manifest.webmanifest +23 -0
  351. cuju/render/web/style.css +8399 -0
  352. cuju/render/web/sw.js +235 -0
  353. cuju/render/web/vendor/fabric/LICENSE +16 -0
  354. cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
  355. cuju/render/web/vendor/lucide/LICENSE +43 -0
  356. cuju/render/web/vendor/lucide/icons.js +141 -0
  357. cuju/render/web/vendor/three/LICENSE +21 -0
  358. cuju/render/web/vendor/three/build/three.core.js +60586 -0
  359. cuju/render/web/vendor/three/build/three.module.js +19719 -0
  360. cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
  361. cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
  362. cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  363. cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
  364. cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  365. cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
  366. cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  367. cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
  368. cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  369. cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  370. cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  371. cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
  372. cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
  373. cuju_render-0.1.0.dist-info/METADATA +116 -0
  374. cuju_render-0.1.0.dist-info/RECORD +382 -0
  375. cuju_render-0.1.0.dist-info/WHEEL +4 -0
  376. cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
  377. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
  378. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
  379. cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
  380. cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
  381. cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
  382. cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
@@ -0,0 +1,645 @@
1
+ # Copyright 2026 The cuju Authors
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """Plays a game in which a person controls one player of a side, against a team of the registry.
5
+
6
+ The server runs this module in a process of its own for the page's Play a game. The process steps
7
+ one environment at real time, ten steps a second, and streams every frame to the page through a
8
+ live source that stays off the list of sources. Commands come from the server as one JSON line at
9
+ a time on standard input, the input of each person's side, pause and quit, and reports go back as
10
+ one JSON line at a time on a channel of their own, as for a requested match.
11
+
12
+ Each person's side is a scenario's agent, as `{scenario}_l1_r0` names it, so the person controls
13
+ one player and the engine hands that control to the designated player as play moves, the player
14
+ nearest the ball among them, as GRF does for its own human players. The keys and buttons that
15
+ the page reads become GRF's 19 default actions through GRF's own controller logic, so a person's
16
+ actions are actions like any agent's and the match stays the match the engine would play for them.
17
+
18
+ The other team, and the person's teammates, are the built-in AI or a submission of the registry.
19
+ A submission loads and plays in this process from its own folder, as in a requested match, and its
20
+ calls run on a thread of their own, `PolicyRunner`, so it never holds the game back. A step whose
21
+ answer comes late goes to the built-in AI, and a submission that fails or stops answering ends the
22
+ game, which keeps its recording.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ import argparse
28
+ import contextlib
29
+ import json
30
+ import os
31
+ import queue
32
+ import struct
33
+ import sys
34
+ import threading
35
+ import time
36
+ from pathlib import Path
37
+ from typing import Any, TextIO
38
+
39
+ import torch
40
+
41
+ from cuju import BatchEnvironment, bundled_scenarios
42
+
43
+ from .._format import recording as _recording
44
+ from .._registry import teams as _teams
45
+ from .._store import library as _library
46
+ from .._text import messages as _messages
47
+ from .._text.messages import MessageError
48
+ from .._watch import live as _live
49
+ from . import achievements as _achievements
50
+ from .play import Policies, PolicyError, PolicyMessageError, PolicyRunner, game_title, side_names
51
+
52
+ # The names of the inputs that the page sends, four directions on the screen and the buttons.
53
+ DIRECTIONS = ('left', 'right', 'up', 'down')
54
+ BUTTONS = ('long_pass', 'high_pass', 'short_pass', 'shot', 'sliding', 'sprint', 'dribble')
55
+ INPUTS = DIRECTIONS + BUTTONS
56
+ # GRF: the indices of the default action set.
57
+ _IDLE, _LEFT, _TOP_LEFT, _TOP, _TOP_RIGHT, _RIGHT, _BOTTOM_RIGHT, _BOTTOM, _BOTTOM_LEFT = range(9)
58
+ _PRESS = {
59
+ 'long_pass': 9,
60
+ 'high_pass': 10,
61
+ 'short_pass': 11,
62
+ 'shot': 12,
63
+ 'sprint': 13,
64
+ 'sliding': 16,
65
+ 'dribble': 17,
66
+ }
67
+ _RELEASE_DIRECTION = 14
68
+ # GRF: releasing sprint and dribble are actions of the default set. The engine releases the other
69
+ # buttons itself after every step in play, so their releases change nothing and take the place of
70
+ # GRF's release actions as idle.
71
+ _RELEASE = {
72
+ 'long_pass': _IDLE,
73
+ 'high_pass': _IDLE,
74
+ 'short_pass': _IDLE,
75
+ 'shot': _IDLE,
76
+ 'sliding': _IDLE,
77
+ 'sprint': 15,
78
+ 'dribble': 18,
79
+ }
80
+ # GRF: `get_env_action` checks the buttons in this order, which decides the one action of a step.
81
+ _ORDER = ('long_pass', 'high_pass', 'short_pass', 'shot', 'sliding', 'sprint', 'dribble')
82
+ STEPS_PER_SECOND = 10
83
+ # Without any message from the server for this long the game pauses, and after this long it ends.
84
+ PAUSE_AFTER_SECONDS = 8.0
85
+ END_AFTER_SECONDS = 120.0
86
+ # A submission answers each step within this share of the step's time, measured from when its
87
+ # observation is read, or the built-in AI plays its players for the step.
88
+ POLICY_BUDGET = 0.9
89
+ # Loading the submissions, and their first answer, each get this long, since a Kaggle agent often
90
+ # loads its model on the first call. Both together stay well within the server's two minutes for
91
+ # the start of a game.
92
+ LOAD_SECONDS = 45.0
93
+ FIRST_CALL_SECONDS = 45.0
94
+ # A submission that has not answered for this long counts as stuck, and the game ends.
95
+ HANG_SECONDS = 10.0
96
+ # After this many steps in a row without an answer in time, the page hears of it.
97
+ LATE_STREAK = 10
98
+ _SCORE = struct.Struct('<2i')
99
+
100
+ # The channel of the reports, standard output until `main` moves everything else away.
101
+ _reports: TextIO = sys.stdout
102
+
103
+
104
+ def _report(**entries: Any) -> None:
105
+ """Writes one line of progress for the server."""
106
+ _reports.write(json.dumps(entries) + '\n')
107
+ _reports.flush()
108
+
109
+
110
+ class Controller:
111
+ """GRF's controller of a person's player, `controller_base.Controller`, on the 19 actions.
112
+
113
+ Each step yields one action. A change of direction comes first, the new direction or a release
114
+ of the direction, and otherwise the first button in GRF's order whose state changed, its press
115
+ or its release. Sprint and dribble stay pressed in the engine until released, while the passes,
116
+ the shot and the slide act on the step they are pressed.
117
+ """
118
+
119
+ def __init__(self) -> None:
120
+ self._direction = _IDLE
121
+ self._buttons: dict[str, bool] = {}
122
+
123
+ def act(self, held: frozenset[str], pressed: frozenset[str]) -> int:
124
+ """Returns the action of one step.
125
+
126
+ Args:
127
+ held: The inputs held at the step, directions and buttons, in the side's own frame.
128
+ pressed: The buttons pressed since the last step, even if already let go, as GRF's
129
+ queue of key presses holds them.
130
+ """
131
+ left, right = 'left' in held, 'right' in held
132
+ top, bottom = 'up' in held, 'down' in held
133
+ direction = _IDLE
134
+ for action, on in (
135
+ (_TOP_LEFT, top and left),
136
+ (_TOP_RIGHT, top and right),
137
+ (_BOTTOM_LEFT, bottom and left),
138
+ (_BOTTOM_RIGHT, bottom and right),
139
+ (_RIGHT, right),
140
+ (_LEFT, left),
141
+ (_TOP, top),
142
+ (_BOTTOM, bottom),
143
+ ):
144
+ if on:
145
+ direction = action
146
+ break
147
+ if direction != self._direction:
148
+ self._direction = direction
149
+ return _RELEASE_DIRECTION if direction == _IDLE else direction
150
+ active = held | pressed
151
+ for name in _ORDER:
152
+ state = name in active
153
+ if self._buttons.get(name, False) != state:
154
+ self._buttons[name] = state
155
+ return _PRESS[name] if state else _RELEASE[name]
156
+ return _IDLE
157
+
158
+
159
+ def own_frame(held: frozenset[str], side: int) -> frozenset[str]:
160
+ """Returns the inputs of a side in its own frame from the directions on the screen.
161
+
162
+ The page's broadcast camera looks across the pitch from the main stand, so right on the screen
163
+ points along the pitch's x axis and up points away from the camera. GRF's right team plays in a
164
+ frame turned half a circle, so its directions swap left with right and up with down.
165
+ """
166
+ if side == 0:
167
+ return held
168
+ swap = {'left': 'right', 'right': 'left', 'up': 'down', 'down': 'up'}
169
+ return frozenset(swap.get(name, name) for name in held)
170
+
171
+
172
+ class Game:
173
+ """One environment in which people control one player of a side each, stepped on request.
174
+
175
+ Attributes:
176
+ humans: Whether a person plays the left side and the right side.
177
+ team_ids: The registry team of each side, the person's teammates on a person's side.
178
+ counts: The agents of each side, a person's first.
179
+ action_set: `v2` when a submission plays, so the built-in AI may stand in for it, or
180
+ `default`.
181
+ actions: The actions of every step so far, one list per step, the left agents first.
182
+ frames: The frames of every step so far, the reset first.
183
+ lineup: The header entry of each player.
184
+ teams: The left and right team, as a recording's header holds them.
185
+ runner: The runner of the submissions, or `None` when the built-in AI plays every player.
186
+ error: Why a submission ended the game, or `None`.
187
+ error_ids: The id and values of the message of `error`, when it has one, for the page.
188
+ controlled: The player in its team that each person controls, on a side shared with a
189
+ submission, where the frames mark every player of the side's agents, or `None`.
190
+ """
191
+
192
+ def __init__(
193
+ self,
194
+ scenario: str,
195
+ humans: tuple[bool, bool],
196
+ ability: tuple[float | None, float | None] = (None, None),
197
+ seed: int | None = None,
198
+ device: str = 'cpu',
199
+ teams: tuple[str, str] = (_teams.BUILTIN, _teams.BUILTIN),
200
+ load_seconds: float | None = LOAD_SECONDS,
201
+ first_call_seconds: float | None = FIRST_CALL_SECONDS,
202
+ length: int | None = None,
203
+ tournament: dict[str, Any] | None = None,
204
+ ) -> None:
205
+ """Creates and resets the environment, and loads the submissions that play.
206
+
207
+ Args:
208
+ scenario: A shipped scenario, without agent counts.
209
+ humans: Whether a person plays the left side and the right side, at least one.
210
+ ability: The ability of the built-in AI on the left and on the right, each from 0 to
211
+ 1, or `None` for the scenario's.
212
+ seed: The seed of the game, or `None` for one drawn from the clock.
213
+ device: `cpu` or `cuda`.
214
+ teams: The registry team of each side. A side without a person is that team, and a
215
+ person's side takes it as the person's teammates, the built-in AI by default.
216
+ load_seconds: How long the submissions may take to load, or `None` without a limit.
217
+ first_call_seconds: How long the submissions may take to answer the first
218
+ observation, or `None` without a limit.
219
+ length: The steps the game lasts, or `None` for the scenario's own duration.
220
+ tournament: The tournament match that the game plays, which its provenance keeps,
221
+ with the names of the people in `names`, or `None`.
222
+
223
+ Raises:
224
+ ArgumentError: If the scenario is not shipped, no side has a person, an ability lies
225
+ outside 0 to 1, or a team cannot play its side.
226
+ PolicyError: If a submission fails to load, fails on its first observation or misses
227
+ its allowance for either.
228
+ """
229
+ ability = _teams.check_ability(ability)
230
+ if scenario not in [*bundled_scenarios(), *_teams.renderer_scenarios()]:
231
+ raise MessageError('server.scenario', scenario=repr(scenario))
232
+ if not any(humans):
233
+ raise MessageError('server.game.person')
234
+ if (
235
+ not isinstance(teams, (tuple, list))
236
+ or len(teams) != 2
237
+ or not all(isinstance(value, str) for value in teams)
238
+ ):
239
+ raise MessageError('server.game.registry_teams', teams=repr(teams))
240
+ self.humans = (bool(humans[0]), bool(humans[1]))
241
+ self.scenario = scenario
242
+ self.seed = int(time.time()) % 2**31 if seed is None else int(seed)
243
+ self.team_ids = [str(teams[0]), str(teams[1])]
244
+ entries = [_teams.entry(identifier) for identifier in self.team_ids]
245
+ agents = _teams.game_agents(entries, scenario, self.humans)
246
+ self.counts = [int(self.humans[side]) + agents[side] for side in (0, 1)]
247
+ self.action_set = 'v2' if any(agents) else 'default'
248
+ self.length = None if length is None else int(length)
249
+ self.tournament = tournament
250
+ if self.length is not None:
251
+ from .._tournaments.tournament_runner import length_scenario
252
+
253
+ asset = length_scenario(scenario, self.length)
254
+ elif scenario in _teams.renderer_scenarios():
255
+ asset = str(_teams.scenario_path(scenario))
256
+ else:
257
+ asset = f'{scenario}_l{self.counts[0]}_r{self.counts[1]}'
258
+ self.batch = BatchEnvironment(
259
+ asset,
260
+ agent_counts=[tuple(self.counts)],
261
+ environment_count=1,
262
+ representation='raw',
263
+ seed=self.seed,
264
+ auto_reset=False,
265
+ device=device,
266
+ difficulty=None if ability == (None, None) else [ability],
267
+ action_set=self.action_set,
268
+ )
269
+ self.sides = [side for side in (0, 1) if self.humans[side]]
270
+ # A person's agent comes first on the side, and the teammates' agents follow it.
271
+ self.person_column = {0: 0, 1: self.counts[0]}
272
+ self.shared = [side for side in self.sides if self.counts[side] > 1]
273
+ self.controlled: list[int | None] = [None, None]
274
+ self.controllers = {side: Controller() for side in self.sides}
275
+ self.reader = _recording.StateReader(
276
+ int(self.batch.left_players[0] + self.batch.right_players[0])
277
+ )
278
+ self.batch.reset()
279
+ self.runner: PolicyRunner | None = None
280
+ self.error: str | None = None
281
+ self.error_ids: dict[str, Any] = {}
282
+ self._failure: PolicyError | None = None
283
+ if any(agents):
284
+ firsts = [int(self.humans[0]), self.counts[0] + int(self.humans[1])]
285
+ batch, runner = self.batch, PolicyRunner(hang=HANG_SECONDS)
286
+ try:
287
+ runner.load(
288
+ lambda: Policies(batch, entries, scenario, agents, True, firsts), load_seconds
289
+ )
290
+ runner.request()
291
+ if not runner.wait(first_call_seconds):
292
+ raise PolicyMessageError('server.policy.first', count=f'{first_call_seconds:g}')
293
+ except BaseException:
294
+ runner.close()
295
+ self.batch.close()
296
+ raise
297
+ self.runner = runner
298
+ state = self.batch.get_state(0)
299
+ self.lineup = self.reader.lineup(state)
300
+ self.frames = [self.reader.frame(state)]
301
+ self.actions: list[list[int]] = []
302
+ self.done = False
303
+ played = [round(float(value), 4) for value in self.batch.difficulty[0].tolist()]
304
+ two = all(self.humans)
305
+ named = side_names(tournament)
306
+ self.teams = []
307
+ for side, team in enumerate(_teams.match_teams(*self.team_ids)):
308
+ # A tournament names the side of an agent as its entrant, such as Built-in AI 0.80.
309
+ # Names that cuju makes, such as You, travel as labels, and a person's name as text.
310
+ name = _teams.shown_name(team)
311
+ if not self.humans[side]:
312
+ name = named[side] or name
313
+ else:
314
+ person = named[side] or (
315
+ _messages.label('server.names.player', number=side + 1)
316
+ if two
317
+ else _messages.label('server.names.you')
318
+ )
319
+ if team['id'] != _teams.BUILTIN:
320
+ person = _messages.label('server.names.person_with', person=person, team=name)
321
+ name = person
322
+ made = ('name_id', 'name_values')
323
+ kept = {key: value for key, value in team.items() if key not in made}
324
+ self.teams.append(
325
+ {
326
+ **kept,
327
+ **_messages.named('name', name),
328
+ 'ability': played[side],
329
+ 'person': self.humans[side],
330
+ }
331
+ )
332
+
333
+ @property
334
+ def title(self) -> dict[str, Any]:
335
+ """Returns the title of the game as a label, its teams by name, after its tournament
336
+ match, which reads as English text in `title['text']`."""
337
+ return game_title([_teams.shown_name(team) for team in self.teams], self.tournament)
338
+
339
+ def step(
340
+ self,
341
+ inputs: dict[int, tuple[frozenset[str], frozenset[str]]],
342
+ budget: float | None = None,
343
+ ) -> bytes:
344
+ """Plays one step with the held and pressed inputs of each person's side, on the screen.
345
+
346
+ Args:
347
+ inputs: The held inputs and the pressed buttons of each person's side.
348
+ budget: The seconds that the submissions have for their answer from when they saw the
349
+ step, or `None` to wait for it however long it takes.
350
+
351
+ Returns:
352
+ The frame of the step.
353
+
354
+ Raises:
355
+ PolicyError: If a submission failed or stopped answering, before the step is played.
356
+ """
357
+ if self._failure is not None:
358
+ raise self._failure
359
+ if self.runner is not None:
360
+ row = self.runner.actions(budget)[0].tolist()
361
+ else:
362
+ row = [0] * sum(self.counts)
363
+ for side in self.sides:
364
+ held, pressed = inputs.get(side, (frozenset(), frozenset()))
365
+ row[self.person_column[side]] = self.controllers[side].act(
366
+ own_frame(held, side), pressed
367
+ )
368
+ self.actions.append(row)
369
+ _, _, finished, _ = self.batch.step(torch.tensor([row], dtype=torch.int32))
370
+ self.done = bool(finished[0])
371
+ frame = self.reader.frame(self.batch.get_state(0), 1 if self.done else 0)
372
+ self.frames.append(frame)
373
+ if self.shared:
374
+ active = self.batch.raw()['active'][0].tolist()
375
+ for side in self.shared:
376
+ self.controlled[side] = int(active[self.person_column[side]])
377
+ if self.runner is not None and not self.done:
378
+ # The submissions see the new step at once, and answer while the game waits for it.
379
+ try:
380
+ self.runner.request()
381
+ except PolicyError as error:
382
+ self._failure = error
383
+ return frame
384
+
385
+ def header(self) -> bytes:
386
+ """Returns the header of the game so far, as its recording holds it."""
387
+ provenance = {
388
+ 'source': 'human_game',
389
+ 'seed': self.seed,
390
+ 'scenario': self.scenario,
391
+ 'humans': list(self.humans),
392
+ 'teams': list(self.team_ids),
393
+ 'agent_counts': list(self.counts),
394
+ 'action_set': self.action_set,
395
+ 'ability': [team['ability'] for team in self.teams],
396
+ }
397
+ if self.runner is not None:
398
+ provenance['late_steps'] = self.runner.late
399
+ if self.length is not None:
400
+ provenance['length'] = self.length
401
+ if self.tournament is not None:
402
+ provenance['tournament'] = self.tournament
403
+ return _recording.header(
404
+ self.title,
405
+ self.scenario,
406
+ self.lineup,
407
+ self.teams,
408
+ len(self.frames),
409
+ _recording.scenario_timing(self.batch.get_state(0)),
410
+ provenance,
411
+ )
412
+
413
+ def save(self) -> Path:
414
+ """Saves the game so far as a recording in the library and returns its path."""
415
+ return _library.save(self.header(), self.frames)
416
+
417
+ def close(self) -> None:
418
+ """Frees the environment and lets the thread of the submissions end."""
419
+ if self.runner is not None:
420
+ self.runner.close()
421
+ self.batch.close()
422
+
423
+
424
+ class _Commands:
425
+ """Reads the server's commands from standard input on a thread of its own."""
426
+
427
+ def __init__(self, stream: TextIO) -> None:
428
+ self.queue: queue.Queue[dict[str, Any] | None] = queue.Queue()
429
+ threading.Thread(target=self._read, args=(stream,), daemon=True).start()
430
+
431
+ def _read(self, stream: TextIO) -> None:
432
+ for line in stream:
433
+ try:
434
+ command = json.loads(line)
435
+ except ValueError:
436
+ continue
437
+ if isinstance(command, dict):
438
+ self.queue.put(command)
439
+ # The server closed the channel, so the game ends.
440
+ self.queue.put(None)
441
+
442
+
443
+ def run(game: Game, commands: _Commands, source: _live.LiveSource, pace: float) -> str:
444
+ """Steps the game at `pace` steps a second while it plays, and returns why it ended.
445
+
446
+ The game waits for its first resume, so the page sees the kick-off. Each step takes the inputs
447
+ that arrived last, together with every button pressed since the step before. A submission that
448
+ fails or stops answering ends the game, with the reason in `game.error`.
449
+ """
450
+ held: dict[int, frozenset[str]] = {side: frozenset() for side in game.sides}
451
+ pressed: dict[int, set[str]] = {side: set() for side in game.sides}
452
+ paused, reason = True, 'ready'
453
+ contact = time.monotonic()
454
+ due = contact
455
+ score = None
456
+ controlled = list(game.controlled)
457
+ _report(state='ready', step=0, score=[0, 0])
458
+ while not game.done:
459
+ timeout = max(0.0, due - time.monotonic()) if not paused else 0.25
460
+ try:
461
+ command = commands.queue.get(timeout=timeout)
462
+ except queue.Empty:
463
+ command = {}
464
+ now = time.monotonic()
465
+ if command is None or command.get('quit'):
466
+ return 'quit'
467
+ if command:
468
+ contact = now
469
+ # A pause for silence lifts by itself once the page is heard again, and a pause the
470
+ # person chose waits for the person.
471
+ if paused and reason == 'input' and 'paused' not in command:
472
+ paused, reason = False, 'page'
473
+ due = now
474
+ _report(state='playing', reason='input', step=len(game.actions))
475
+ side = command.get('side')
476
+ if isinstance(side, int) and side in held:
477
+ held[side] = frozenset(command.get('held', ())) & frozenset(INPUTS)
478
+ pressed[side].update(frozenset(command.get('pressed', ())) & frozenset(BUTTONS))
479
+ if 'paused' in command and bool(command['paused']) != paused:
480
+ paused, reason = bool(command['paused']), 'page'
481
+ due = now
482
+ _report(state='paused' if paused else 'playing', reason=reason, step=len(game.actions))
483
+ if now - contact > END_AFTER_SECONDS:
484
+ return 'timeout'
485
+ if not paused and now - contact > PAUSE_AFTER_SECONDS:
486
+ paused, reason = True, 'input'
487
+ _report(state='paused', reason=reason, step=len(game.actions))
488
+ if paused or time.monotonic() < due:
489
+ continue
490
+ inputs = {side: (held[side], frozenset(pressed[side])) for side in game.sides}
491
+ for side in game.sides:
492
+ pressed[side].clear()
493
+ try:
494
+ frame = game.step(inputs, POLICY_BUDGET / pace)
495
+ except PolicyError as error:
496
+ game.error = str(error)
497
+ game.error_ids = _messages.id_fields(error)
498
+ return 'policy'
499
+ source.push(frame, game.lineup)
500
+ # A late step starts the clock again, so a slow moment never brings a burst of steps.
501
+ due = max(due + 1 / pace, time.monotonic() - 2 / pace)
502
+ now_score = list(_SCORE.unpack_from(frame, 8))
503
+ streak = game.runner.streak if game.runner is not None else 0
504
+ moved = game.controlled != controlled
505
+ if now_score != score or len(game.actions) % 10 == 0 or streak == LATE_STREAK or moved:
506
+ score, controlled = now_score, list(game.controlled)
507
+ _report(state='playing', step=len(game.actions), score=score, **_status(game))
508
+ # A full match ends at full time, and any other scenario at the end of its episode.
509
+ timing = _recording.scenario_timing(game.batch.get_state(0))
510
+ return 'full time' if timing['full_match'] else 'episode'
511
+
512
+
513
+ def _status(game: Game) -> dict[str, Any]:
514
+ """Returns what a report says of the play, the people's actions, players and late steps.
515
+
516
+ The actions are those that the engine took for each person's agent on the last step, as GRF's
517
+ controller logic turned the keys and buttons into them, and `None` on a side without a person.
518
+ """
519
+ report: dict[str, Any] = {}
520
+ if game.actions:
521
+ report['actions'] = [
522
+ game.actions[-1][game.person_column[side]] if side in game.sides else None
523
+ for side in (0, 1)
524
+ ]
525
+ if game.shared:
526
+ report['controlled'] = game.controlled
527
+ if game.runner is not None:
528
+ report.update(late=game.runner.late, streak=game.runner.streak)
529
+ return report
530
+
531
+
532
+ def _waited_arguments(stream: TextIO) -> list[str] | None:
533
+ """Returns the arguments of a game that a process kept ready reads from its first line.
534
+
535
+ The server writes them as one JSON list of strings, and a closed or unreadable channel yields
536
+ `None`, for a process the server no longer needs.
537
+ """
538
+ try:
539
+ arguments = json.loads(stream.readline() or 'null')
540
+ except (OSError, ValueError):
541
+ return None
542
+ if isinstance(arguments, list) and all(isinstance(value, str) for value in arguments):
543
+ return arguments
544
+ return None
545
+
546
+
547
+ def main(arguments: list[str] | None = None) -> None:
548
+ """Plays the game that the command line names, as the server asks.
549
+
550
+ With `--warm` alone, the process has already loaded torch, cuju and every module of a game,
551
+ and waits for the arguments of its game as one JSON list on the first line of standard input,
552
+ so the game starts as soon as the server sends them. Such a process plays that one game exactly
553
+ as a process started with the arguments would, and it ends without a game when its input
554
+ closes.
555
+ """
556
+ global _reports
557
+ if arguments is None:
558
+ arguments = sys.argv[1:]
559
+ if arguments == ['--warm']:
560
+ arguments = _waited_arguments(sys.stdin)
561
+ if arguments is None:
562
+ return
563
+ parser = argparse.ArgumentParser(prog='python -m cuju.render._playing.game')
564
+ parser.add_argument('--scenario', default='11_vs_11_kaggle')
565
+ parser.add_argument('--left', choices=('person', 'builtin'), default='person')
566
+ parser.add_argument('--right', choices=('person', 'builtin'), default='builtin')
567
+ parser.add_argument('--left-team', default=_teams.BUILTIN)
568
+ parser.add_argument('--right-team', default=_teams.BUILTIN)
569
+ parser.add_argument('--seed', type=int, default=None)
570
+ parser.add_argument('--left-ability', type=float, default=None)
571
+ parser.add_argument('--right-ability', type=float, default=None)
572
+ parser.add_argument('--record', action='store_true')
573
+ parser.add_argument('--pace', type=float, default=STEPS_PER_SECOND)
574
+ parser.add_argument('--length', type=int, default=None)
575
+ parser.add_argument('--tournament', type=json.loads, default=None)
576
+ options = parser.parse_args(arguments)
577
+ # The reports keep a copy of standard output, and everything else written there goes to
578
+ # standard error, so nothing printed by a library can pass for a report.
579
+ sys.stdout.flush()
580
+ _reports = os.fdopen(os.dup(1), 'w', encoding='utf-8')
581
+ os.dup2(2, 1)
582
+ sys.stdout = sys.stderr
583
+ commands = _Commands(sys.stdin)
584
+ try:
585
+ game = Game(
586
+ options.scenario,
587
+ (options.left == 'person', options.right == 'person'),
588
+ (options.left_ability, options.right_ability),
589
+ options.seed,
590
+ teams=(options.left_team, options.right_team),
591
+ length=options.length,
592
+ tournament=options.tournament,
593
+ )
594
+ except PolicyError as error:
595
+ _report(error=str(error), **_messages.id_fields(error))
596
+ sys.exit(1)
597
+ except Exception as error:
598
+ _report(error=_messages.described(error), **_messages.id_fields(error))
599
+ sys.exit(1)
600
+ source = _live.LiveSource(game.batch, 0, game.title, game.teams, game.scenario, announce=False)
601
+ saved = None
602
+ try:
603
+ source.push(game.frames[0], game.lineup)
604
+ _report(
605
+ port=source.port,
606
+ seed=game.seed,
607
+ teams=[team['name'] for team in game.teams],
608
+ team_labels=[
609
+ label if isinstance(label := _teams.shown_name(team), dict) else None
610
+ for team in game.teams
611
+ ],
612
+ )
613
+ ending = run(game, commands, source, max(0.1, options.pace))
614
+ if options.record and len(game.frames) > 1:
615
+ saved = game.save().stem
616
+ # The people's achievements, by the rules that teams earn by, saved or not.
617
+ earned = None
618
+ with contextlib.suppress(Exception):
619
+ earned = _achievements.for_game(game.header(), game.frames, game.sides)
620
+ _report(
621
+ state='ended',
622
+ ending=ending,
623
+ step=len(game.actions),
624
+ match=saved,
625
+ error=game.error,
626
+ **game.error_ids,
627
+ achievements=earned,
628
+ **_status(game),
629
+ )
630
+ # The page reads the last frames before the stream closes.
631
+ time.sleep(0.5)
632
+ except Exception as error:
633
+ # A game that stops for any other reason still keeps what it played.
634
+ if options.record and saved is None and len(game.frames) > 1:
635
+ with contextlib.suppress(Exception):
636
+ saved = game.save().stem
637
+ _report(error=_messages.described(error), match=saved, **_messages.id_fields(error))
638
+ sys.exit(1)
639
+ finally:
640
+ source.close()
641
+ game.close()
642
+
643
+
644
+ if __name__ == '__main__':
645
+ main()