cuju-engine 0.3.0__py3-none-win_amd64.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 (222) hide show
  1. cuju/__init__.py +217 -0
  2. cuju/__main__.py +262 -0
  3. cuju/_batch/__init__.py +4 -0
  4. cuju/_batch/allocator.py +52 -0
  5. cuju/_batch/assets.py +68 -0
  6. cuju/_batch/environment.py +1890 -0
  7. cuju/_batch/frame_stack.py +114 -0
  8. cuju/_batch/library.py +190 -0
  9. cuju/_batch/log.py +103 -0
  10. cuju/_batch/memory.py +70 -0
  11. cuju/_batch/operators.py +55 -0
  12. cuju/_batch/pinned.py +39 -0
  13. cuju/_batch/pixels.py +207 -0
  14. cuju/_batch/state.py +77 -0
  15. cuju/_checksums.py +60 -0
  16. cuju/_cli_contract.py +244 -0
  17. cuju/_cli_parsers.py +191 -0
  18. cuju/_completion.py +277 -0
  19. cuju/_dump_to_txt.py +66 -0
  20. cuju/_grf_config.py +331 -0
  21. cuju/_library_path.py +141 -0
  22. cuju/_media.py +113 -0
  23. cuju/_pixels.py +276 -0
  24. cuju/_plugins.py +106 -0
  25. cuju/_python_players.py +224 -0
  26. cuju/_replay_command.py +109 -0
  27. cuju/_replay_player.py +42 -0
  28. cuju/_replays.py +414 -0
  29. cuju/_script_helpers.py +109 -0
  30. cuju/_version.py +6 -0
  31. cuju/action_log.py +371 -0
  32. cuju/check.py +596 -0
  33. cuju/cuju_cpu.dll +0 -0
  34. cuju/cuju_cuda.dll +0 -0
  35. cuju/cuju_render.dll +0 -0
  36. cuju/data/SHA256SUMS +20 -0
  37. cuju/data/animations.bin +0 -0
  38. cuju/data/assets/11_vs_11_competition_l0_r0.cjb +0 -0
  39. cuju/data/assets/11_vs_11_easy_stochastic_l0_r0.cjb +0 -0
  40. cuju/data/assets/11_vs_11_hard_stochastic_l0_r0.cjb +0 -0
  41. cuju/data/assets/11_vs_11_kaggle_l0_r0.cjb +0 -0
  42. cuju/data/assets/11_vs_11_stochastic_l0_r0.cjb +0 -0
  43. cuju/data/assets/1_vs_1_easy_l0_r0.cjb +0 -0
  44. cuju/data/assets/5_vs_5_l0_r0.cjb +0 -0
  45. cuju/data/assets/academy_3_vs_1_with_keeper_l0_r0.cjb +0 -0
  46. cuju/data/assets/academy_corner_l0_r0.cjb +0 -0
  47. cuju/data/assets/academy_counterattack_easy_l0_r0.cjb +0 -0
  48. cuju/data/assets/academy_counterattack_hard_l0_r0.cjb +0 -0
  49. cuju/data/assets/academy_empty_goal_close_l0_r0.cjb +0 -0
  50. cuju/data/assets/academy_empty_goal_l0_r0.cjb +0 -0
  51. cuju/data/assets/academy_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
  52. cuju/data/assets/academy_run_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
  53. cuju/data/assets/academy_run_to_score_l0_r0.cjb +0 -0
  54. cuju/data/assets/academy_run_to_score_with_keeper_l0_r0.cjb +0 -0
  55. cuju/data/assets/academy_single_goal_versus_lazy_l0_r0.cjb +0 -0
  56. cuju/data/assets/test_example_multiagent_l0_r0.cjb +0 -0
  57. cuju/data/digests.json +186 -0
  58. cuju/data/render_digests.json.z +0 -0
  59. cuju/data/scenarios/11_vs_11_competition.py +45 -0
  60. cuju/data/scenarios/11_vs_11_easy_stochastic.py +44 -0
  61. cuju/data/scenarios/11_vs_11_hard_stochastic.py +44 -0
  62. cuju/data/scenarios/11_vs_11_kaggle.py +46 -0
  63. cuju/data/scenarios/11_vs_11_stochastic.py +44 -0
  64. cuju/data/scenarios/1_vs_1_easy.py +25 -0
  65. cuju/data/scenarios/5_vs_5.py +33 -0
  66. cuju/data/scenarios/academy_3_vs_1_with_keeper.py +28 -0
  67. cuju/data/scenarios/academy_corner.py +45 -0
  68. cuju/data/scenarios/academy_counterattack_easy.py +45 -0
  69. cuju/data/scenarios/academy_counterattack_hard.py +45 -0
  70. cuju/data/scenarios/academy_empty_goal.py +25 -0
  71. cuju/data/scenarios/academy_empty_goal_close.py +25 -0
  72. cuju/data/scenarios/academy_pass_and_shoot_with_keeper.py +27 -0
  73. cuju/data/scenarios/academy_run_pass_and_shoot_with_keeper.py +27 -0
  74. cuju/data/scenarios/academy_run_to_score.py +30 -0
  75. cuju/data/scenarios/academy_run_to_score_with_keeper.py +30 -0
  76. cuju/data/scenarios/academy_single_goal_versus_lazy.py +49 -0
  77. cuju/data/scenarios/test_example_multiagent.py +28 -0
  78. cuju/dumps.py +942 -0
  79. cuju/engine_status.py +106 -0
  80. cuju/env.py +1168 -0
  81. cuju/errors.py +108 -0
  82. cuju/gfootball/GRF_SOURCES +86 -0
  83. cuju/gfootball/__init__.py +60 -0
  84. cuju/gfootball/_cv2.py +43 -0
  85. cuju/gfootball/_gym/__init__.py +88 -0
  86. cuju/gfootball/_gym/_vendored/GYM_SOURCES +22 -0
  87. cuju/gfootball/_gym/_vendored/__init__.py +43 -0
  88. cuju/gfootball/_gym/_vendored/core.py +361 -0
  89. cuju/gfootball/_gym/_vendored/envs/__init__.py +19 -0
  90. cuju/gfootball/_gym/_vendored/envs/registration.py +284 -0
  91. cuju/gfootball/_gym/_vendored/error.py +230 -0
  92. cuju/gfootball/_gym/_vendored/logger.py +56 -0
  93. cuju/gfootball/_gym/_vendored/spaces/__init__.py +30 -0
  94. cuju/gfootball/_gym/_vendored/spaces/box.py +171 -0
  95. cuju/gfootball/_gym/_vendored/spaces/dict.py +162 -0
  96. cuju/gfootball/_gym/_vendored/spaces/discrete.py +41 -0
  97. cuju/gfootball/_gym/_vendored/spaces/multi_binary.py +61 -0
  98. cuju/gfootball/_gym/_vendored/spaces/multi_discrete.py +77 -0
  99. cuju/gfootball/_gym/_vendored/spaces/space.py +94 -0
  100. cuju/gfootball/_gym/_vendored/spaces/tuple.py +96 -0
  101. cuju/gfootball/_gym/_vendored/spaces/utils.py +228 -0
  102. cuju/gfootball/_gym/_vendored/utils/__init__.py +13 -0
  103. cuju/gfootball/_gym/_vendored/utils/closer.py +72 -0
  104. cuju/gfootball/_gym/_vendored/utils/colorize.py +36 -0
  105. cuju/gfootball/_gym/_vendored/utils/ezpickle.py +37 -0
  106. cuju/gfootball/_gym/_vendored/utils/json_utils.py +27 -0
  107. cuju/gfootball/_gym/_vendored/utils/seeding.py +101 -0
  108. cuju/gfootball/_gym/_vendored/version.py +5 -0
  109. cuju/gfootball/_gym/_vendored/wrappers/__init__.py +8 -0
  110. cuju/gfootball/_gym/_vendored/wrappers/order_enforcing.py +20 -0
  111. cuju/gfootball/_gym/_vendored/wrappers/time_limit.py +31 -0
  112. cuju/gfootball/dump_to_txt.py +49 -0
  113. cuju/gfootball/dump_to_video.py +33 -0
  114. cuju/gfootball/env/__init__.py +271 -0
  115. cuju/gfootball/env/config.py +163 -0
  116. cuju/gfootball/env/constants.py +33 -0
  117. cuju/gfootball/env/controller_base.py +114 -0
  118. cuju/gfootball/env/event_queue.py +54 -0
  119. cuju/gfootball/env/football_action_set.py +220 -0
  120. cuju/gfootball/env/football_action_set_test.py +76 -0
  121. cuju/gfootball/env/football_env.py +225 -0
  122. cuju/gfootball/env/football_env_core.py +447 -0
  123. cuju/gfootball/env/football_env_test.py +692 -0
  124. cuju/gfootball/env/gym_test.py +47 -0
  125. cuju/gfootball/env/observation_preprocessing.py +94 -0
  126. cuju/gfootball/env/observation_processor.py +526 -0
  127. cuju/gfootball/env/observation_rotation.py +163 -0
  128. cuju/gfootball/env/observation_rotation_test.py +84 -0
  129. cuju/gfootball/env/player_base.py +46 -0
  130. cuju/gfootball/env/players/__init__.py +16 -0
  131. cuju/gfootball/env/players/agent.py +39 -0
  132. cuju/gfootball/env/players/bot.py +217 -0
  133. cuju/gfootball/env/players/gamepad.py +81 -0
  134. cuju/gfootball/env/players/keyboard.py +72 -0
  135. cuju/gfootball/env/players/lazy.py +31 -0
  136. cuju/gfootball/env/players/ppo2_cnn.py +119 -0
  137. cuju/gfootball/env/players/replay.py +40 -0
  138. cuju/gfootball/env/remote_football_env.py +189 -0
  139. cuju/gfootball/env/scenario_builder.py +125 -0
  140. cuju/gfootball/env/script_helpers.py +130 -0
  141. cuju/gfootball/env/script_helpers_test.py +107 -0
  142. cuju/gfootball/env/wrappers.py +440 -0
  143. cuju/gfootball/env/wrappers_test.py +150 -0
  144. cuju/gfootball/eval_server/__init__.py +17 -0
  145. cuju/gfootball/eval_server/config.py +30 -0
  146. cuju/gfootball/eval_server/example_client.py +107 -0
  147. cuju/gfootball/eval_server/proto/game_server.proto +62 -0
  148. cuju/gfootball/eval_server/proto/game_server_pb2.py +501 -0
  149. cuju/gfootball/eval_server/proto/game_server_pb2_grpc.py +113 -0
  150. cuju/gfootball/eval_server/proto/master.proto +25 -0
  151. cuju/gfootball/eval_server/proto/master_pb2.py +184 -0
  152. cuju/gfootball/eval_server/proto/master_pb2_grpc.py +62 -0
  153. cuju/gfootball/eval_server/utils.py +52 -0
  154. cuju/gfootball/examples/__init__.py +16 -0
  155. cuju/gfootball/examples/models.py +66 -0
  156. cuju/gfootball/examples/run_multiagent_rllib.py +140 -0
  157. cuju/gfootball/examples/run_ppo2.py +123 -0
  158. cuju/gfootball/play_game.py +73 -0
  159. cuju/gfootball/replay.py +43 -0
  160. cuju/gfootball/scenarios/11_vs_11_competition.py +59 -0
  161. cuju/gfootball/scenarios/11_vs_11_easy_stochastic.py +57 -0
  162. cuju/gfootball/scenarios/11_vs_11_hard_stochastic.py +57 -0
  163. cuju/gfootball/scenarios/11_vs_11_kaggle.py +60 -0
  164. cuju/gfootball/scenarios/11_vs_11_stochastic.py +57 -0
  165. cuju/gfootball/scenarios/1_vs_1_easy.py +39 -0
  166. cuju/gfootball/scenarios/5_vs_5.py +46 -0
  167. cuju/gfootball/scenarios/__init__.py +31 -0
  168. cuju/gfootball/scenarios/academy_3_vs_1_with_keeper.py +42 -0
  169. cuju/gfootball/scenarios/academy_corner.py +59 -0
  170. cuju/gfootball/scenarios/academy_counterattack_easy.py +59 -0
  171. cuju/gfootball/scenarios/academy_counterattack_hard.py +59 -0
  172. cuju/gfootball/scenarios/academy_empty_goal.py +39 -0
  173. cuju/gfootball/scenarios/academy_empty_goal_close.py +39 -0
  174. cuju/gfootball/scenarios/academy_pass_and_shoot_with_keeper.py +41 -0
  175. cuju/gfootball/scenarios/academy_run_pass_and_shoot_with_keeper.py +41 -0
  176. cuju/gfootball/scenarios/academy_run_to_score.py +44 -0
  177. cuju/gfootball/scenarios/academy_run_to_score_with_keeper.py +44 -0
  178. cuju/gfootball/scenarios/academy_single_goal_versus_lazy.py +63 -0
  179. cuju/gfootball/scenarios/test_example_multiagent.py +42 -0
  180. cuju/gfootball/scenarios/tests/11_vs_11_deterministic.py +58 -0
  181. cuju/gfootball/scenarios/tests/11_vs_11_easy_deterministic.py +58 -0
  182. cuju/gfootball/scenarios/tests/11_vs_11_hard_deterministic.py +58 -0
  183. cuju/gfootball/scenarios/tests/11_vs_11_single_goal_deterministic.py +58 -0
  184. cuju/gfootball/scenarios/tests/11_vs_11_single_goal_stochastic.py +58 -0
  185. cuju/gfootball/scenarios/tests/11_vs_4_offence_deterministic.py +47 -0
  186. cuju/gfootball/scenarios/tests/11_vs_4_offence_stochastic.py +47 -0
  187. cuju/gfootball/scenarios/tests/__init__.py +31 -0
  188. cuju/gfootball/scenarios/tests/corner_test.py +38 -0
  189. cuju/gfootball/scenarios/tests/goal_test.py +35 -0
  190. cuju/gfootball/scenarios/tests/keeper_test.py +38 -0
  191. cuju/gfootball/scenarios/tests/kickoff_for_goal_loosing_team_test.py +34 -0
  192. cuju/gfootball/scenarios/tests/multiagent_wrapper.py +60 -0
  193. cuju/gfootball/scenarios/tests/offside_test.py +39 -0
  194. cuju/gfootball/scenarios/tests/penalty.py +34 -0
  195. cuju/gfootball/scenarios/tests/second_half.py +33 -0
  196. cuju/gfootball/scenarios/tests/symmetric.py +53 -0
  197. cuju/gfootball_engine/__init__.py +31 -0
  198. cuju/gfootball_engine/_gameplayfootball.py +1624 -0
  199. cuju/gfootball_engine/_native.py +193 -0
  200. cuju/gfootball_engine/_pickle_names.py +114 -0
  201. cuju/gfootball_engine/_render_hooks.py +156 -0
  202. cuju/kaggle.py +425 -0
  203. cuju/multi_device.py +401 -0
  204. cuju/players.py +260 -0
  205. cuju/raw.py +93 -0
  206. cuju/scenarios.py +661 -0
  207. cuju/state.py +211 -0
  208. cuju/wrappers.py +325 -0
  209. cuju_engine-0.3.0.dist-info/METADATA +325 -0
  210. cuju_engine-0.3.0.dist-info/RECORD +222 -0
  211. cuju_engine-0.3.0.dist-info/WHEEL +5 -0
  212. cuju_engine-0.3.0.dist-info/entry_points.txt +4 -0
  213. cuju_engine-0.3.0.dist-info/licenses/LICENSE +202 -0
  214. cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +31 -0
  215. cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSL-1.0.txt +23 -0
  216. cuju_engine-0.3.0.dist-info/licenses/LICENSES/LGPL-2.1-or-later.txt +502 -0
  217. cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-Mesa.txt +26 -0
  218. cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-gym.txt +23 -0
  219. cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT.txt +23 -0
  220. cuju_engine-0.3.0.dist-info/licenses/LICENSES/SunPro.txt +8 -0
  221. cuju_engine-0.3.0.dist-info/licenses/LICENSES/Zlib.txt +20 -0
  222. cuju_engine-0.3.0.dist-info/licenses/NOTICE +56 -0
