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,61 @@
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 MultiBinary(Space):
10
+ """
11
+ An n-shape binary space.
12
+
13
+ The argument to MultiBinary defines n, which could be a number or a `list` of numbers.
14
+
15
+ Example Usage:
16
+
17
+ >> self.observation_space = spaces.MultiBinary(5)
18
+
19
+ >> self.observation_space.sample()
20
+
21
+ array([0,1,0,1,0], dtype =int8)
22
+
23
+ >> self.observation_space = spaces.MultiBinary([3,2])
24
+
25
+ >> self.observation_space.sample()
26
+
27
+ array([[0, 0],
28
+ [0, 1],
29
+ [1, 1]], dtype=int8)
30
+
31
+ """
32
+
33
+ def __init__(self, n, seed=None):
34
+ self.n = n
35
+ if type(n) in [tuple, list, np.ndarray]:
36
+ input_n = n
37
+ else:
38
+ input_n = (n,)
39
+ super(MultiBinary, self).__init__(input_n, np.int8, seed)
40
+
41
+ def sample(self):
42
+ return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
43
+
44
+ def contains(self, x):
45
+ if isinstance(x, list) or isinstance(x, tuple):
46
+ x = np.array(x) # Promote list to array for contains check
47
+ if self.shape != x.shape:
48
+ return False
49
+ return ((x == 0) | (x == 1)).all()
50
+
51
+ def to_jsonable(self, sample_n):
52
+ return np.array(sample_n).tolist()
53
+
54
+ def from_jsonable(self, sample_n):
55
+ return [np.asarray(sample) for sample in sample_n]
56
+
57
+ def __repr__(self):
58
+ return "MultiBinary({})".format(self.n)
59
+
60
+ def __eq__(self, other):
61
+ return isinstance(other, MultiBinary) and self.n == other.n
@@ -0,0 +1,77 @@
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 cuju.gfootball._gym._vendored import logger
7
+ from .space import Space
8
+ from .discrete import Discrete
9
+
10
+
11
+ class MultiDiscrete(Space):
12
+ """
13
+ - The multi-discrete action space consists of a series of discrete action spaces with different number of actions in each
14
+ - It is useful to represent game controllers or keyboards where each key can be represented as a discrete action space
15
+ - It is parametrized by passing an array of positive integers specifying number of actions for each discrete action space
16
+
17
+ Note: Some environment wrappers assume a value of 0 always represents the NOOP action.
18
+
19
+ e.g. Nintendo Game Controller
20
+ - Can be conceptualized as 3 discrete action spaces:
21
+
22
+ 1) Arrow Keys: Discrete 5 - NOOP[0], UP[1], RIGHT[2], DOWN[3], LEFT[4] - params: min: 0, max: 4
23
+ 2) Button A: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1
24
+ 3) Button B: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1
25
+
26
+ - Can be initialized as
27
+
28
+ MultiDiscrete([ 5, 2, 2 ])
29
+
30
+ """
31
+
32
+ def __init__(self, nvec, dtype=np.int64, seed=None):
33
+ """
34
+ nvec: vector of counts of each categorical variable
35
+ """
36
+ assert (np.array(nvec) > 0).all(), "nvec (counts) have to be positive"
37
+ self.nvec = np.asarray(nvec, dtype=dtype)
38
+
39
+ super(MultiDiscrete, self).__init__(self.nvec.shape, dtype, seed)
40
+
41
+ def sample(self):
42
+ return (self.np_random.random_sample(self.nvec.shape) * self.nvec).astype(
43
+ self.dtype
44
+ )
45
+
46
+ def contains(self, x):
47
+ if isinstance(x, list):
48
+ x = np.array(x) # Promote list to array for contains check
49
+ # if nvec is uint32 and space dtype is uint32, then 0 <= x < self.nvec guarantees that x
50
+ # is within correct bounds for space dtype (even though x does not have to be unsigned)
51
+ return x.shape == self.shape and (0 <= x).all() and (x < self.nvec).all()
52
+
53
+ def to_jsonable(self, sample_n):
54
+ return [sample.tolist() for sample in sample_n]
55
+
56
+ def from_jsonable(self, sample_n):
57
+ return np.array(sample_n)
58
+
59
+ def __repr__(self):
60
+ return "MultiDiscrete({})".format(self.nvec)
61
+
62
+ def __getitem__(self, index):
63
+ nvec = self.nvec[index]
64
+ if nvec.ndim == 0:
65
+ subspace = Discrete(nvec)
66
+ else:
67
+ subspace = MultiDiscrete(nvec, self.dtype)
68
+ subspace.np_random.set_state(self.np_random.get_state()) # for reproducibility
69
+ return subspace
70
+
71
+ def __len__(self):
72
+ if self.nvec.ndim >= 2:
73
+ logger.warn("Get length of a multi-dimensional MultiDiscrete space.")
74
+ return len(self.nvec)
75
+
76
+ def __eq__(self, other):
77
+ return isinstance(other, MultiDiscrete) and np.all(self.nvec == other.nvec)
@@ -0,0 +1,94 @@
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.utils import seeding
6
+
7
+
8
+ class Space(object):
9
+ """Defines the observation and action spaces, so you can write generic
10
+ code that applies to any Env. For example, you can choose a random
11
+ action.
12
+
13
+ WARNING - Custom observation & action spaces can inherit from the `Space`
14
+ class. However, most use-cases should be covered by the existing space
15
+ classes (e.g. `Box`, `Discrete`, etc...), and container classes (`Tuple` &
16
+ `Dict`). Note that parametrized probability distributions (through the
17
+ `sample()` method), and batching functions (in `gym.vector.VectorEnv`), are
18
+ only well-defined for instances of spaces provided in gym by default.
19
+ Moreover, some implementations of Reinforcement Learning algorithms might
20
+ not handle custom spaces properly. Use custom spaces with care.
21
+ """
22
+
23
+ def __init__(self, shape=None, dtype=None, seed=None):
24
+ import numpy as np # takes about 300-400ms to import, so we load lazily
25
+
26
+ self._shape = None if shape is None else tuple(shape)
27
+ self.dtype = None if dtype is None else np.dtype(dtype)
28
+ self._np_random = None
29
+ if seed is not None:
30
+ self.seed(seed)
31
+
32
+ @property
33
+ def np_random(self):
34
+ """Lazily seed the rng since this is expensive and only needed if
35
+ sampling from this space.
36
+ """
37
+ if self._np_random is None:
38
+ self.seed()
39
+
40
+ return self._np_random
41
+
42
+ @property
43
+ def shape(self):
44
+ """Return the shape of the space as an immutable property"""
45
+ return self._shape
46
+
47
+ def sample(self):
48
+ """Randomly sample an element of this space. Can be
49
+ uniform or non-uniform sampling based on boundedness of space."""
50
+ raise NotImplementedError
51
+
52
+ def seed(self, seed=None):
53
+ """Seed the PRNG of this space."""
54
+ self._np_random, seed = seeding.np_random(seed)
55
+ return [seed]
56
+
57
+ def contains(self, x):
58
+ """
59
+ Return boolean specifying if x is a valid
60
+ member of this space
61
+ """
62
+ raise NotImplementedError
63
+
64
+ def __contains__(self, x):
65
+ return self.contains(x)
66
+
67
+ def __setstate__(self, state):
68
+ # Don't mutate the original state
69
+ state = dict(state)
70
+
71
+ # Allow for loading of legacy states.
72
+ # See:
73
+ # https://github.com/openai/gym/pull/2397 -- shape
74
+ # https://github.com/openai/gym/pull/1913 -- np_random
75
+ #
76
+ if "shape" in state:
77
+ state["_shape"] = state["shape"]
78
+ del state["shape"]
79
+ if "np_random" in state:
80
+ state["_np_random"] = state["np_random"]
81
+ del state["np_random"]
82
+
83
+ # Update our state
84
+ self.__dict__.update(state)
85
+
86
+ def to_jsonable(self, sample_n):
87
+ """Convert a batch of samples from this space to a JSONable data type."""
88
+ # By default, assume identity is JSONable
89
+ return sample_n
90
+
91
+ def from_jsonable(self, sample_n):
92
+ """Convert a JSONable data type to a batch of samples from this space."""
93
+ # By default, assume identity is JSONable
94
+ return sample_n
@@ -0,0 +1,96 @@
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 Tuple(Space):
10
+ """
11
+ A tuple (i.e., product) of simpler spaces
12
+
13
+ Example usage:
14
+ self.observation_space = spaces.Tuple((spaces.Discrete(2), spaces.Discrete(3)))
15
+ """
16
+
17
+ def __init__(self, spaces, seed=None):
18
+ self.spaces = spaces
19
+ for space in spaces:
20
+ assert isinstance(
21
+ space, Space
22
+ ), "Elements of the tuple must be instances of gym.Space"
23
+ super(Tuple, self).__init__(None, None, seed)
24
+
25
+ def seed(self, seed=None):
26
+ seeds = []
27
+
28
+ if isinstance(seed, list):
29
+ for i, space in enumerate(self.spaces):
30
+ seeds += space.seed(seed[i])
31
+ elif isinstance(seed, int):
32
+ seeds = super().seed(seed)
33
+ try:
34
+ subseeds = self.np_random.choice(
35
+ np.iinfo(int).max,
36
+ size=len(self.spaces),
37
+ replace=False, # unique subseed for each subspace
38
+ )
39
+ except ValueError:
40
+ subseeds = self.np_random.choice(
41
+ np.iinfo(int).max,
42
+ size=len(self.spaces),
43
+ replace=True, # we get more than INT_MAX subspaces
44
+ )
45
+
46
+ for subspace, subseed in zip(self.spaces, subseeds):
47
+ seeds.append(subspace.seed(int(subseed))[0])
48
+ elif seed is None:
49
+ for space in self.spaces:
50
+ seeds += space.seed(seed)
51
+ else:
52
+ raise TypeError("Passed seed not of an expected type: list or int or None")
53
+
54
+ return seeds
55
+
56
+ def sample(self):
57
+ return tuple([space.sample() for space in self.spaces])
58
+
59
+ def contains(self, x):
60
+ if isinstance(x, list):
61
+ x = tuple(x) # Promote list to tuple for contains check
62
+ return (
63
+ isinstance(x, tuple)
64
+ and len(x) == len(self.spaces)
65
+ and all(space.contains(part) for (space, part) in zip(self.spaces, x))
66
+ )
67
+
68
+ def __repr__(self):
69
+ return "Tuple(" + ", ".join([str(s) for s in self.spaces]) + ")"
70
+
71
+ def to_jsonable(self, sample_n):
72
+ # serialize as list-repr of tuple of vectors
73
+ return [
74
+ space.to_jsonable([sample[i] for sample in sample_n])
75
+ for i, space in enumerate(self.spaces)
76
+ ]
77
+
78
+ def from_jsonable(self, sample_n):
79
+ return [
80
+ sample
81
+ for sample in zip(
82
+ *[
83
+ space.from_jsonable(sample_n[i])
84
+ for i, space in enumerate(self.spaces)
85
+ ]
86
+ )
87
+ ]
88
+
89
+ def __getitem__(self, index):
90
+ return self.spaces[index]
91
+
92
+ def __len__(self):
93
+ return len(self.spaces)
94
+
95
+ def __eq__(self, other):
96
+ return isinstance(other, Tuple) and self.spaces == other.spaces
@@ -0,0 +1,228 @@
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
+ from functools import singledispatch, reduce
7
+ import numpy as np
8
+ import operator as op
9
+
10
+ from cuju.gfootball._gym._vendored.spaces import Box
11
+ from cuju.gfootball._gym._vendored.spaces import Discrete
12
+ from cuju.gfootball._gym._vendored.spaces import MultiDiscrete
13
+ from cuju.gfootball._gym._vendored.spaces import MultiBinary
14
+ from cuju.gfootball._gym._vendored.spaces import Tuple
15
+ from cuju.gfootball._gym._vendored.spaces import Dict
16
+
17
+
18
+ @singledispatch
19
+ def flatdim(space):
20
+ """Return the number of dimensions a flattened equivalent of this space
21
+ would have.
22
+
23
+ Accepts a space and returns an integer. Raises ``NotImplementedError`` if
24
+ the space is not defined in ``gym.spaces``.
25
+ """
26
+ raise NotImplementedError(f"Unknown space: `{space}`")
27
+
28
+
29
+ @flatdim.register(Box)
30
+ @flatdim.register(MultiBinary)
31
+ def flatdim_box_multibinary(space):
32
+ return reduce(op.mul, space.shape, 1)
33
+
34
+
35
+ @flatdim.register(Discrete)
36
+ def flatdim_discrete(space):
37
+ return int(space.n)
38
+
39
+
40
+ @flatdim.register(MultiDiscrete)
41
+ def flatdim_multidiscrete(space):
42
+ return int(np.sum(space.nvec))
43
+
44
+
45
+ @flatdim.register(Tuple)
46
+ def flatdim_tuple(space):
47
+ return sum([flatdim(s) for s in space.spaces])
48
+
49
+
50
+ @flatdim.register(Dict)
51
+ def flatdim_dict(space):
52
+ return sum([flatdim(s) for s in space.spaces.values()])
53
+
54
+
55
+ @singledispatch
56
+ def flatten(space, x):
57
+ """Flatten a data point from a space.
58
+
59
+ This is useful when e.g. points from spaces must be passed to a neural
60
+ network, which only understands flat arrays of floats.
61
+
62
+ Accepts a space and a point from that space. Always returns a 1D array.
63
+ Raises ``NotImplementedError`` if the space is not defined in
64
+ ``gym.spaces``.
65
+ """
66
+ raise NotImplementedError(f"Unknown space: `{space}`")
67
+
68
+
69
+ @flatten.register(Box)
70
+ @flatten.register(MultiBinary)
71
+ def flatten_box_multibinary(space, x):
72
+ return np.asarray(x, dtype=space.dtype).flatten()
73
+
74
+
75
+ @flatten.register(Discrete)
76
+ def flatten_discrete(space, x):
77
+ onehot = np.zeros(space.n, dtype=space.dtype)
78
+ onehot[x] = 1
79
+ return onehot
80
+
81
+
82
+ @flatten.register(MultiDiscrete)
83
+ def flatten_multidiscrete(space, x):
84
+ offsets = np.zeros((space.nvec.size + 1,), dtype=space.dtype)
85
+ offsets[1:] = np.cumsum(space.nvec.flatten())
86
+
87
+ onehot = np.zeros((offsets[-1],), dtype=space.dtype)
88
+ onehot[offsets[:-1] + x.flatten()] = 1
89
+ return onehot
90
+
91
+
92
+ @flatten.register(Tuple)
93
+ def flatten_tuple(space, x):
94
+ return np.concatenate([flatten(s, x_part) for x_part, s in zip(x, space.spaces)])
95
+
96
+
97
+ @flatten.register(Dict)
98
+ def flatten_dict(space, x):
99
+ return np.concatenate([flatten(s, x[key]) for key, s in space.spaces.items()])
100
+
101
+
102
+ @singledispatch
103
+ def unflatten(space, x):
104
+ """Unflatten a data point from a space.
105
+
106
+ This reverses the transformation applied by ``flatten()``. You must ensure
107
+ that the ``space`` argument is the same as for the ``flatten()`` call.
108
+
109
+ Accepts a space and a flattened point. Returns a point with a structure
110
+ that matches the space. Raises ``NotImplementedError`` if the space is not
111
+ defined in ``gym.spaces``.
112
+ """
113
+ raise NotImplementedError(f"Unknown space: `{space}`")
114
+
115
+
116
+ @unflatten.register(Box)
117
+ @unflatten.register(MultiBinary)
118
+ def unflatten_box_multibinary(space, x):
119
+ return np.asarray(x, dtype=space.dtype).reshape(space.shape)
120
+
121
+
122
+ @unflatten.register(Discrete)
123
+ def unflatten_discrete(space, x):
124
+ return int(np.nonzero(x)[0][0])
125
+
126
+
127
+ @unflatten.register(MultiDiscrete)
128
+ def unflatten_multidiscrete(space, x):
129
+ offsets = np.zeros((space.nvec.size + 1,), dtype=space.dtype)
130
+ offsets[1:] = np.cumsum(space.nvec.flatten())
131
+
132
+ (indices,) = np.nonzero(x)
133
+ return np.asarray(indices - offsets[:-1], dtype=space.dtype).reshape(space.shape)
134
+
135
+
136
+ @unflatten.register(Tuple)
137
+ def unflatten_tuple(space, x):
138
+ dims = np.asarray([flatdim(s) for s in space.spaces], dtype=np.int_)
139
+ list_flattened = np.split(x, np.cumsum(dims[:-1]))
140
+ return tuple(
141
+ unflatten(s, flattened) for flattened, s in zip(list_flattened, space.spaces)
142
+ )
143
+
144
+
145
+ @unflatten.register(Dict)
146
+ def unflatten_dict(space, x):
147
+ dims = np.asarray([flatdim(s) for s in space.spaces.values()], dtype=np.int_)
148
+ list_flattened = np.split(x, np.cumsum(dims[:-1]))
149
+ return OrderedDict(
150
+ [
151
+ (key, unflatten(s, flattened))
152
+ for flattened, (key, s) in zip(list_flattened, space.spaces.items())
153
+ ]
154
+ )
155
+
156
+
157
+ @singledispatch
158
+ def flatten_space(space):
159
+ """Flatten a space into a single ``Box``.
160
+
161
+ This is equivalent to ``flatten()``, but operates on the space itself. The
162
+ result always is a `Box` with flat boundaries. The box has exactly
163
+ ``flatdim(space)`` dimensions. Flattening a sample of the original space
164
+ has the same effect as taking a sample of the flattenend space.
165
+
166
+ Raises ``NotImplementedError`` if the space is not defined in
167
+ ``gym.spaces``.
168
+
169
+ Example::
170
+
171
+ >>> box = Box(0.0, 1.0, shape=(3, 4, 5))
172
+ >>> box
173
+ Box(3, 4, 5)
174
+ >>> flatten_space(box)
175
+ Box(60,)
176
+ >>> flatten(box, box.sample()) in flatten_space(box)
177
+ True
178
+
179
+ Example that flattens a discrete space::
180
+
181
+ >>> discrete = Discrete(5)
182
+ >>> flatten_space(discrete)
183
+ Box(5,)
184
+ >>> flatten(box, box.sample()) in flatten_space(box)
185
+ True
186
+
187
+ Example that recursively flattens a dict::
188
+
189
+ >>> space = Dict({"position": Discrete(2),
190
+ ... "velocity": Box(0, 1, shape=(2, 2))})
191
+ >>> flatten_space(space)
192
+ Box(6,)
193
+ >>> flatten(space, space.sample()) in flatten_space(space)
194
+ True
195
+ """
196
+ raise NotImplementedError(f"Unknown space: `{space}`")
197
+
198
+
199
+ @flatten_space.register(Box)
200
+ def flatten_space_box(space):
201
+ return Box(space.low.flatten(), space.high.flatten(), dtype=space.dtype)
202
+
203
+
204
+ @flatten_space.register(Discrete)
205
+ @flatten_space.register(MultiBinary)
206
+ @flatten_space.register(MultiDiscrete)
207
+ def flatten_space_binary(space):
208
+ return Box(low=0, high=1, shape=(flatdim(space),), dtype=space.dtype)
209
+
210
+
211
+ @flatten_space.register(Tuple)
212
+ def flatten_space_tuple(space):
213
+ space = [flatten_space(s) for s in space.spaces]
214
+ return Box(
215
+ low=np.concatenate([s.low for s in space]),
216
+ high=np.concatenate([s.high for s in space]),
217
+ dtype=np.result_type(*[s.dtype for s in space]),
218
+ )
219
+
220
+
221
+ @flatten_space.register(Dict)
222
+ def flatten_space_dict(space):
223
+ space = [flatten_space(s) for s in space.spaces.values()]
224
+ return Box(
225
+ low=np.concatenate([s.low for s in space]),
226
+ high=np.concatenate([s.high for s in space]),
227
+ dtype=np.result_type(*[s.dtype for s in space]),
228
+ )
@@ -0,0 +1,13 @@
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
+ """A set of common utilities used within the environments. These are
6
+ not intended as API functions, and will not remain stable over time.
7
+ """
8
+
9
+ # These submodules should not have any import-time dependencies.
10
+ # We want this since we use `utils` during our import-time sanity checks
11
+ # that verify that our dependencies are actually present.
12
+ from .colorize import colorize
13
+ from .ezpickle import EzPickle
@@ -0,0 +1,72 @@
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 atexit
6
+ import threading
7
+ import weakref
8
+
9
+
10
+ class Closer(object):
11
+ """A registry that ensures your objects get closed, whether manually,
12
+ upon garbage collection, or upon exit. To work properly, your
13
+ objects need to cooperate and do something like the following:
14
+
15
+ ```
16
+ closer = Closer()
17
+ class Example(object):
18
+ def __init__(self):
19
+ self._id = closer.register(self)
20
+
21
+ def close(self):
22
+ # Probably worth making idempotent too!
23
+ ...
24
+ closer.unregister(self._id)
25
+
26
+ def __del__(self):
27
+ self.close()
28
+ ```
29
+
30
+ That is, your objects should:
31
+
32
+ - register() themselves and save the returned ID
33
+ - unregister() themselves upon close()
34
+ - include a __del__ method which close()'s the object
35
+ """
36
+
37
+ def __init__(self, atexit_register=True):
38
+ self.lock = threading.Lock()
39
+ self.next_id = -1
40
+ self.closeables = weakref.WeakValueDictionary()
41
+
42
+ if atexit_register:
43
+ atexit.register(self.close)
44
+
45
+ def generate_next_id(self):
46
+ with self.lock:
47
+ self.next_id += 1
48
+ return self.next_id
49
+
50
+ def register(self, closeable):
51
+ """Registers an object with a 'close' method.
52
+
53
+ Returns:
54
+ int: The registration ID of this object. It is the caller's responsibility to save this ID if early closing is desired.
55
+ """
56
+ assert hasattr(closeable, "close"), "No close method for {}".format(closeable)
57
+
58
+ next_id = self.generate_next_id()
59
+ self.closeables[next_id] = closeable
60
+ return next_id
61
+
62
+ def unregister(self, id):
63
+ assert id is not None
64
+ if id in self.closeables:
65
+ del self.closeables[id]
66
+
67
+ def close(self):
68
+ # Explicitly fetch all monitors first so that they can't disappear while
69
+ # we iterate. cf. http://stackoverflow.com/a/12429620
70
+ closeables = list(self.closeables.values())
71
+ for closeable in closeables:
72
+ closeable.close()
@@ -0,0 +1,36 @@
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
+ """A set of common utilities used within the environments. These are
6
+ not intended as API functions, and will not remain stable over time.
7
+ """
8
+
9
+ color2num = dict(
10
+ gray=30,
11
+ red=31,
12
+ green=32,
13
+ yellow=33,
14
+ blue=34,
15
+ magenta=35,
16
+ cyan=36,
17
+ white=37,
18
+ crimson=38,
19
+ )
20
+
21
+
22
+ def colorize(string, color, bold=False, highlight=False):
23
+ """Return string surrounded by appropriate terminal color codes to
24
+ print colorized text. Valid colors: gray, red, green, yellow,
25
+ blue, magenta, cyan, white, crimson
26
+ """
27
+
28
+ attr = []
29
+ num = color2num[color]
30
+ if highlight:
31
+ num += 10
32
+ attr.append(str(num))
33
+ if bold:
34
+ attr.append("1")
35
+ attrs = ";".join(attr)
36
+ return "\x1b[%sm%s\x1b[0m" % (attrs, string)