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,150 @@
|
|
|
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
|
+
"""Tests for gym wrappers."""
|
|
19
|
+
|
|
20
|
+
from __future__ import absolute_import
|
|
21
|
+
from __future__ import division
|
|
22
|
+
from __future__ import print_function
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
from cuju.gfootball import _gym as gym
|
|
26
|
+
import numpy as np
|
|
27
|
+
from absl.testing import absltest
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SingleAgentWrapperTest(absltest.TestCase):
|
|
31
|
+
|
|
32
|
+
def test_consistent_observation_and_action(self):
|
|
33
|
+
env = gym.make(
|
|
34
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-SMM-v0',
|
|
35
|
+
number_of_left_players_agent_controls=1)
|
|
36
|
+
|
|
37
|
+
self.assertEqual(
|
|
38
|
+
gym.spaces.Box(low=0, high=255, shape=(72, 96, 4), dtype=np.uint8),
|
|
39
|
+
env.observation_space)
|
|
40
|
+
|
|
41
|
+
env.reset()
|
|
42
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
43
|
+
self.assertEqual((72, 96, 4), obs.shape)
|
|
44
|
+
env.close()
|
|
45
|
+
|
|
46
|
+
env = gym.make(
|
|
47
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-SMM-v0',
|
|
48
|
+
number_of_left_players_agent_controls=2)
|
|
49
|
+
|
|
50
|
+
self.assertEqual(
|
|
51
|
+
gym.spaces.Box(low=0, high=255, shape=(2, 72, 96, 4), dtype=np.uint8),
|
|
52
|
+
env.observation_space)
|
|
53
|
+
|
|
54
|
+
env.reset()
|
|
55
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
56
|
+
self.assertEqual((2, 72, 96, 4), obs.shape)
|
|
57
|
+
env.close()
|
|
58
|
+
|
|
59
|
+
def test_consistent_observation_and_action_stacked(self):
|
|
60
|
+
env = gym.make(
|
|
61
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-SMM-v0',
|
|
62
|
+
number_of_left_players_agent_controls=1,
|
|
63
|
+
stacked=True)
|
|
64
|
+
|
|
65
|
+
self.assertEqual(
|
|
66
|
+
gym.spaces.Box(low=0, high=255, shape=(72, 96, 16), dtype=np.uint8),
|
|
67
|
+
env.observation_space)
|
|
68
|
+
|
|
69
|
+
env.reset()
|
|
70
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
71
|
+
self.assertEqual((72, 96, 16), obs.shape)
|
|
72
|
+
env.close()
|
|
73
|
+
|
|
74
|
+
env = gym.make(
|
|
75
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-SMM-v0',
|
|
76
|
+
number_of_left_players_agent_controls=2,
|
|
77
|
+
stacked=True)
|
|
78
|
+
|
|
79
|
+
self.assertEqual(
|
|
80
|
+
gym.spaces.Box(low=0, high=255, shape=(2, 72, 96, 16), dtype=np.uint8),
|
|
81
|
+
env.observation_space)
|
|
82
|
+
|
|
83
|
+
env.reset()
|
|
84
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
85
|
+
self.assertEqual((2, 72, 96, 16), obs.shape)
|
|
86
|
+
env.close()
|
|
87
|
+
|
|
88
|
+
def test_consistent_observation_and_action_pixels(self):
|
|
89
|
+
if 'UNITTEST_IN_DOCKER' in os.environ:
|
|
90
|
+
# Forge doesn't support rendering.
|
|
91
|
+
return
|
|
92
|
+
env = gym.make(
|
|
93
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-Pixels-v0',
|
|
94
|
+
number_of_left_players_agent_controls=1,
|
|
95
|
+
render=True)
|
|
96
|
+
|
|
97
|
+
self.assertEqual(
|
|
98
|
+
gym.spaces.Box(low=0, high=255, shape=(72, 96, 3), dtype=np.uint8),
|
|
99
|
+
env.observation_space)
|
|
100
|
+
|
|
101
|
+
env.reset()
|
|
102
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
103
|
+
self.assertEqual((72, 96, 3), obs.shape)
|
|
104
|
+
env.close()
|
|
105
|
+
|
|
106
|
+
env = gym.make(
|
|
107
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-Pixels-v0',
|
|
108
|
+
number_of_left_players_agent_controls=2,
|
|
109
|
+
render=True)
|
|
110
|
+
|
|
111
|
+
self.assertEqual(
|
|
112
|
+
gym.spaces.Box(low=0, high=255, shape=(2, 72, 96, 3), dtype=np.uint8),
|
|
113
|
+
env.observation_space)
|
|
114
|
+
|
|
115
|
+
env.reset()
|
|
116
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
117
|
+
self.assertEqual((2, 72, 96, 3), obs.shape)
|
|
118
|
+
env.close()
|
|
119
|
+
|
|
120
|
+
def test_consistent_observation_and_action_floats(self):
|
|
121
|
+
env = gym.make(
|
|
122
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-simple115-v0',
|
|
123
|
+
number_of_left_players_agent_controls=1)
|
|
124
|
+
|
|
125
|
+
self.assertEqual(
|
|
126
|
+
gym.spaces.Box(
|
|
127
|
+
low=-np.inf, high=np.inf, shape=(115,), dtype=np.float32),
|
|
128
|
+
env.observation_space)
|
|
129
|
+
|
|
130
|
+
env.reset()
|
|
131
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
132
|
+
self.assertEqual((115,), obs.shape)
|
|
133
|
+
env.close()
|
|
134
|
+
|
|
135
|
+
env = gym.make(
|
|
136
|
+
'cuju.gfootball:GFootball-11_vs_11_easy_stochastic-simple115-v0',
|
|
137
|
+
number_of_left_players_agent_controls=2)
|
|
138
|
+
|
|
139
|
+
self.assertEqual(
|
|
140
|
+
gym.spaces.Box(
|
|
141
|
+
low=-np.inf, high=np.inf, shape=(2, 115), dtype=np.float32),
|
|
142
|
+
env.observation_space)
|
|
143
|
+
|
|
144
|
+
env.reset()
|
|
145
|
+
obs, _, _, _ = env.step(env.action_space.sample())
|
|
146
|
+
self.assertEqual((2, 115), obs.shape)
|
|
147
|
+
env.close()
|
|
148
|
+
|
|
149
|
+
if __name__ == '__main__':
|
|
150
|
+
absltest.main()
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
"""Config values like number of instances, ports, etc."""
|
|
18
|
+
|
|
19
|
+
grpc_port = 50000
|
|
20
|
+
master_address_bucket = 'grf_public'
|
|
21
|
+
master_address_file = 'eval_server_master_ip'
|
|
22
|
+
master_address_public_path = 'https://storage.googleapis.com/{}/{}'.format(
|
|
23
|
+
master_address_bucket, master_address_file)
|
|
24
|
+
game_version = '2.0'
|
|
25
|
+
|
|
26
|
+
track_to_num_controlled_players = {
|
|
27
|
+
'mini': 1,
|
|
28
|
+
'11vs11': 1,
|
|
29
|
+
'multiagent': 4,
|
|
30
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
"""Example football client.
|
|
18
|
+
|
|
19
|
+
It creates remote football game with given credentials and plays a few games.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import random
|
|
23
|
+
|
|
24
|
+
from absl import app
|
|
25
|
+
from absl import flags
|
|
26
|
+
from absl import logging
|
|
27
|
+
import cuju.gfootball.env as football_env
|
|
28
|
+
from cuju.gfootball.env import football_action_set
|
|
29
|
+
import grpc
|
|
30
|
+
import numpy as np
|
|
31
|
+
import tensorflow.compat.v2 as tf
|
|
32
|
+
|
|
33
|
+
FLAGS = flags.FLAGS
|
|
34
|
+
flags.DEFINE_string('username', None, 'Username to use')
|
|
35
|
+
flags.mark_flag_as_required('username')
|
|
36
|
+
flags.DEFINE_string('token', None, 'Token to use.')
|
|
37
|
+
flags.DEFINE_integer('how_many', 1000, 'How many games to play')
|
|
38
|
+
flags.DEFINE_bool('render', False, 'Whether to render a game.')
|
|
39
|
+
flags.DEFINE_string('track', '', 'Name of the competition track.')
|
|
40
|
+
flags.DEFINE_string('model_name', '',
|
|
41
|
+
'A model identifier to be displayed on the leaderboard.')
|
|
42
|
+
flags.DEFINE_string('inference_model', '',
|
|
43
|
+
'A path to an inference model. Empty for random actions')
|
|
44
|
+
|
|
45
|
+
NUM_ACTIONS = len(football_action_set.action_set_dict['default'])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def random_actions(obs):
|
|
49
|
+
num_players = 1 if len(obs.shape) == 3 else obs.shape[0]
|
|
50
|
+
a = []
|
|
51
|
+
for _ in range(num_players):
|
|
52
|
+
a.append(random.randint(0, NUM_ACTIONS - 1))
|
|
53
|
+
return a
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def seed_rl_preprocessing(observation):
|
|
57
|
+
observation = np.expand_dims(observation, axis=0)
|
|
58
|
+
data = np.packbits(observation, axis=-1) # This packs to uint8
|
|
59
|
+
if data.shape[-1] % 2 == 1:
|
|
60
|
+
data = np.pad(data, [(0, 0)] * (data.ndim - 1) + [(0, 1)], 'constant')
|
|
61
|
+
return data.view(np.uint16)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def generate_actions(obs, model):
|
|
65
|
+
a = []
|
|
66
|
+
# Single agent case
|
|
67
|
+
if len(obs.shape) == 3:
|
|
68
|
+
a.append(model(seed_rl_preprocessing(obs))[0][0].numpy())
|
|
69
|
+
else:
|
|
70
|
+
# Multiagent -> first dimension is a number of agents you control.
|
|
71
|
+
for x in range(obs.shape[0]):
|
|
72
|
+
a.append(model(seed_rl_preprocessing(obs[x]))[0][0].numpy())
|
|
73
|
+
return a
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_inference_model(inference_model):
|
|
77
|
+
if not inference_model or FLAGS.username == 'random':
|
|
78
|
+
return random_actions
|
|
79
|
+
model = tf.saved_model.load(inference_model)
|
|
80
|
+
return lambda obs: generate_actions(obs, model)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main(unused_argv):
|
|
84
|
+
model = get_inference_model(FLAGS.inference_model)
|
|
85
|
+
env = football_env.create_remote_environment(
|
|
86
|
+
FLAGS.username, FLAGS.token, FLAGS.model_name, track=FLAGS.track,
|
|
87
|
+
representation='extracted', stacked=True,
|
|
88
|
+
include_rendering=FLAGS.render)
|
|
89
|
+
for _ in range(FLAGS.how_many):
|
|
90
|
+
ob = env.reset()
|
|
91
|
+
cnt = 1
|
|
92
|
+
done = False
|
|
93
|
+
while not done:
|
|
94
|
+
try:
|
|
95
|
+
action = model(ob)
|
|
96
|
+
ob, rew, done, _ = env.step(action)
|
|
97
|
+
logging.info('Playing the game, step %d, action %s, rew %s, done %d',
|
|
98
|
+
cnt, action, rew, done)
|
|
99
|
+
cnt += 1
|
|
100
|
+
except grpc.RpcError as e:
|
|
101
|
+
print(e)
|
|
102
|
+
break
|
|
103
|
+
print('=' * 50)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if __name__ == '__main__':
|
|
107
|
+
app.run(main)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright 2019 Google LLC
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
syntax = "proto3";
|
|
5
|
+
|
|
6
|
+
package gfootball.eval_server;
|
|
7
|
+
|
|
8
|
+
message GetEnvResultRequest {
|
|
9
|
+
string game_version = 1; // string to check if client and server have matching versions
|
|
10
|
+
string game_id = 2;
|
|
11
|
+
string username = 3;
|
|
12
|
+
string token = 4;
|
|
13
|
+
string model_name = 5;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
message GetEnvResultResponse {
|
|
17
|
+
bytes env_result = 1; // pickled state 4-tuple (observation, reward, done, info)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
message StepRequest {
|
|
21
|
+
string game_version = 1; // string to check if client and server have matching versions
|
|
22
|
+
string game_id = 2;
|
|
23
|
+
string username = 3;
|
|
24
|
+
string token = 4;
|
|
25
|
+
int32 action = 5;
|
|
26
|
+
string model_name = 6;
|
|
27
|
+
repeated int32 action_list = 7;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
message StepResponse {
|
|
31
|
+
bytes env_result = 1; // pickled state 4-tuple (observation, reward, done, info)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
message GetCapacityRequest {}
|
|
35
|
+
|
|
36
|
+
message GetCapacityResponse {
|
|
37
|
+
int32 capacity_for_games = 1; // number indicating how many more games can be scheduled
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
message CreateGameRequest {
|
|
41
|
+
string game_id = 1;
|
|
42
|
+
string left_player = 2;
|
|
43
|
+
string right_player = 3;
|
|
44
|
+
bool include_rendering = 4;
|
|
45
|
+
string track = 5;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
message CreateGameResponse {
|
|
49
|
+
bool success = 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
service GameServer {
|
|
53
|
+
// Rpc for obtaining the current state.
|
|
54
|
+
rpc GetEnvResult(GetEnvResultRequest) returns (GetEnvResultResponse) {}
|
|
55
|
+
// Rpc for doing a step in the environment and obtaining a state after that.
|
|
56
|
+
rpc Step(StepRequest) returns (StepResponse) {}
|
|
57
|
+
// Rpc for informing Master how many games can still be scheduled on this GS.
|
|
58
|
+
rpc GetCapacity(GetCapacityRequest) returns (GetCapacityResponse) {}
|
|
59
|
+
// Rpc to create a new game instance, only called by Master.
|
|
60
|
+
rpc CreateGame(CreateGameRequest) returns (CreateGameResponse) {}
|
|
61
|
+
}
|
|
62
|
+
|