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,163 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+
18
+ """Config loader."""
19
+
20
+ from __future__ import print_function
21
+
22
+ import copy
23
+ import tempfile
24
+ import os
25
+ import platform
26
+
27
+ from absl import flags
28
+
29
+ from cuju import gfootball_engine as libgame
30
+
31
+ FLAGS = flags.FLAGS
32
+
33
+ def parse_player_definition(definition):
34
+ """Parses player definition.
35
+
36
+ An example of player definition is: "agent:players=4" or "replay:path=...".
37
+
38
+ Args:
39
+ definition: a string defining a player
40
+
41
+ Returns:
42
+ A tuple (name, dict).
43
+ """
44
+ name = definition
45
+ d = {'left_players': 0,
46
+ 'right_players': 0}
47
+ if ':' in definition:
48
+ # Windows requires special handling of replays, because path may contain ':'
49
+ if platform.system() == 'Windows' and definition.startswith('replay:') \
50
+ and len(definition.split(':')) > 2:
51
+ (name, params) = 'replay', definition.split('replay:')[-1]
52
+ else:
53
+ (name, params) = definition.split(':')
54
+ for param in params.split(','):
55
+ (key, value) = param.split('=')
56
+ d[key] = value
57
+ if d['left_players'] == 0 and d['right_players'] == 0:
58
+ d['left_players'] = 1
59
+ return name, d
60
+
61
+
62
+ def count_players(definition):
63
+ """Returns a number of players given a definition."""
64
+ _, player_definition = parse_player_definition(definition)
65
+ return (int(player_definition['left_players']) +
66
+ int(player_definition['right_players']))
67
+
68
+
69
+ def count_left_players(definition):
70
+ """Returns a number of left players given a definition."""
71
+ return int(parse_player_definition(definition)[1]['left_players'])
72
+
73
+
74
+ def count_right_players(definition):
75
+ """Returns a number of players given a definition."""
76
+ return int(parse_player_definition(definition)[1]['right_players'])
77
+
78
+
79
+ def get_agent_number_of_players(players):
80
+ """Returns a total number of players controlled by an agent."""
81
+ return sum([count_players(player) for player in players
82
+ if player.startswith('agent')])
83
+
84
+
85
+ class Config(object):
86
+
87
+ def __init__(self, values=None):
88
+ self._values = {
89
+ 'action_set': 'default',
90
+ 'custom_display_stats': None,
91
+ 'display_game_stats': True,
92
+ 'dump_full_episodes': False,
93
+ 'dump_scores': False,
94
+ 'players': ['agent:left_players=1'],
95
+ 'level': '11_vs_11_stochastic',
96
+ 'physics_steps_per_frame': 10,
97
+ 'render_resolution_x': 1280,
98
+ 'real_time': False,
99
+ 'tracesdir': os.path.join(tempfile.gettempdir(), 'dumps'),
100
+ 'video_format': 'avi',
101
+ 'video_quality_level': 0, # 0 - low, 1 - medium, 2 - high
102
+ 'write_video': False
103
+ }
104
+ self._values['render_resolution_y'] = int(
105
+ 0.5625 * self._values['render_resolution_x'])
106
+ if values:
107
+ self._values.update(values)
108
+ self.NewScenario()
109
+
110
+ def number_of_left_players(self):
111
+ return sum([count_left_players(player)
112
+ for player in self._values['players']])
113
+
114
+ def number_of_right_players(self):
115
+ return sum([count_right_players(player)
116
+ for player in self._values['players']])
117
+
118
+ def number_of_players_agent_controls(self):
119
+ return get_agent_number_of_players(self._values['players'])
120
+
121
+ def __eq__(self, other):
122
+ assert isinstance(other, self.__class__)
123
+ return self._values == other._values and self._scenario_values == other._scenario_values
124
+
125
+ def __ne__(self, other):
126
+ return not self.__eq__(other)
127
+
128
+ def __getitem__(self, key):
129
+ if key in self._scenario_values:
130
+ return self._scenario_values[key]
131
+ return self._values[key]
132
+
133
+ def __setitem__(self, key, value):
134
+ self._values[key] = value
135
+
136
+ def __contains__(self, key):
137
+ return key in self._scenario_values or key in self._values
138
+
139
+ def get_dictionary(self):
140
+ cfg = copy.deepcopy(self._values)
141
+ cfg.update(self._scenario_values)
142
+ return cfg
143
+
144
+ def set_scenario_value(self, key, value):
145
+ """Override value of specific config key for a single episode."""
146
+ self._scenario_values[key] = value
147
+
148
+ def serialize(self):
149
+ return self._values
150
+
151
+ def update(self, config):
152
+ self._values.update(config)
153
+
154
+ def ScenarioConfig(self):
155
+ return self._scenario_cfg
156
+
157
+ def NewScenario(self, inc = 1):
158
+ if 'episode_number' not in self._values:
159
+ self._values['episode_number'] = 0
160
+ self._values['episode_number'] += inc
161
+ self._scenario_values = {}
162
+ from cuju.gfootball.env import scenario_builder
163
+ self._scenario_cfg = scenario_builder.Scenario(self).ScenarioConfig()
@@ -0,0 +1,33 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+
18
+ """Important environment constants."""
19
+
20
+ from __future__ import print_function
21
+
22
+ # How many physics steps game engine does per second.
23
+ PHYSICS_STEPS_PER_SECOND = 100
24
+
25
+ # List of observations exposed by the environment.
26
+ EXPOSED_OBSERVATIONS = frozenset({
27
+ 'ball', 'ball_direction', 'ball_rotation', 'ball_owned_team',
28
+ 'ball_owned_player', 'left_team', 'left_team_direction',
29
+ 'left_team_tired_factor', 'left_team_yellow_card', 'left_team_active',
30
+ 'left_team_roles', 'right_team', 'right_team_direction',
31
+ 'right_team_tired_factor', 'right_team_yellow_card', 'right_team_active',
32
+ 'right_team_roles', 'score', 'steps_left', 'game_mode'
33
+ })
@@ -0,0 +1,114 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+
18
+ """Base controller class."""
19
+
20
+ from cuju.gfootball.env import football_action_set
21
+ from cuju.gfootball.env import player_base
22
+
23
+
24
+ class Controller(player_base.PlayerBase):
25
+ """Base controller class."""
26
+
27
+ def __init__(self, player_config, env_config):
28
+ player_base.PlayerBase.__init__(self, player_config)
29
+ self._active_actions = {}
30
+ self._env_config = env_config
31
+ self._last_action = football_action_set.action_idle
32
+ self._last_direction = football_action_set.action_idle
33
+ self._current_direction = football_action_set.action_idle
34
+
35
+ def _check_action(self, action, active_actions):
36
+ """Compare (and update) controller's state with the set of active actions.
37
+
38
+ Args:
39
+ action: Action to check
40
+ active_actions: Set of all active actions
41
+ """
42
+ assert isinstance(action, football_action_set.CoreAction)
43
+ if not action.is_in_actionset(self._env_config):
44
+ return
45
+ state = active_actions.get(action, 0)
46
+ if (self._last_action == football_action_set.action_idle and
47
+ self._active_actions.get(action, 0) != state):
48
+ self._active_actions[action] = state
49
+ if state:
50
+ self._last_action = action
51
+ else:
52
+ self._last_action = football_action_set.disable_action(action)
53
+ assert self._last_action
54
+
55
+ def _check_direction(self, action, state):
56
+ """Compare (and update) controller's direction with the current direction.
57
+
58
+ Args:
59
+ action: Action to check
60
+ state: Current state of the action being checked
61
+ """
62
+ assert isinstance(action, football_action_set.CoreAction)
63
+ if not action.is_in_actionset(self._env_config):
64
+ return
65
+ if self._current_direction != football_action_set.action_idle:
66
+ return
67
+ if state:
68
+ self._current_direction = action
69
+
70
+ def get_env_action(self, left, right, top, bottom, active_actions):
71
+ """For a given controller's state generate next environment action.
72
+
73
+ Args:
74
+ action: Action to check
75
+ state: Current state of the action being checked
76
+ """
77
+ self._current_direction = football_action_set.action_idle
78
+ self._check_direction(football_action_set.action_top_left, top and
79
+ left)
80
+ self._check_direction(football_action_set.action_top_right, top and
81
+ right)
82
+ self._check_direction(football_action_set.action_bottom_left,
83
+ bottom and left)
84
+ self._check_direction(football_action_set.action_bottom_right,
85
+ bottom and right)
86
+ if self._current_direction == football_action_set.action_idle:
87
+ self._check_direction(football_action_set.action_right, right)
88
+ self._check_direction(football_action_set.action_left, left)
89
+ self._check_direction(football_action_set.action_top, top)
90
+ self._check_direction(football_action_set.action_bottom, bottom)
91
+ if self._current_direction != self._last_direction:
92
+ self._last_direction = self._current_direction
93
+ if self._current_direction == football_action_set.action_idle:
94
+ return football_action_set.action_release_direction
95
+ else:
96
+ return self._current_direction
97
+ self._last_action = football_action_set.action_idle
98
+ self._check_action(football_action_set.action_long_pass,
99
+ active_actions)
100
+ self._check_action(football_action_set.action_high_pass,
101
+ active_actions)
102
+ self._check_action(football_action_set.action_short_pass,
103
+ active_actions)
104
+ self._check_action(football_action_set.action_shot, active_actions)
105
+ self._check_action(football_action_set.action_keeper_rush,
106
+ active_actions)
107
+ self._check_action(football_action_set.action_sliding, active_actions)
108
+ self._check_action(football_action_set.action_pressure,
109
+ active_actions)
110
+ self._check_action(football_action_set.action_team_pressure,
111
+ active_actions)
112
+ self._check_action(football_action_set.action_sprint, active_actions)
113
+ self._check_action(football_action_set.action_dribble, active_actions)
114
+ return self._last_action
@@ -0,0 +1,54 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+ import pygame
18
+
19
+ KEYBOARD_EVENTS = [pygame.KEYDOWN]
20
+ GAMEPAD_EVENTS = [pygame.JOYBUTTONDOWN, pygame.JOYAXISMOTION]
21
+
22
+ _queue = []
23
+ _controllers = []
24
+
25
+
26
+ def add_controller(controller_kind, controller_index=None):
27
+ global _controllers
28
+ _controllers.append((controller_kind, controller_index))
29
+
30
+
31
+ def fits(event, controller_kind, controller_index):
32
+ if controller_kind == 'keyboard':
33
+ return event.type in KEYBOARD_EVENTS
34
+ if controller_kind == 'gamepad':
35
+ return event.type in GAMEPAD_EVENTS and event.joy == controller_index
36
+ assert False, 'Unknown controller kind!'
37
+
38
+
39
+ def get(controller_kind, controller_index=None):
40
+ global _queue
41
+ global _controllers
42
+ _queue.extend(pygame.event.get())
43
+ result = []
44
+ new_state = []
45
+ for event in _queue:
46
+ if fits(event, controller_kind, controller_index):
47
+ result.append(event)
48
+ else:
49
+ for controller in _controllers:
50
+ if fits(event, *controller):
51
+ new_state.append(event)
52
+ break
53
+ _queue = new_state
54
+ return result
@@ -0,0 +1,220 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+
18
+ """List of core actions / action sets supported by the gfootball environment."""
19
+
20
+ # ***** List of core actions *****
21
+ # Only add new ones, do not reorder so the numbering do not change.
22
+
23
+ from __future__ import absolute_import
24
+ from __future__ import division
25
+ from __future__ import print_function
26
+
27
+ from cuju.gfootball_engine import e_BackendAction
28
+ import numpy
29
+ from six.moves import range
30
+
31
+
32
+ class CoreAction(object):
33
+
34
+ def __init__(self, backend_action, name, sticky=False, directional=False):
35
+ self._backend_action = backend_action
36
+ self._name = name
37
+ self._sticky = sticky
38
+ self._directional = directional
39
+
40
+ def is_in_actionset(self, config):
41
+ return self in get_action_set(config)
42
+
43
+ def __eq__(self, other):
44
+ assert set(other.__dict__) == set(self.__dict__)
45
+ return self._name == other._name
46
+
47
+ def __ne__(self, other):
48
+ return not self.__eq__(other)
49
+
50
+ def __lt__(self, other):
51
+ assert set(other.__dict__) == set(self.__dict__)
52
+ return self._backend_action < other._backend_action
53
+
54
+ def __le__(self, other):
55
+ assert set(other.__dict__) == set(self.__dict__)
56
+ return self._backend_action <= other._backend_action
57
+
58
+ def __gt__(self, other):
59
+ assert set(other.__dict__) == set(self.__dict__)
60
+ return self._backend_action > other._backend_action
61
+
62
+ def __ge__(self, other):
63
+ assert set(other.__dict__) == set(self.__dict__)
64
+ return self._backend_action >= other._backend_action
65
+
66
+ def __hash__(self):
67
+ return self._backend_action
68
+
69
+ def __repr__(self):
70
+ return self._name
71
+
72
+
73
+ action_idle = CoreAction(e_BackendAction.idle, "idle")
74
+ action_builtin_ai = CoreAction(e_BackendAction.builtin_ai, "builtin_ai")
75
+ action_left = CoreAction(
76
+ e_BackendAction.left, "left", sticky=True, directional=True)
77
+ action_top_left = CoreAction(
78
+ e_BackendAction.top_left, "top_left", sticky=True, directional=True)
79
+ action_top = CoreAction(
80
+ e_BackendAction.top, "top", sticky=True, directional=True)
81
+ action_top_right = CoreAction(
82
+ e_BackendAction.top_right, "top_right", sticky=True, directional=True)
83
+ action_right = CoreAction(
84
+ e_BackendAction.right, "right", sticky=True, directional=True)
85
+ action_bottom_right = CoreAction(
86
+ e_BackendAction.bottom_right, "bottom_right", sticky=True, directional=True)
87
+ action_bottom = CoreAction(
88
+ e_BackendAction.bottom, "bottom", sticky=True, directional=True)
89
+ action_bottom_left = CoreAction(
90
+ e_BackendAction.bottom_left, "bottom_left", sticky=True, directional=True)
91
+ action_long_pass = CoreAction(e_BackendAction.long_pass, "long_pass")
92
+ action_high_pass = CoreAction(e_BackendAction.high_pass, "high_pass")
93
+ action_short_pass = CoreAction(e_BackendAction.short_pass, "short_pass")
94
+ action_shot = CoreAction(e_BackendAction.shot, "shot")
95
+ action_keeper_rush = CoreAction(
96
+ e_BackendAction.keeper_rush, "keeper_rush", sticky=True)
97
+ action_sliding = CoreAction(e_BackendAction.sliding, "sliding")
98
+ action_pressure = CoreAction(
99
+ e_BackendAction.pressure, "pressure", sticky=True)
100
+ action_team_pressure = CoreAction(
101
+ e_BackendAction.team_pressure, "team_pressure", sticky=True)
102
+ action_switch = CoreAction(e_BackendAction.switch, "switch")
103
+ action_sprint = CoreAction(e_BackendAction.sprint, "sprint", sticky=True)
104
+ action_dribble = CoreAction(
105
+ e_BackendAction.dribble, "dribble", sticky=True)
106
+ action_release_direction = CoreAction(
107
+ e_BackendAction.release_direction, "release_direction", directional=True)
108
+ action_release_long_pass = CoreAction(e_BackendAction.release_long_pass,
109
+ "release_long_pass")
110
+ action_release_high_pass = CoreAction(e_BackendAction.release_high_pass,
111
+ "release_high_pass")
112
+ action_release_short_pass = CoreAction(e_BackendAction.release_short_pass,
113
+ "release_short_pass")
114
+ action_release_shot = CoreAction(e_BackendAction.release_shot, "release_shot")
115
+ action_release_keeper_rush = CoreAction(e_BackendAction.release_keeper_rush,
116
+ "release_keeper_rush")
117
+ action_release_sliding = CoreAction(e_BackendAction.release_sliding,
118
+ "release_sliding")
119
+ action_release_pressure = CoreAction(e_BackendAction.release_pressure,
120
+ "release_pressure")
121
+ action_release_team_pressure = CoreAction(e_BackendAction.release_team_pressure,
122
+ "release_team_pressure")
123
+ action_release_switch = CoreAction(e_BackendAction.release_switch,
124
+ "release_switch")
125
+ action_release_sprint = CoreAction(e_BackendAction.release_sprint,
126
+ "release_sprint")
127
+ action_release_dribble = CoreAction(e_BackendAction.release_dribble,
128
+ "release_dribble")
129
+
130
+ # ***** Define some action sets *****
131
+ action_set_v1 = [
132
+ action_idle, action_left, action_top_left, action_top,
133
+ action_top_right, action_right, action_bottom_right,
134
+ action_bottom, action_bottom_left, action_long_pass,
135
+ action_high_pass, action_short_pass, action_shot,
136
+ action_sprint, action_release_direction, action_release_sprint,
137
+ action_sliding, action_dribble, action_release_dribble]
138
+
139
+ action_set_v2 = action_set_v1 + [action_builtin_ai]
140
+
141
+ # Special action set that includes all the core actions in the same order.
142
+ full_action_set = action_set_v2 + [
143
+ action_keeper_rush, action_pressure,
144
+ action_team_pressure, action_switch,
145
+ action_release_long_pass, action_release_high_pass,
146
+ action_release_short_pass, action_release_shot,
147
+ action_release_keeper_rush, action_release_sliding,
148
+ action_release_pressure, action_release_team_pressure,
149
+ action_release_switch,
150
+ ]
151
+
152
+ action_set_dict = {
153
+ "default": action_set_v1,
154
+ "v2": action_set_v2,
155
+ # "full" action set is needed by the play_game script.
156
+ # Don't use it for training models.
157
+ "full": full_action_set,
158
+ }
159
+
160
+ reverse_action_mapping = {
161
+ action_long_pass: action_release_long_pass,
162
+ action_high_pass: action_release_high_pass,
163
+ action_short_pass: action_release_short_pass,
164
+ action_shot: action_release_shot,
165
+ action_keeper_rush: action_release_keeper_rush,
166
+ action_sliding: action_release_sliding,
167
+ action_pressure: action_release_pressure,
168
+ action_team_pressure: action_release_team_pressure,
169
+ action_switch: action_release_switch,
170
+ action_sprint: action_release_sprint,
171
+ action_dribble: action_release_dribble,
172
+ action_release_long_pass: action_long_pass,
173
+ action_release_high_pass: action_high_pass,
174
+ action_release_short_pass: action_short_pass,
175
+ action_release_shot: action_shot,
176
+ action_release_keeper_rush: action_keeper_rush,
177
+ action_release_sliding: action_sliding,
178
+ action_release_pressure: action_pressure,
179
+ action_release_team_pressure: action_team_pressure,
180
+ action_release_switch: action_switch,
181
+ action_release_sprint: action_sprint,
182
+ action_release_dribble: action_dribble
183
+ }
184
+
185
+ # Returns action set specified by the config.
186
+ def get_action_set(config):
187
+ action_set_name = config["action_set"]
188
+ return action_set_dict[action_set_name]
189
+
190
+ def get_sticky_actions(config):
191
+ """Returns list of sticky actions for the currently used action set."""
192
+ sticky_actions = []
193
+ for a in get_action_set(config):
194
+ if a._sticky:
195
+ sticky_actions.append(a)
196
+ return sticky_actions
197
+
198
+
199
+ # Converts different action representation to an action from a given action set.
200
+ def named_action_from_action_set(action_set, action):
201
+ if (hasattr(action, "__dict__") and action_set and
202
+ set(action.__dict__) == set(action_set[0].__dict__)):
203
+ return action
204
+
205
+ if (isinstance(action, numpy.int32) or isinstance(action, numpy.int64) or
206
+ isinstance(action, int)):
207
+ # The action can be given as a numpy.int32 which cannot be
208
+ # serialized. First convert it to a proper python integer.
209
+ action = int(action)
210
+ assert action < len(action_set), "Action outside of action set"
211
+ return action_set[action]
212
+
213
+ assert False, "Action {} not found in action set".format(action)
214
+
215
+
216
+ def disable_action(action):
217
+ assert set(action.__dict__) == set(action_left.__dict__)
218
+ if action._directional:
219
+ return action_release_direction
220
+ return reverse_action_mapping[action]
@@ -0,0 +1,76 @@
1
+ # coding=utf-8
2
+ # Copyright 2019 Google LLC
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+
18
+ """Football action set tests."""
19
+
20
+ from absl.testing import absltest
21
+ from cuju.gfootball.env import football_action_set
22
+ import numpy as np
23
+
24
+ named_action_from_action_set = football_action_set.named_action_from_action_set
25
+
26
+
27
+ class FootballActionSetTest(absltest.TestCase):
28
+
29
+ def test_action_from_basic_action_set(self):
30
+ action_set = football_action_set.get_action_set({'action_set': 'default'})
31
+ self.assertEqual(
32
+ named_action_from_action_set(action_set, 1),
33
+ football_action_set.action_left)
34
+ self.assertEqual(
35
+ named_action_from_action_set(action_set, 12),
36
+ football_action_set.action_shot)
37
+
38
+ self.assertEqual(named_action_from_action_set(action_set, np.int32(1)),
39
+ football_action_set.action_left)
40
+ self.assertRaises(Exception, named_action_from_action_set, action_set,
41
+ np.int32(100))
42
+
43
+ self.assertEqual(
44
+ named_action_from_action_set(action_set,
45
+ football_action_set.action_left),
46
+ football_action_set.action_left)
47
+ self.assertRaises(Exception, named_action_from_action_set, action_set, 100)
48
+
49
+ def test_action_set_full(self):
50
+ self.assertEqual(football_action_set.full_action_set[0],
51
+ football_action_set.action_idle)
52
+
53
+ def test_disable_action(self):
54
+ self.assertEqual(
55
+ football_action_set.disable_action(
56
+ football_action_set.action_left),
57
+ football_action_set.action_release_direction)
58
+ self.assertEqual(
59
+ football_action_set.disable_action(
60
+ football_action_set.action_release_direction),
61
+ football_action_set.action_release_direction)
62
+
63
+ def test_sticky_actions_have_release(self):
64
+ for i in football_action_set.action_set_dict:
65
+ action_set = football_action_set.action_set_dict[i]
66
+ for action in action_set:
67
+ if action._sticky:
68
+ reverse = football_action_set.disable_action(action)
69
+ self.assertTrue(
70
+ reverse in action_set,
71
+ 'Action {} has no release action in action set {}'.format(
72
+ action._name, i))
73
+
74
+
75
+ if __name__ == '__main__':
76
+ absltest.main()