@@ -0,0 +1,230 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import sys
6
+
7
+
8
+ class Error(Exception):
9
+ pass
10
+
11
+
12
+ # Local errors
13
+
14
+
15
+ class Unregistered(Error):
16
+ """Raised when the user requests an item from the registry that does
17
+ not actually exist.
18
+ """
19
+
20
+ pass
21
+
22
+
23
+ class UnregisteredEnv(Unregistered):
24
+ """Raised when the user requests an env from the registry that does
25
+ not actually exist.
26
+ """
27
+
28
+ pass
29
+
30
+
31
+ class UnregisteredBenchmark(Unregistered):
32
+ """Raised when the user requests an env from the registry that does
33
+ not actually exist.
34
+ """
35
+
36
+ pass
37
+
38
+
39
+ class DeprecatedEnv(Error):
40
+ """Raised when the user requests an env from the registry with an
41
+ older version number than the latest env with the same name.
42
+ """
43
+
44
+ pass
45
+
46
+
47
+ class UnseedableEnv(Error):
48
+ """Raised when the user tries to seed an env that does not support
49
+ seeding.
50
+ """
51
+
52
+ pass
53
+
54
+
55
+ class DependencyNotInstalled(Error):
56
+ pass
57
+
58
+
59
+ class UnsupportedMode(Exception):
60
+ """Raised when the user requests a rendering mode not supported by the
61
+ environment.
62
+ """
63
+
64
+ pass
65
+
66
+
67
+ class ResetNeeded(Exception):
68
+ """When the monitor is active, raised when the user tries to step an
69
+ environment that's already done.
70
+ """
71
+
72
+ pass
73
+
74
+
75
+ class ResetNotAllowed(Exception):
76
+ """When the monitor is active, raised when the user tries to step an
77
+ environment that's not yet done.
78
+ """
79
+
80
+ pass
81
+
82
+
83
+ class InvalidAction(Exception):
84
+ """Raised when the user performs an action not contained within the
85
+ action space
86
+ """
87
+
88
+ pass
89
+
90
+
91
+ # API errors
92
+
93
+
94
+ class APIError(Error):
95
+ def __init__(
96
+ self,
97
+ message=None,
98
+ http_body=None,
99
+ http_status=None,
100
+ json_body=None,
101
+ headers=None,
102
+ ):
103
+ super(APIError, self).__init__(message)
104
+
105
+ if http_body and hasattr(http_body, "decode"):
106
+ try:
107
+ http_body = http_body.decode("utf-8")
108
+ except:
109
+ http_body = (
110
+ "<Could not decode body as utf-8. "
111
+ "Please report to gym@openai.com>"
112
+ )
113
+
114
+ self._message = message
115
+ self.http_body = http_body
116
+ self.http_status = http_status
117
+ self.json_body = json_body
118
+ self.headers = headers or {}
119
+ self.request_id = self.headers.get("request-id", None)
120
+
121
+ def __unicode__(self):
122
+ if self.request_id is not None:
123
+ msg = self._message or "<empty message>"
124
+ return u"Request {0}: {1}".format(self.request_id, msg)
125
+ else:
126
+ return self._message
127
+
128
+ def __str__(self):
129
+ try: # Python 2
130
+ return unicode(self).encode("utf-8")
131
+ except NameError: # Python 3
132
+ return self.__unicode__()
133
+
134
+
135
+ class APIConnectionError(APIError):
136
+ pass
137
+
138
+
139
+ class InvalidRequestError(APIError):
140
+ def __init__(
141
+ self,
142
+ message,
143
+ param,
144
+ http_body=None,
145
+ http_status=None,
146
+ json_body=None,
147
+ headers=None,
148
+ ):
149
+ super(InvalidRequestError, self).__init__(
150
+ message, http_body, http_status, json_body, headers
151
+ )
152
+ self.param = param
153
+
154
+
155
+ class AuthenticationError(APIError):
156
+ pass
157
+
158
+
159
+ class RateLimitError(APIError):
160
+ pass
161
+
162
+
163
+ # Video errors
164
+
165
+
166
+ class VideoRecorderError(Error):
167
+ pass
168
+
169
+
170
+ class InvalidFrame(Error):
171
+ pass
172
+
173
+
174
+ # Wrapper errors
175
+
176
+
177
+ class DoubleWrapperError(Error):
178
+ pass
179
+
180
+
181
+ class WrapAfterConfigureError(Error):
182
+ pass
183
+
184
+
185
+ class RetriesExceededError(Error):
186
+ pass
187
+
188
+
189
+ # Vectorized environments errors
190
+
191
+
192
+ class AlreadyPendingCallError(Exception):
193
+ """
194
+ Raised when `reset`, or `step` is called asynchronously (e.g. with
195
+ `reset_async`, or `step_async` respectively), and `reset_async`, or
196
+ `step_async` (respectively) is called again (without a complete call to
197
+ `reset_wait`, or `step_wait` respectively).
198
+ """
199
+
200
+ def __init__(self, message, name):
201
+ super(AlreadyPendingCallError, self).__init__(message)
202
+ self.name = name
203
+
204
+
205
+ class NoAsyncCallError(Exception):
206
+ """
207
+ Raised when an asynchronous `reset`, or `step` is not running, but
208
+ `reset_wait`, or `step_wait` (respectively) is called.
209
+ """
210
+
211
+ def __init__(self, message, name):
212
+ super(NoAsyncCallError, self).__init__(message)
213
+ self.name = name
214
+
215
+
216
+ class ClosedEnvironmentError(Exception):
217
+ """
218
+ Trying to call `reset`, or `step`, while the environment is closed.
219
+ """
220
+
221
+ pass
222
+
223
+
224
+ class CustomSpaceError(Exception):
225
+ """
226
+ The space is a custom gym.Space instance, and is not supported by
227
+ `AsyncVectorEnv` with `shared_memory=True`.
228
+ """
229
+
230
+ pass
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import sys
6
+ import warnings
7
+
8
+ from cuju.gfootball._gym._vendored.utils import colorize
9
+
10
+ DEBUG = 10
11
+ INFO = 20
12
+ WARN = 30
13
+ ERROR = 40
14
+ DISABLED = 50
15
+
16
+ MIN_LEVEL = 30
17
+
18
+
19
+ def set_level(level):
20
+ """
21
+ Set logging threshold on current logger.
22
+ """
23
+ global MIN_LEVEL
24
+ MIN_LEVEL = level
25
+
26
+
27
+ def debug(msg, *args):
28
+ if MIN_LEVEL <= DEBUG:
29
+ print("%s: %s" % ("DEBUG", msg % args), file=sys.stderr)
30
+
31
+
32
+ def info(msg, *args):
33
+ if MIN_LEVEL <= INFO:
34
+ print("%s: %s" % ("INFO", msg % args), file=sys.stderr)
35
+
36
+
37
+ def warn(msg, *args, category=None, stacklevel=1):
38
+ if MIN_LEVEL <= WARN:
39
+ warnings.warn(
40
+ colorize("%s: %s" % ("WARN", msg % args), "yellow"),
41
+ category=category,
42
+ stacklevel=stacklevel + 1,
43
+ )
44
+
45
+
46
+ def deprecation(msg, *args):
47
+ warn(msg, *args, category=DeprecationWarning, stacklevel=2)
48
+
49
+
50
+ def error(msg, *args):
51
+ if MIN_LEVEL <= ERROR:
52
+ print(colorize("%s: %s" % ("ERROR", msg % args), "red"), file=sys.stderr)
53
+
54
+
55
+ # DEPRECATED:
56
+ setLevel = set_level
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ from cuju.gfootball._gym._vendored.spaces.space import Space
6
+ from cuju.gfootball._gym._vendored.spaces.box import Box
7
+ from cuju.gfootball._gym._vendored.spaces.discrete import Discrete
8
+ from cuju.gfootball._gym._vendored.spaces.multi_discrete import MultiDiscrete
9
+ from cuju.gfootball._gym._vendored.spaces.multi_binary import MultiBinary
10
+ from cuju.gfootball._gym._vendored.spaces.tuple import Tuple
11
+ from cuju.gfootball._gym._vendored.spaces.dict import Dict
12
+
13
+ from cuju.gfootball._gym._vendored.spaces.utils import flatdim
14
+ from cuju.gfootball._gym._vendored.spaces.utils import flatten_space
15
+ from cuju.gfootball._gym._vendored.spaces.utils import flatten
16
+ from cuju.gfootball._gym._vendored.spaces.utils import unflatten
17
+
18
+ __all__ = [
19
+ "Space",
20
+ "Box",
21
+ "Discrete",
22
+ "MultiDiscrete",
23
+ "MultiBinary",
24
+ "Tuple",
25
+ "Dict",
26
+ "flatdim",
27
+ "flatten_space",
28
+ "flatten",
29
+ "unflatten",
30
+ ]
@@ -0,0 +1,171 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import numpy as np
6
+
7
+ from .space import Space
8
+ from cuju.gfootball._gym._vendored import logger
9
+
10
+
11
+ class Box(Space):
12
+ """
13
+ A (possibly unbounded) box in R^n. Specifically, a Box represents the
14
+ Cartesian product of n closed intervals. Each interval has the form of one
15
+ of [a, b], (-oo, b], [a, oo), or (-oo, oo).
16
+
17
+ There are two common use cases:
18
+
19
+ * Identical bound for each dimension::
20
+ >>> Box(low=-1.0, high=2.0, shape=(3, 4), dtype=np.float32)
21
+ Box(3, 4)
22
+
23
+ * Independent bound for each dimension::
24
+ >>> Box(low=np.array([-1.0, -2.0]), high=np.array([2.0, 4.0]), dtype=np.float32)
25
+ Box(2,)
26
+
27
+ """
28
+
29
+ def __init__(self, low, high, shape=None, dtype=np.float32, seed=None):
30
+ assert dtype is not None, "dtype must be explicitly provided. "
31
+ self.dtype = np.dtype(dtype)
32
+
33
+ # determine shape if it isn't provided directly
34
+ if shape is not None:
35
+ shape = tuple(shape)
36
+ assert (
37
+ np.isscalar(low) or low.shape == shape
38
+ ), "low.shape doesn't match provided shape"
39
+ assert (
40
+ np.isscalar(high) or high.shape == shape
41
+ ), "high.shape doesn't match provided shape"
42
+ elif not np.isscalar(low):
43
+ shape = low.shape
44
+ assert (
45
+ np.isscalar(high) or high.shape == shape
46
+ ), "high.shape doesn't match low.shape"
47
+ elif not np.isscalar(high):
48
+ shape = high.shape
49
+ assert (
50
+ np.isscalar(low) or low.shape == shape
51
+ ), "low.shape doesn't match high.shape"
52
+ else:
53
+ raise ValueError(
54
+ "shape must be provided or inferred from the shapes of low or high"
55
+ )
56
+
57
+ if np.isscalar(low):
58
+ low = np.full(shape, low, dtype=dtype)
59
+
60
+ if np.isscalar(high):
61
+ high = np.full(shape, high, dtype=dtype)
62
+
63
+ self._shape = shape
64
+ self.low = low
65
+ self.high = high
66
+
67
+ def _get_precision(dtype):
68
+ if np.issubdtype(dtype, np.floating):
69
+ return np.finfo(dtype).precision
70
+ else:
71
+ return np.inf
72
+
73
+ low_precision = _get_precision(self.low.dtype)
74
+ high_precision = _get_precision(self.high.dtype)
75
+ dtype_precision = _get_precision(self.dtype)
76
+ if min(low_precision, high_precision) > dtype_precision:
77
+ logger.warn(
78
+ "Box bound precision lowered by casting to {}".format(self.dtype)
79
+ )
80
+ self.low = self.low.astype(self.dtype)
81
+ self.high = self.high.astype(self.dtype)
82
+
83
+ # Boolean arrays which indicate the interval type for each coordinate
84
+ self.bounded_below = -np.inf < self.low
85
+ self.bounded_above = np.inf > self.high
86
+
87
+ super(Box, self).__init__(self.shape, self.dtype, seed)
88
+
89
+ def is_bounded(self, manner="both"):
90
+ below = np.all(self.bounded_below)
91
+ above = np.all(self.bounded_above)
92
+ if manner == "both":
93
+ return below and above
94
+ elif manner == "below":
95
+ return below
96
+ elif manner == "above":
97
+ return above
98
+ else:
99
+ raise ValueError("manner is not in {'below', 'above', 'both'}")
100
+
101
+ def sample(self):
102
+ """
103
+ Generates a single random sample inside of the Box.
104
+
105
+ In creating a sample of the box, each coordinate is sampled according to
106
+ the form of the interval:
107
+
108
+ * [a, b] : uniform distribution
109
+ * [a, oo) : shifted exponential distribution
110
+ * (-oo, b] : shifted negative exponential distribution
111
+ * (-oo, oo) : normal distribution
112
+ """
113
+ high = self.high if self.dtype.kind == "f" else self.high.astype("int64") + 1
114
+ sample = np.empty(self.shape)
115
+
116
+ # Masking arrays which classify the coordinates according to interval
117
+ # type
118
+ unbounded = ~self.bounded_below & ~self.bounded_above
119
+ upp_bounded = ~self.bounded_below & self.bounded_above
120
+ low_bounded = self.bounded_below & ~self.bounded_above
121
+ bounded = self.bounded_below & self.bounded_above
122
+
123
+ # Vectorized sampling by interval type
124
+ sample[unbounded] = self.np_random.normal(size=unbounded[unbounded].shape)
125
+
126
+ sample[low_bounded] = (
127
+ self.np_random.exponential(size=low_bounded[low_bounded].shape)
128
+ + self.low[low_bounded]
129
+ )
130
+
131
+ sample[upp_bounded] = (
132
+ -self.np_random.exponential(size=upp_bounded[upp_bounded].shape)
133
+ + self.high[upp_bounded]
134
+ )
135
+
136
+ sample[bounded] = self.np_random.uniform(
137
+ low=self.low[bounded], high=high[bounded], size=bounded[bounded].shape
138
+ )
139
+ if self.dtype.kind == "i":
140
+ sample = np.floor(sample)
141
+
142
+ return sample.astype(self.dtype)
143
+
144
+ def contains(self, x):
145
+ if not isinstance(x, np.ndarray):
146
+ logger.warn("Casting input x to numpy array.")
147
+ x = np.asarray(x, dtype=self.dtype)
148
+
149
+ return (
150
+ np.can_cast(x.dtype, self.dtype)
151
+ and x.shape == self.shape
152
+ and np.all(x >= self.low)
153
+ and np.all(x <= self.high)
154
+ )
155
+
156
+ def to_jsonable(self, sample_n):
157
+ return np.array(sample_n).tolist()
158
+
159
+ def from_jsonable(self, sample_n):
160
+ return [np.asarray(sample) for sample in sample_n]
161
+
162
+ def __repr__(self):
163
+ return f"Box({self.low}, {self.high}, {self.shape}, {self.dtype})"
164
+
165
+ def __eq__(self, other):
166
+ return (
167
+ isinstance(other, Box)
168
+ and (self.shape == other.shape)
169
+ and np.allclose(self.low, other.low)
170
+ and np.allclose(self.high, other.high)
171
+ )
@@ -0,0 +1,162 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ from collections import OrderedDict
6
+ import numpy as np
7
+ from .space import Space
8
+
9
+
10
+ class Dict(Space):
11
+ """
12
+ A dictionary of simpler spaces.
13
+
14
+ Example usage:
15
+ self.observation_space = spaces.Dict({"position": spaces.Discrete(2), "velocity": spaces.Discrete(3)})
16
+
17
+ Example usage [nested]:
18
+ self.nested_observation_space = spaces.Dict({
19
+ 'sensors': spaces.Dict({
20
+ 'position': spaces.Box(low=-100, high=100, shape=(3,)),
21
+ 'velocity': spaces.Box(low=-1, high=1, shape=(3,)),
22
+ 'front_cam': spaces.Tuple((
23
+ spaces.Box(low=0, high=1, shape=(10, 10, 3)),
24
+ spaces.Box(low=0, high=1, shape=(10, 10, 3))
25
+ )),
26
+ 'rear_cam': spaces.Box(low=0, high=1, shape=(10, 10, 3)),
27
+ }),
28
+ 'ext_controller': spaces.MultiDiscrete((5, 2, 2)),
29
+ 'inner_state':spaces.Dict({
30
+ 'charge': spaces.Discrete(100),
31
+ 'system_checks': spaces.MultiBinary(10),
32
+ 'job_status': spaces.Dict({
33
+ 'task': spaces.Discrete(5),
34
+ 'progress': spaces.Box(low=0, high=100, shape=()),
35
+ })
36
+ })
37
+ })
38
+ """
39
+
40
+ def __init__(self, spaces=None, seed=None, **spaces_kwargs):
41
+ assert (spaces is None) or (
42
+ not spaces_kwargs
43
+ ), "Use either Dict(spaces=dict(...)) or Dict(foo=x, bar=z)"
44
+
45
+ if spaces is None:
46
+ spaces = spaces_kwargs
47
+ if isinstance(spaces, dict) and not isinstance(spaces, OrderedDict):
48
+ spaces = OrderedDict(sorted(list(spaces.items())))
49
+ if isinstance(spaces, list):
50
+ spaces = OrderedDict(spaces)
51
+ self.spaces = spaces
52
+ for space in spaces.values():
53
+ assert isinstance(
54
+ space, Space
55
+ ), "Values of the dict should be instances of gym.Space"
56
+ super(Dict, self).__init__(
57
+ None, None, seed
58
+ ) # None for shape and dtype, since it'll require special handling
59
+
60
+ def seed(self, seed=None):
61
+ seeds = []
62
+ if isinstance(seed, dict):
63
+ for key, seed_key in zip(self.spaces, seed):
64
+ assert key == seed_key, print(
65
+ "Key value",
66
+ seed_key,
67
+ "in passed seed dict did not match key value",
68
+ key,
69
+ "in spaces Dict.",
70
+ )
71
+ seeds += self.spaces[key].seed(seed[seed_key])
72
+ elif isinstance(seed, int):
73
+ seeds = super().seed(seed)
74
+ try:
75
+ subseeds = self.np_random.choice(
76
+ np.iinfo(int).max,
77
+ size=len(self.spaces),
78
+ replace=False, # unique subseed for each subspace
79
+ )
80
+ except ValueError:
81
+ subseeds = self.np_random.choice(
82
+ np.iinfo(int).max,
83
+ size=len(self.spaces),
84
+ replace=True, # we get more than INT_MAX subspaces
85
+ )
86
+
87
+ for subspace, subseed in zip(self.spaces.values(), subseeds):
88
+ seeds.append(subspace.seed(int(subseed))[0])
89
+ elif seed is None:
90
+ for space in self.spaces.values():
91
+ seeds += space.seed(seed)
92
+ else:
93
+ raise TypeError("Passed seed not of an expected type: dict or int or None")
94
+
95
+ return seeds
96
+
97
+ def sample(self):
98
+ return OrderedDict([(k, space.sample()) for k, space in self.spaces.items()])
99
+
100
+ def contains(self, x):
101
+ if not isinstance(x, dict) or len(x) != len(self.spaces):
102
+ return False
103
+ for k, space in self.spaces.items():
104
+ if k not in x:
105
+ return False
106
+ if not space.contains(x[k]):
107
+ return False
108
+ return True
109
+
110
+ def __getitem__(self, key):
111
+ return self.spaces[key]
112
+
113
+ def __setitem__(self, key, value):
114
+ self.spaces[key] = value
115
+
116
+ def __iter__(self):
117
+ for key in self.spaces:
118
+ yield key
119
+
120
+ def __len__(self):
121
+ return len(self.spaces)
122
+
123
+ def __contains__(self, item):
124
+ return self.contains(item)
125
+
126
+ def __repr__(self):
127
+ return (
128
+ "Dict("
129
+ + ", ".join([str(k) + ":" + str(s) for k, s in self.spaces.items()])
130
+ + ")"
131
+ )
132
+
133
+ def to_jsonable(self, sample_n):
134
+ # serialize as dict-repr of vectors
135
+ return {
136
+ key: space.to_jsonable([sample[key] for sample in sample_n])
137
+ for key, space in self.spaces.items()
138
+ }
139
+
140
+ def from_jsonable(self, sample_n):
141
+ dict_of_list = {}
142
+ for key, space in self.spaces.items():
143
+ dict_of_list[key] = space.from_jsonable(sample_n[key])
144
+ ret = []
145
+ for i, _ in enumerate(dict_of_list[key]):
146
+ entry = {}
147
+ for key, value in dict_of_list.items():
148
+ entry[key] = value[i]
149
+ ret.append(entry)
150
+ return ret
151
+
152
+ def __eq__(self, other):
153
+ return isinstance(other, Dict) and self.spaces == other.spaces
154
+
155
+ def keys(self):
156
+ return self.spaces.keys()
157
+
158
+ def values(self):
159
+ return self.spaces.values()
160
+
161
+ def items(self):
162
+ return self.spaces.items()
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2016 OpenAI (https://openai.com)
2
+ # Modified by the cuju Authors in 2026, in the lines that ci/port_gfootball.py lists.
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import numpy as np
6
+ from .space import Space
7
+
8
+
9
+ class Discrete(Space):
10
+ r"""A discrete space in :math:`\{ 0, 1, \\dots, n-1 \}`.
11
+
12
+ Example::
13
+
14
+ >>> Discrete(2)
15
+
16
+ """
17
+
18
+ def __init__(self, n, seed=None):
19
+ assert n >= 0
20
+ self.n = n
21
+ super(Discrete, self).__init__((), np.int64, seed)
22
+
23
+ def sample(self):
24
+ return self.np_random.randint(self.n)
25
+
26
+ def contains(self, x):
27
+ if isinstance(x, int):
28
+ as_int = x
29
+ elif isinstance(x, (np.generic, np.ndarray)) and (
30
+ x.dtype.char in np.typecodes["AllInteger"] and x.shape == ()
31
+ ):
32
+ as_int = int(x)
33
+ else:
34
+ return False
35
+ return as_int >= 0 and as_int < self.n
36
+
37
+ def __repr__(self):
38
+ return "Discrete(%d)" % self.n
39
+
40
+ def __eq__(self, other):
41
+ return isinstance(other, Discrete) and self.n == other.n