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.
- cuju/__init__.py +217 -0
- cuju/__main__.py +262 -0
- cuju/_batch/__init__.py +4 -0
- cuju/_batch/allocator.py +52 -0
- cuju/_batch/assets.py +68 -0
- cuju/_batch/environment.py +1890 -0
- cuju/_batch/frame_stack.py +114 -0
- cuju/_batch/library.py +190 -0
- cuju/_batch/log.py +103 -0
- cuju/_batch/memory.py +70 -0
- cuju/_batch/operators.py +55 -0
- cuju/_batch/pinned.py +39 -0
- cuju/_batch/pixels.py +207 -0
- cuju/_batch/state.py +77 -0
- cuju/_checksums.py +60 -0
- cuju/_cli_contract.py +244 -0
- cuju/_cli_parsers.py +191 -0
- cuju/_completion.py +277 -0
- cuju/_dump_to_txt.py +66 -0
- cuju/_grf_config.py +331 -0
- cuju/_library_path.py +141 -0
- cuju/_media.py +113 -0
- cuju/_pixels.py +276 -0
- cuju/_plugins.py +106 -0
- cuju/_python_players.py +224 -0
- cuju/_replay_command.py +109 -0
- cuju/_replay_player.py +42 -0
- cuju/_replays.py +414 -0
- cuju/_script_helpers.py +109 -0
- cuju/_version.py +6 -0
- cuju/action_log.py +371 -0
- cuju/check.py +596 -0
- cuju/cuju_cpu.dll +0 -0
- cuju/cuju_cuda.dll +0 -0
- cuju/cuju_render.dll +0 -0
- cuju/data/SHA256SUMS +20 -0
- cuju/data/animations.bin +0 -0
- cuju/data/assets/11_vs_11_competition_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_easy_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_hard_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_kaggle_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/1_vs_1_easy_l0_r0.cjb +0 -0
- cuju/data/assets/5_vs_5_l0_r0.cjb +0 -0
- cuju/data/assets/academy_3_vs_1_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_corner_l0_r0.cjb +0 -0
- cuju/data/assets/academy_counterattack_easy_l0_r0.cjb +0 -0
- cuju/data/assets/academy_counterattack_hard_l0_r0.cjb +0 -0
- cuju/data/assets/academy_empty_goal_close_l0_r0.cjb +0 -0
- cuju/data/assets/academy_empty_goal_l0_r0.cjb +0 -0
- cuju/data/assets/academy_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_to_score_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_to_score_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_single_goal_versus_lazy_l0_r0.cjb +0 -0
- cuju/data/assets/test_example_multiagent_l0_r0.cjb +0 -0
- cuju/data/digests.json +186 -0
- cuju/data/render_digests.json.z +0 -0
- cuju/data/scenarios/11_vs_11_competition.py +45 -0
- cuju/data/scenarios/11_vs_11_easy_stochastic.py +44 -0
- cuju/data/scenarios/11_vs_11_hard_stochastic.py +44 -0
- cuju/data/scenarios/11_vs_11_kaggle.py +46 -0
- cuju/data/scenarios/11_vs_11_stochastic.py +44 -0
- cuju/data/scenarios/1_vs_1_easy.py +25 -0
- cuju/data/scenarios/5_vs_5.py +33 -0
- cuju/data/scenarios/academy_3_vs_1_with_keeper.py +28 -0
- cuju/data/scenarios/academy_corner.py +45 -0
- cuju/data/scenarios/academy_counterattack_easy.py +45 -0
- cuju/data/scenarios/academy_counterattack_hard.py +45 -0
- cuju/data/scenarios/academy_empty_goal.py +25 -0
- cuju/data/scenarios/academy_empty_goal_close.py +25 -0
- cuju/data/scenarios/academy_pass_and_shoot_with_keeper.py +27 -0
- cuju/data/scenarios/academy_run_pass_and_shoot_with_keeper.py +27 -0
- cuju/data/scenarios/academy_run_to_score.py +30 -0
- cuju/data/scenarios/academy_run_to_score_with_keeper.py +30 -0
- cuju/data/scenarios/academy_single_goal_versus_lazy.py +49 -0
- cuju/data/scenarios/test_example_multiagent.py +28 -0
- cuju/dumps.py +942 -0
- cuju/engine_status.py +106 -0
- cuju/env.py +1168 -0
- cuju/errors.py +108 -0
- cuju/gfootball/GRF_SOURCES +86 -0
- cuju/gfootball/__init__.py +60 -0
- cuju/gfootball/_cv2.py +43 -0
- cuju/gfootball/_gym/__init__.py +88 -0
- cuju/gfootball/_gym/_vendored/GYM_SOURCES +22 -0
- cuju/gfootball/_gym/_vendored/__init__.py +43 -0
- cuju/gfootball/_gym/_vendored/core.py +361 -0
- cuju/gfootball/_gym/_vendored/envs/__init__.py +19 -0
- cuju/gfootball/_gym/_vendored/envs/registration.py +284 -0
- cuju/gfootball/_gym/_vendored/error.py +230 -0
- cuju/gfootball/_gym/_vendored/logger.py +56 -0
- cuju/gfootball/_gym/_vendored/spaces/__init__.py +30 -0
- cuju/gfootball/_gym/_vendored/spaces/box.py +171 -0
- cuju/gfootball/_gym/_vendored/spaces/dict.py +162 -0
- cuju/gfootball/_gym/_vendored/spaces/discrete.py +41 -0
- cuju/gfootball/_gym/_vendored/spaces/multi_binary.py +61 -0
- cuju/gfootball/_gym/_vendored/spaces/multi_discrete.py +77 -0
- cuju/gfootball/_gym/_vendored/spaces/space.py +94 -0
- cuju/gfootball/_gym/_vendored/spaces/tuple.py +96 -0
- cuju/gfootball/_gym/_vendored/spaces/utils.py +228 -0
- cuju/gfootball/_gym/_vendored/utils/__init__.py +13 -0
- cuju/gfootball/_gym/_vendored/utils/closer.py +72 -0
- cuju/gfootball/_gym/_vendored/utils/colorize.py +36 -0
- cuju/gfootball/_gym/_vendored/utils/ezpickle.py +37 -0
- cuju/gfootball/_gym/_vendored/utils/json_utils.py +27 -0
- cuju/gfootball/_gym/_vendored/utils/seeding.py +101 -0
- cuju/gfootball/_gym/_vendored/version.py +5 -0
- cuju/gfootball/_gym/_vendored/wrappers/__init__.py +8 -0
- cuju/gfootball/_gym/_vendored/wrappers/order_enforcing.py +20 -0
- cuju/gfootball/_gym/_vendored/wrappers/time_limit.py +31 -0
- cuju/gfootball/dump_to_txt.py +49 -0
- cuju/gfootball/dump_to_video.py +33 -0
- cuju/gfootball/env/__init__.py +271 -0
- cuju/gfootball/env/config.py +163 -0
- cuju/gfootball/env/constants.py +33 -0
- cuju/gfootball/env/controller_base.py +114 -0
- cuju/gfootball/env/event_queue.py +54 -0
- cuju/gfootball/env/football_action_set.py +220 -0
- cuju/gfootball/env/football_action_set_test.py +76 -0
- cuju/gfootball/env/football_env.py +225 -0
- cuju/gfootball/env/football_env_core.py +447 -0
- cuju/gfootball/env/football_env_test.py +692 -0
- cuju/gfootball/env/gym_test.py +47 -0
- cuju/gfootball/env/observation_preprocessing.py +94 -0
- cuju/gfootball/env/observation_processor.py +526 -0
- cuju/gfootball/env/observation_rotation.py +163 -0
- cuju/gfootball/env/observation_rotation_test.py +84 -0
- cuju/gfootball/env/player_base.py +46 -0
- cuju/gfootball/env/players/__init__.py +16 -0
- cuju/gfootball/env/players/agent.py +39 -0
- cuju/gfootball/env/players/bot.py +217 -0
- cuju/gfootball/env/players/gamepad.py +81 -0
- cuju/gfootball/env/players/keyboard.py +72 -0
- cuju/gfootball/env/players/lazy.py +31 -0
- cuju/gfootball/env/players/ppo2_cnn.py +119 -0
- cuju/gfootball/env/players/replay.py +40 -0
- cuju/gfootball/env/remote_football_env.py +189 -0
- cuju/gfootball/env/scenario_builder.py +125 -0
- cuju/gfootball/env/script_helpers.py +130 -0
- cuju/gfootball/env/script_helpers_test.py +107 -0
- cuju/gfootball/env/wrappers.py +440 -0
- cuju/gfootball/env/wrappers_test.py +150 -0
- cuju/gfootball/eval_server/__init__.py +17 -0
- cuju/gfootball/eval_server/config.py +30 -0
- cuju/gfootball/eval_server/example_client.py +107 -0
- cuju/gfootball/eval_server/proto/game_server.proto +62 -0
- cuju/gfootball/eval_server/proto/game_server_pb2.py +501 -0
- cuju/gfootball/eval_server/proto/game_server_pb2_grpc.py +113 -0
- cuju/gfootball/eval_server/proto/master.proto +25 -0
- cuju/gfootball/eval_server/proto/master_pb2.py +184 -0
- cuju/gfootball/eval_server/proto/master_pb2_grpc.py +62 -0
- cuju/gfootball/eval_server/utils.py +52 -0
- cuju/gfootball/examples/__init__.py +16 -0
- cuju/gfootball/examples/models.py +66 -0
- cuju/gfootball/examples/run_multiagent_rllib.py +140 -0
- cuju/gfootball/examples/run_ppo2.py +123 -0
- cuju/gfootball/play_game.py +73 -0
- cuju/gfootball/replay.py +43 -0
- cuju/gfootball/scenarios/11_vs_11_competition.py +59 -0
- cuju/gfootball/scenarios/11_vs_11_easy_stochastic.py +57 -0
- cuju/gfootball/scenarios/11_vs_11_hard_stochastic.py +57 -0
- cuju/gfootball/scenarios/11_vs_11_kaggle.py +60 -0
- cuju/gfootball/scenarios/11_vs_11_stochastic.py +57 -0
- cuju/gfootball/scenarios/1_vs_1_easy.py +39 -0
- cuju/gfootball/scenarios/5_vs_5.py +46 -0
- cuju/gfootball/scenarios/__init__.py +31 -0
- cuju/gfootball/scenarios/academy_3_vs_1_with_keeper.py +42 -0
- cuju/gfootball/scenarios/academy_corner.py +59 -0
- cuju/gfootball/scenarios/academy_counterattack_easy.py +59 -0
- cuju/gfootball/scenarios/academy_counterattack_hard.py +59 -0
- cuju/gfootball/scenarios/academy_empty_goal.py +39 -0
- cuju/gfootball/scenarios/academy_empty_goal_close.py +39 -0
- cuju/gfootball/scenarios/academy_pass_and_shoot_with_keeper.py +41 -0
- cuju/gfootball/scenarios/academy_run_pass_and_shoot_with_keeper.py +41 -0
- cuju/gfootball/scenarios/academy_run_to_score.py +44 -0
- cuju/gfootball/scenarios/academy_run_to_score_with_keeper.py +44 -0
- cuju/gfootball/scenarios/academy_single_goal_versus_lazy.py +63 -0
- cuju/gfootball/scenarios/test_example_multiagent.py +42 -0
- cuju/gfootball/scenarios/tests/11_vs_11_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_easy_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_hard_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_single_goal_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_single_goal_stochastic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_4_offence_deterministic.py +47 -0
- cuju/gfootball/scenarios/tests/11_vs_4_offence_stochastic.py +47 -0
- cuju/gfootball/scenarios/tests/__init__.py +31 -0
- cuju/gfootball/scenarios/tests/corner_test.py +38 -0
- cuju/gfootball/scenarios/tests/goal_test.py +35 -0
- cuju/gfootball/scenarios/tests/keeper_test.py +38 -0
- cuju/gfootball/scenarios/tests/kickoff_for_goal_loosing_team_test.py +34 -0
- cuju/gfootball/scenarios/tests/multiagent_wrapper.py +60 -0
- cuju/gfootball/scenarios/tests/offside_test.py +39 -0
- cuju/gfootball/scenarios/tests/penalty.py +34 -0
- cuju/gfootball/scenarios/tests/second_half.py +33 -0
- cuju/gfootball/scenarios/tests/symmetric.py +53 -0
- cuju/gfootball_engine/__init__.py +31 -0
- cuju/gfootball_engine/_gameplayfootball.py +1624 -0
- cuju/gfootball_engine/_native.py +193 -0
- cuju/gfootball_engine/_pickle_names.py +114 -0
- cuju/gfootball_engine/_render_hooks.py +156 -0
- cuju/kaggle.py +425 -0
- cuju/multi_device.py +401 -0
- cuju/players.py +260 -0
- cuju/raw.py +93 -0
- cuju/scenarios.py +661 -0
- cuju/state.py +211 -0
- cuju/wrappers.py +325 -0
- cuju_engine-0.3.0.dist-info/METADATA +325 -0
- cuju_engine-0.3.0.dist-info/RECORD +222 -0
- cuju_engine-0.3.0.dist-info/WHEEL +5 -0
- cuju_engine-0.3.0.dist-info/entry_points.txt +4 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSE +202 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +31 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSL-1.0.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/LGPL-2.1-or-later.txt +502 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-Mesa.txt +26 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-gym.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/SunPro.txt +8 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/Zlib.txt +20 -0
- cuju_engine-0.3.0.dist-info/licenses/NOTICE +56 -0
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
class EzPickle(object):
|
|
6
|
+
"""Objects that are pickled and unpickled via their constructor
|
|
7
|
+
arguments.
|
|
8
|
+
|
|
9
|
+
Example usage:
|
|
10
|
+
|
|
11
|
+
class Dog(Animal, EzPickle):
|
|
12
|
+
def __init__(self, furcolor, tailkind="bushy"):
|
|
13
|
+
Animal.__init__()
|
|
14
|
+
EzPickle.__init__(furcolor, tailkind)
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
When this object is unpickled, a new Dog will be constructed by passing the provided
|
|
18
|
+
furcolor and tailkind into the constructor. However, philosophers are still not sure
|
|
19
|
+
whether it is still the same dog.
|
|
20
|
+
|
|
21
|
+
This is generally needed only for environments which wrap C/C++ code, such as MuJoCo
|
|
22
|
+
and Atari.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, *args, **kwargs):
|
|
26
|
+
self._ezpickle_args = args
|
|
27
|
+
self._ezpickle_kwargs = kwargs
|
|
28
|
+
|
|
29
|
+
def __getstate__(self):
|
|
30
|
+
return {
|
|
31
|
+
"_ezpickle_args": self._ezpickle_args,
|
|
32
|
+
"_ezpickle_kwargs": self._ezpickle_kwargs,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def __setstate__(self, d):
|
|
36
|
+
out = type(self)(*d["_ezpickle_args"], **d["_ezpickle_kwargs"])
|
|
37
|
+
self.__dict__.update(out.__dict__)
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
8
|
+
def json_encode_np(obj):
|
|
9
|
+
"""
|
|
10
|
+
JSON can't serialize numpy types, so convert to pure python
|
|
11
|
+
"""
|
|
12
|
+
if isinstance(obj, np.ndarray):
|
|
13
|
+
return list(obj)
|
|
14
|
+
elif isinstance(obj, np.float32):
|
|
15
|
+
return float(obj)
|
|
16
|
+
elif isinstance(obj, np.float64):
|
|
17
|
+
return float(obj)
|
|
18
|
+
elif isinstance(obj, np.int8):
|
|
19
|
+
return int(obj)
|
|
20
|
+
elif isinstance(obj, np.int16):
|
|
21
|
+
return int(obj)
|
|
22
|
+
elif isinstance(obj, np.int32):
|
|
23
|
+
return int(obj)
|
|
24
|
+
elif isinstance(obj, np.int64):
|
|
25
|
+
return int(obj)
|
|
26
|
+
else:
|
|
27
|
+
return obj
|
|
@@ -0,0 +1,101 @@
|
|
|
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 hashlib
|
|
6
|
+
import numpy as np
|
|
7
|
+
import os
|
|
8
|
+
import random as _random
|
|
9
|
+
import struct
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
from cuju.gfootball._gym._vendored import error
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def np_random(seed=None):
|
|
16
|
+
if seed is not None and not (isinstance(seed, int) and 0 <= seed):
|
|
17
|
+
raise error.Error(
|
|
18
|
+
"Seed must be a non-negative integer or omitted, not {}".format(seed)
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
seed = create_seed(seed)
|
|
22
|
+
|
|
23
|
+
rng = np.random.RandomState()
|
|
24
|
+
rng.seed(_int_list_from_bigint(hash_seed(seed)))
|
|
25
|
+
return rng, seed
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def hash_seed(seed=None, max_bytes=8):
|
|
29
|
+
"""Any given evaluation is likely to have many PRNG's active at
|
|
30
|
+
once. (Most commonly, because the environment is running in
|
|
31
|
+
multiple processes.) There's literature indicating that having
|
|
32
|
+
linear correlations between seeds of multiple PRNG's can correlate
|
|
33
|
+
the outputs:
|
|
34
|
+
|
|
35
|
+
http://blogs.unity3d.com/2015/01/07/a-primer-on-repeatable-random-numbers/
|
|
36
|
+
http://stackoverflow.com/questions/1554958/how-different-do-random-seeds-need-to-be
|
|
37
|
+
http://dl.acm.org/citation.cfm?id=1276928
|
|
38
|
+
|
|
39
|
+
Thus, for sanity we hash the seeds before using them. (This scheme
|
|
40
|
+
is likely not crypto-strength, but it should be good enough to get
|
|
41
|
+
rid of simple correlations.)
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
seed (Optional[int]): None seeds from an operating system specific randomness source.
|
|
45
|
+
max_bytes: Maximum number of bytes to use in the hashed seed.
|
|
46
|
+
"""
|
|
47
|
+
if seed is None:
|
|
48
|
+
seed = create_seed(max_bytes=max_bytes)
|
|
49
|
+
hash = hashlib.sha512(str(seed).encode("utf8")).digest()
|
|
50
|
+
return _bigint_from_bytes(hash[:max_bytes])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def create_seed(a=None, max_bytes=8):
|
|
54
|
+
"""Create a strong random seed. Otherwise, Python 2 would seed using
|
|
55
|
+
the system time, which might be non-robust especially in the
|
|
56
|
+
presence of concurrency.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
a (Optional[int, str]): None seeds from an operating system specific randomness source.
|
|
60
|
+
max_bytes: Maximum number of bytes to use in the seed.
|
|
61
|
+
"""
|
|
62
|
+
# Adapted from https://svn.python.org/projects/python/tags/r32/Lib/random.py
|
|
63
|
+
if a is None:
|
|
64
|
+
a = _bigint_from_bytes(os.urandom(max_bytes))
|
|
65
|
+
elif isinstance(a, str):
|
|
66
|
+
a = a.encode("utf8")
|
|
67
|
+
a += hashlib.sha512(a).digest()
|
|
68
|
+
a = _bigint_from_bytes(a[:max_bytes])
|
|
69
|
+
elif isinstance(a, int):
|
|
70
|
+
a = a % 2 ** (8 * max_bytes)
|
|
71
|
+
else:
|
|
72
|
+
raise error.Error("Invalid type for seed: {} ({})".format(type(a), a))
|
|
73
|
+
|
|
74
|
+
return a
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# TODO: don't hardcode sizeof_int here
|
|
78
|
+
def _bigint_from_bytes(bytes):
|
|
79
|
+
sizeof_int = 4
|
|
80
|
+
padding = sizeof_int - len(bytes) % sizeof_int
|
|
81
|
+
bytes += b"\0" * padding
|
|
82
|
+
int_count = int(len(bytes) / sizeof_int)
|
|
83
|
+
unpacked = struct.unpack("{}I".format(int_count), bytes)
|
|
84
|
+
accum = 0
|
|
85
|
+
for i, val in enumerate(unpacked):
|
|
86
|
+
accum += 2 ** (sizeof_int * 8 * i) * val
|
|
87
|
+
return accum
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _int_list_from_bigint(bigint):
|
|
91
|
+
# Special case 0
|
|
92
|
+
if bigint < 0:
|
|
93
|
+
raise error.Error("Seed must be non-negative, not {}".format(bigint))
|
|
94
|
+
elif bigint == 0:
|
|
95
|
+
return [0]
|
|
96
|
+
|
|
97
|
+
ints = []
|
|
98
|
+
while bigint > 0:
|
|
99
|
+
bigint, mod = divmod(bigint, 2 ** 32)
|
|
100
|
+
ints.append(mod)
|
|
101
|
+
return ints
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""The two wrappers of gym 0.21.0 that its `make` applies, `OrderEnforcing` and `TimeLimit`."""
|
|
4
|
+
|
|
5
|
+
from cuju.gfootball._gym._vendored.wrappers.order_enforcing import OrderEnforcing
|
|
6
|
+
from cuju.gfootball._gym._vendored.wrappers.time_limit import TimeLimit
|
|
7
|
+
|
|
8
|
+
__all__ = ['OrderEnforcing', 'TimeLimit']
|
|
@@ -0,0 +1,20 @@
|
|
|
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 import _vendored as gym
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OrderEnforcing(gym.Wrapper):
|
|
9
|
+
def __init__(self, env):
|
|
10
|
+
super(OrderEnforcing, self).__init__(env)
|
|
11
|
+
self._has_reset = False
|
|
12
|
+
|
|
13
|
+
def step(self, action):
|
|
14
|
+
assert self._has_reset, "Cannot call env.step() before calling reset()"
|
|
15
|
+
observation, reward, done, info = self.env.step(action)
|
|
16
|
+
return observation, reward, done, info
|
|
17
|
+
|
|
18
|
+
def reset(self, **kwargs):
|
|
19
|
+
self._has_reset = True
|
|
20
|
+
return self.env.reset(**kwargs)
|
|
@@ -0,0 +1,31 @@
|
|
|
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 import _vendored as gym
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TimeLimit(gym.Wrapper):
|
|
9
|
+
def __init__(self, env, max_episode_steps=None):
|
|
10
|
+
super(TimeLimit, self).__init__(env)
|
|
11
|
+
if max_episode_steps is None and self.env.spec is not None:
|
|
12
|
+
max_episode_steps = env.spec.max_episode_steps
|
|
13
|
+
if self.env.spec is not None:
|
|
14
|
+
self.env.spec.max_episode_steps = max_episode_steps
|
|
15
|
+
self._max_episode_steps = max_episode_steps
|
|
16
|
+
self._elapsed_steps = None
|
|
17
|
+
|
|
18
|
+
def step(self, action):
|
|
19
|
+
assert (
|
|
20
|
+
self._elapsed_steps is not None
|
|
21
|
+
), "Cannot call env.step() before calling reset()"
|
|
22
|
+
observation, reward, done, info = self.env.step(action)
|
|
23
|
+
self._elapsed_steps += 1
|
|
24
|
+
if self._elapsed_steps >= self._max_episode_steps:
|
|
25
|
+
info["TimeLimit.truncated"] = not done
|
|
26
|
+
done = True
|
|
27
|
+
return observation, reward, done, info
|
|
28
|
+
|
|
29
|
+
def reset(self, **kwargs):
|
|
30
|
+
self._elapsed_steps = 0
|
|
31
|
+
return self.env.reset(**kwargs)
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
"""Script converting dump file to human readable format.
|
|
19
|
+
|
|
20
|
+
Example usage:
|
|
21
|
+
python dump_to_txt.py --trace_file=/tmp/input.dump --output=/tmp/output.txt
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import absolute_import
|
|
26
|
+
from __future__ import division
|
|
27
|
+
from __future__ import print_function
|
|
28
|
+
|
|
29
|
+
from absl import app
|
|
30
|
+
from absl import flags
|
|
31
|
+
from cuju.gfootball.env import script_helpers
|
|
32
|
+
|
|
33
|
+
FLAGS = flags.FLAGS
|
|
34
|
+
|
|
35
|
+
flags.DEFINE_string('trace_file', None, 'Trace file to convert')
|
|
36
|
+
flags.DEFINE_string('output', None, 'Output txt file')
|
|
37
|
+
flags.DEFINE_bool('include_debug', True,
|
|
38
|
+
'Include debug information for each step')
|
|
39
|
+
flags.mark_flag_as_required('trace_file')
|
|
40
|
+
flags.mark_flag_as_required('output')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main(_):
|
|
44
|
+
script_helpers.ScriptHelpers().dump_to_txt(FLAGS.trace_file, FLAGS.output,
|
|
45
|
+
FLAGS.include_debug)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == '__main__':
|
|
49
|
+
app.run(main)
|
|
@@ -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
|
+
"""Script allowing to render a replay video from a game dump."""
|
|
18
|
+
|
|
19
|
+
from absl import app
|
|
20
|
+
from absl import flags
|
|
21
|
+
from cuju.gfootball.env import script_helpers
|
|
22
|
+
|
|
23
|
+
FLAGS = flags.FLAGS
|
|
24
|
+
flags.DEFINE_string('trace_file', None, 'Trace file to render')
|
|
25
|
+
flags.mark_flag_as_required('trace_file')
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main(_):
|
|
29
|
+
script_helpers.ScriptHelpers().dump_to_video(FLAGS.trace_file)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == '__main__':
|
|
33
|
+
app.run(main)
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
"""GFootball Environment."""
|
|
18
|
+
|
|
19
|
+
from __future__ import absolute_import
|
|
20
|
+
from __future__ import division
|
|
21
|
+
from __future__ import print_function
|
|
22
|
+
|
|
23
|
+
from cuju.gfootball.env import config
|
|
24
|
+
from cuju.gfootball.env import football_env
|
|
25
|
+
from cuju.gfootball.env import observation_preprocessing
|
|
26
|
+
from cuju.gfootball.env import wrappers
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _process_reward_wrappers(env, rewards):
|
|
30
|
+
assert 'scoring' in rewards.split(',')
|
|
31
|
+
if 'checkpoints' in rewards.split(','):
|
|
32
|
+
env = wrappers.CheckpointRewardWrapper(env)
|
|
33
|
+
return env
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _process_representation_wrappers(env, representation, channel_dimensions):
|
|
37
|
+
"""Wraps with necessary representation wrappers.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
env: A GFootball gym environment.
|
|
41
|
+
representation: See create_environment.representation comment.
|
|
42
|
+
channel_dimensions: (width, height) tuple that represents the dimensions of
|
|
43
|
+
SMM or pixels representation.
|
|
44
|
+
Returns:
|
|
45
|
+
Google Research Football environment.
|
|
46
|
+
"""
|
|
47
|
+
if representation.startswith('pixels'):
|
|
48
|
+
env = wrappers.PixelsStateWrapper(env, 'gray' in representation,
|
|
49
|
+
channel_dimensions)
|
|
50
|
+
elif representation == 'simple115':
|
|
51
|
+
env = wrappers.Simple115StateWrapper(env)
|
|
52
|
+
elif representation == 'simple115v2':
|
|
53
|
+
env = wrappers.Simple115StateWrapper(env, True)
|
|
54
|
+
elif representation == 'extracted':
|
|
55
|
+
env = wrappers.SMMWrapper(env, channel_dimensions)
|
|
56
|
+
elif representation == 'raw':
|
|
57
|
+
pass
|
|
58
|
+
else:
|
|
59
|
+
raise ValueError('Unsupported representation: {}'.format(representation))
|
|
60
|
+
return env
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _apply_output_wrappers(env, rewards, representation, channel_dimensions,
|
|
64
|
+
apply_single_agent_wrappers, stacked):
|
|
65
|
+
"""Wraps with necessary wrappers modifying the output of the environment.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
env: A GFootball gym environment.
|
|
69
|
+
rewards: What rewards to apply.
|
|
70
|
+
representation: See create_environment.representation comment.
|
|
71
|
+
channel_dimensions: (width, height) tuple that represents the dimensions of
|
|
72
|
+
SMM or pixels representation.
|
|
73
|
+
apply_single_agent_wrappers: Whether to reduce output to single agent case.
|
|
74
|
+
stacked: Should observations be stacked.
|
|
75
|
+
Returns:
|
|
76
|
+
Google Research Football environment.
|
|
77
|
+
"""
|
|
78
|
+
env = _process_reward_wrappers(env, rewards)
|
|
79
|
+
env = _process_representation_wrappers(env, representation,
|
|
80
|
+
channel_dimensions)
|
|
81
|
+
if apply_single_agent_wrappers:
|
|
82
|
+
if representation != 'raw':
|
|
83
|
+
env = wrappers.SingleAgentObservationWrapper(env)
|
|
84
|
+
env = wrappers.SingleAgentRewardWrapper(env)
|
|
85
|
+
if stacked:
|
|
86
|
+
env = wrappers.FrameStack(env, 4)
|
|
87
|
+
env = wrappers.GetStateWrapper(env)
|
|
88
|
+
return env
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def create_environment(env_name='',
|
|
92
|
+
stacked=False,
|
|
93
|
+
representation='extracted',
|
|
94
|
+
rewards='scoring',
|
|
95
|
+
write_goal_dumps=False,
|
|
96
|
+
write_full_episode_dumps=False,
|
|
97
|
+
render=False,
|
|
98
|
+
write_video=False,
|
|
99
|
+
dump_frequency=1,
|
|
100
|
+
logdir='',
|
|
101
|
+
extra_players=None,
|
|
102
|
+
number_of_left_players_agent_controls=1,
|
|
103
|
+
number_of_right_players_agent_controls=0,
|
|
104
|
+
channel_dimensions=(
|
|
105
|
+
observation_preprocessing.SMM_WIDTH,
|
|
106
|
+
observation_preprocessing.SMM_HEIGHT),
|
|
107
|
+
other_config_options={}):
|
|
108
|
+
"""Creates a Google Research Football environment.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
env_name: a name of a scenario to run, e.g. "11_vs_11_stochastic".
|
|
112
|
+
The list of scenarios can be found in directory "scenarios".
|
|
113
|
+
stacked: If True, stack 4 observations, otherwise, only the last
|
|
114
|
+
observation is returned by the environment.
|
|
115
|
+
Stacking is only possible when representation is one of the following:
|
|
116
|
+
"pixels", "pixels_gray" or "extracted".
|
|
117
|
+
In that case, the stacking is done along the last (i.e. channel)
|
|
118
|
+
dimension.
|
|
119
|
+
representation: String to define the representation used to build
|
|
120
|
+
the observation. It can be one of the following:
|
|
121
|
+
'pixels': the observation is the rendered view of the football field
|
|
122
|
+
downsampled to 'channel_dimensions'. The observation size is:
|
|
123
|
+
'channel_dimensions'x3 (or 'channel_dimensions'x12 when "stacked" is
|
|
124
|
+
True).
|
|
125
|
+
'pixels_gray': the observation is the rendered view of the football field
|
|
126
|
+
in gray scale and downsampled to 'channel_dimensions'. The observation
|
|
127
|
+
size is 'channel_dimensions'x1 (or 'channel_dimensions'x4 when stacked
|
|
128
|
+
is True).
|
|
129
|
+
'extracted': also referred to as super minimap. The observation is
|
|
130
|
+
composed of 4 planes of size 'channel_dimensions'.
|
|
131
|
+
Its size is then 'channel_dimensions'x4 (or 'channel_dimensions'x16 when
|
|
132
|
+
stacked is True).
|
|
133
|
+
The first plane P holds the position of players on the left
|
|
134
|
+
team, P[y,x] is 255 if there is a player at position (x,y), otherwise,
|
|
135
|
+
its value is 0.
|
|
136
|
+
The second plane holds in the same way the position of players
|
|
137
|
+
on the right team.
|
|
138
|
+
The third plane holds the position of the ball.
|
|
139
|
+
The last plane holds the active player.
|
|
140
|
+
'simple115'/'simple115v2': the observation is a vector of size 115.
|
|
141
|
+
It holds:
|
|
142
|
+
- the ball_position and the ball_direction as (x,y,z)
|
|
143
|
+
- one hot encoding of who controls the ball.
|
|
144
|
+
[1, 0, 0]: nobody, [0, 1, 0]: left team, [0, 0, 1]: right team.
|
|
145
|
+
- one hot encoding of size 11 to indicate who is the active player
|
|
146
|
+
in the left team.
|
|
147
|
+
- 11 (x,y) positions for each player of the left team.
|
|
148
|
+
- 11 (x,y) motion vectors for each player of the left team.
|
|
149
|
+
- 11 (x,y) positions for each player of the right team.
|
|
150
|
+
- 11 (x,y) motion vectors for each player of the right team.
|
|
151
|
+
- one hot encoding of the game mode. Vector of size 7 with the
|
|
152
|
+
following meaning:
|
|
153
|
+
{NormalMode, KickOffMode, GoalKickMode, FreeKickMode,
|
|
154
|
+
CornerMode, ThrowInMode, PenaltyMode}.
|
|
155
|
+
Can only be used when the scenario is a flavor of normal game
|
|
156
|
+
(i.e. 11 versus 11 players).
|
|
157
|
+
rewards: Comma separated list of rewards to be added.
|
|
158
|
+
Currently supported rewards are 'scoring' and 'checkpoints'.
|
|
159
|
+
write_goal_dumps: whether to dump traces up to 200 frames before goals.
|
|
160
|
+
write_full_episode_dumps: whether to dump traces for every episode.
|
|
161
|
+
render: whether to render game frames.
|
|
162
|
+
Must be enable when rendering videos or when using pixels
|
|
163
|
+
representation.
|
|
164
|
+
write_video: whether to dump videos when a trace is dumped.
|
|
165
|
+
dump_frequency: how often to write dumps/videos (in terms of # of episodes)
|
|
166
|
+
Sub-sample the episodes for which we dump videos to save some disk space.
|
|
167
|
+
logdir: directory holding the logs.
|
|
168
|
+
extra_players: A list of extra players to use in the environment.
|
|
169
|
+
Each player is defined by a string like:
|
|
170
|
+
"$player_name:left_players=?,right_players=?,$param1=?,$param2=?...."
|
|
171
|
+
number_of_left_players_agent_controls: Number of left players an agent
|
|
172
|
+
controls.
|
|
173
|
+
number_of_right_players_agent_controls: Number of right players an agent
|
|
174
|
+
controls.
|
|
175
|
+
channel_dimensions: (width, height) tuple that represents the dimensions of
|
|
176
|
+
SMM or pixels representation.
|
|
177
|
+
other_config_options: dict that allows directly setting other options in
|
|
178
|
+
the Config
|
|
179
|
+
Returns:
|
|
180
|
+
Google Research Football environment.
|
|
181
|
+
"""
|
|
182
|
+
assert env_name
|
|
183
|
+
|
|
184
|
+
scenario_config = config.Config({'level': env_name}).ScenarioConfig()
|
|
185
|
+
players = [('agent:left_players=%d,right_players=%d' % (
|
|
186
|
+
number_of_left_players_agent_controls,
|
|
187
|
+
number_of_right_players_agent_controls))]
|
|
188
|
+
|
|
189
|
+
# Enable MultiAgentToSingleAgent wrapper?
|
|
190
|
+
multiagent_to_singleagent = False
|
|
191
|
+
if scenario_config.control_all_players:
|
|
192
|
+
if (number_of_left_players_agent_controls in [0, 1] and
|
|
193
|
+
number_of_right_players_agent_controls in [0, 1]):
|
|
194
|
+
multiagent_to_singleagent = True
|
|
195
|
+
players = [('agent:left_players=%d,right_players=%d' %
|
|
196
|
+
(scenario_config.controllable_left_players
|
|
197
|
+
if number_of_left_players_agent_controls else 0,
|
|
198
|
+
scenario_config.controllable_right_players
|
|
199
|
+
if number_of_right_players_agent_controls else 0))]
|
|
200
|
+
|
|
201
|
+
if extra_players is not None:
|
|
202
|
+
players.extend(extra_players)
|
|
203
|
+
config_values = {
|
|
204
|
+
'dump_full_episodes': write_full_episode_dumps,
|
|
205
|
+
'dump_scores': write_goal_dumps,
|
|
206
|
+
'players': players,
|
|
207
|
+
'level': env_name,
|
|
208
|
+
'tracesdir': logdir,
|
|
209
|
+
'write_video': write_video,
|
|
210
|
+
}
|
|
211
|
+
config_values.update(other_config_options)
|
|
212
|
+
c = config.Config(config_values)
|
|
213
|
+
|
|
214
|
+
env = football_env.FootballEnv(c)
|
|
215
|
+
if multiagent_to_singleagent:
|
|
216
|
+
env = wrappers.MultiAgentToSingleAgent(
|
|
217
|
+
env, number_of_left_players_agent_controls,
|
|
218
|
+
number_of_right_players_agent_controls)
|
|
219
|
+
if dump_frequency > 1:
|
|
220
|
+
env = wrappers.PeriodicDumpWriter(env, dump_frequency, render)
|
|
221
|
+
elif render:
|
|
222
|
+
env.render()
|
|
223
|
+
env = _apply_output_wrappers(
|
|
224
|
+
env, rewards, representation, channel_dimensions,
|
|
225
|
+
(number_of_left_players_agent_controls +
|
|
226
|
+
number_of_right_players_agent_controls == 1), stacked)
|
|
227
|
+
return env
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def create_remote_environment(
|
|
231
|
+
username,
|
|
232
|
+
token,
|
|
233
|
+
model_name='',
|
|
234
|
+
track='',
|
|
235
|
+
stacked=False,
|
|
236
|
+
representation='raw',
|
|
237
|
+
rewards='scoring',
|
|
238
|
+
channel_dimensions=(
|
|
239
|
+
observation_preprocessing.SMM_WIDTH,
|
|
240
|
+
observation_preprocessing.SMM_HEIGHT),
|
|
241
|
+
include_rendering=False):
|
|
242
|
+
"""Creates a remote Google Research Football environment.
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
username: User name.
|
|
246
|
+
token: User token.
|
|
247
|
+
model_name: A model identifier to be displayed on the leaderboard.
|
|
248
|
+
track: which competition track to connect to.
|
|
249
|
+
stacked: If True, stack 4 observations, otherwise, only the last
|
|
250
|
+
observation is returned by the environment.
|
|
251
|
+
Stacking is only possible when representation is one of the following:
|
|
252
|
+
"pixels", "pixels_gray" or "extracted".
|
|
253
|
+
In that case, the stacking is done along the last (i.e. channel)
|
|
254
|
+
dimension.
|
|
255
|
+
representation: See create_environment.representation comment.
|
|
256
|
+
rewards: Comma separated list of rewards to be added.
|
|
257
|
+
Currently supported rewards are 'scoring' and 'checkpoints'.
|
|
258
|
+
channel_dimensions: (width, height) tuple that represents the dimensions of
|
|
259
|
+
SMM or pixels representation.
|
|
260
|
+
include_rendering: Whether to return frame as part of the output.
|
|
261
|
+
Returns:
|
|
262
|
+
Google Research Football environment.
|
|
263
|
+
"""
|
|
264
|
+
from cuju.gfootball.env import remote_football_env
|
|
265
|
+
env = remote_football_env.RemoteFootballEnv(
|
|
266
|
+
username, token, model_name=model_name, track=track,
|
|
267
|
+
include_rendering=include_rendering)
|
|
268
|
+
env = _apply_output_wrappers(
|
|
269
|
+
env, rewards, representation, channel_dimensions,
|
|
270
|
+
env._config.number_of_players_agent_controls() == 1, stacked)
|
|
271
|
+
return env
|