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,1624 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""GRF's module `_gameplayfootball` over cuju's engine, with its names, types and conversions.
|
|
6
|
+
|
|
7
|
+
Every class, enumeration and method keeps the behaviour of GRF's boost.python module, so GRF's
|
|
8
|
+
Python runs on it unchanged. A call that GRF answers with a fatal error raises instead.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import ctypes
|
|
14
|
+
import os
|
|
15
|
+
import pickle
|
|
16
|
+
import struct
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
import weakref
|
|
20
|
+
|
|
21
|
+
from .. import errors as _errors
|
|
22
|
+
from ..scenarios import ScenarioError
|
|
23
|
+
from . import _native, _pickle_names, _render_hooks
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
'ControllerInfo',
|
|
27
|
+
'ControllerInfoVec',
|
|
28
|
+
'FloatVec',
|
|
29
|
+
'FormationEntry',
|
|
30
|
+
'FormationEntryVec',
|
|
31
|
+
'GameConfig',
|
|
32
|
+
'GameEnv',
|
|
33
|
+
'GameState',
|
|
34
|
+
'IntVec',
|
|
35
|
+
'PlayerInfo',
|
|
36
|
+
'PlayerInfoVec',
|
|
37
|
+
'Position',
|
|
38
|
+
'ScenarioConfig',
|
|
39
|
+
'SharedInfo',
|
|
40
|
+
'StringVector',
|
|
41
|
+
'Vector3',
|
|
42
|
+
'e_BackendAction',
|
|
43
|
+
'e_GameMode',
|
|
44
|
+
'e_PlayerRole',
|
|
45
|
+
'e_RenderingMode',
|
|
46
|
+
'e_Team',
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
# The name that GRF's reprs and messages print for this module.
|
|
50
|
+
_NAME = '_gameplayfootball'
|
|
51
|
+
_FLOAT = struct.Struct('<f')
|
|
52
|
+
_PICKLING = (
|
|
53
|
+
'Pickling of "_gameplayfootball.{}" instances is not enabled '
|
|
54
|
+
'(http://www.boost.org/libs/python/doc/v2/pickle.html)'
|
|
55
|
+
)
|
|
56
|
+
_STRING = 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'
|
|
57
|
+
# GRF: `FORMATION_Y_SCALE`, a float.
|
|
58
|
+
_Y_SCALE = _FLOAT.unpack(_FLOAT.pack(-2.36))[0]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _float32(value):
|
|
62
|
+
"""Returns `value` rounded to float, as a C cast rounds it, infinite past the range."""
|
|
63
|
+
try:
|
|
64
|
+
return _FLOAT.unpack(_FLOAT.pack(float(value)))[0]
|
|
65
|
+
except OverflowError:
|
|
66
|
+
return float('inf') if value > 0 else float('-inf')
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class _MismatchError(Exception):
|
|
70
|
+
"""An argument that the C++ signature does not take."""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _type_name(value):
|
|
74
|
+
kind = type(value)
|
|
75
|
+
if kind.__module__ in ('builtins', __name__, _NAME) or kind.__flags__ & (1 << 9):
|
|
76
|
+
return kind.__name__
|
|
77
|
+
return f'{kind.__module__}.{kind.__name__}'
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _signature_error(owner, method, arguments, signature):
|
|
81
|
+
names = ', '.join(_type_name(value) for value in arguments)
|
|
82
|
+
return _errors.SignatureError(
|
|
83
|
+
f'Python argument types in\n {owner}.{method}({names})\n'
|
|
84
|
+
f'did not match C++ signature:\n {signature}'
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# Each converter returns the C++ value of an argument or raises `_MismatchError`.
|
|
89
|
+
def _to_float(value):
|
|
90
|
+
if isinstance(value, (int, float)):
|
|
91
|
+
return _float32(value)
|
|
92
|
+
raise _MismatchError
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _to_int(value):
|
|
96
|
+
if not isinstance(value, int):
|
|
97
|
+
raise _MismatchError
|
|
98
|
+
if value > 2**31 - 1:
|
|
99
|
+
raise OverflowError('bad numeric conversion: positive overflow')
|
|
100
|
+
if value < -(2**31):
|
|
101
|
+
raise OverflowError('bad numeric conversion: negative overflow')
|
|
102
|
+
return int(value)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _to_unsigned(value):
|
|
106
|
+
if not isinstance(value, int):
|
|
107
|
+
raise _MismatchError
|
|
108
|
+
if value < 0:
|
|
109
|
+
raise OverflowError("can't convert negative value to unsigned int")
|
|
110
|
+
if value > 2**32 - 1:
|
|
111
|
+
raise OverflowError('bad numeric conversion: positive overflow')
|
|
112
|
+
return int(value)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _to_long(value):
|
|
116
|
+
if not isinstance(value, int):
|
|
117
|
+
raise _MismatchError
|
|
118
|
+
if not -(2**63) <= value < 2**63:
|
|
119
|
+
raise OverflowError('Python int too large to convert to C long')
|
|
120
|
+
return int(value)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _to_bool(value):
|
|
124
|
+
if value is None:
|
|
125
|
+
return False
|
|
126
|
+
if isinstance(value, int):
|
|
127
|
+
return bool(value)
|
|
128
|
+
raise _MismatchError
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _to_string(value):
|
|
132
|
+
if isinstance(value, bytes):
|
|
133
|
+
return value
|
|
134
|
+
if isinstance(value, str):
|
|
135
|
+
return value.encode('utf-8')
|
|
136
|
+
raise _MismatchError
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _instance(kind):
|
|
140
|
+
def convert(value):
|
|
141
|
+
if not isinstance(value, kind):
|
|
142
|
+
raise _MismatchError
|
|
143
|
+
return value
|
|
144
|
+
|
|
145
|
+
return convert
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _arguments(owner, method, signature, arguments, keywords, converters):
|
|
149
|
+
"""Converts the positional `arguments` of a call as boost.python does, or raises its error."""
|
|
150
|
+
if keywords or len(arguments) != len(converters):
|
|
151
|
+
raise _signature_error(owner, method, arguments, signature)
|
|
152
|
+
try:
|
|
153
|
+
return [convert(value) for convert, value in zip(converters, arguments, strict=True)]
|
|
154
|
+
except _MismatchError:
|
|
155
|
+
raise _signature_error(owner, method, arguments, signature) from None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _setter(owner_type, cpp_type, convert):
|
|
159
|
+
"""Returns the conversion of a property's value, raising the error of boost.python's setter."""
|
|
160
|
+
|
|
161
|
+
def apply(instance, value):
|
|
162
|
+
try:
|
|
163
|
+
return convert(value)
|
|
164
|
+
except _MismatchError:
|
|
165
|
+
raise _signature_error(
|
|
166
|
+
'None',
|
|
167
|
+
'None',
|
|
168
|
+
(instance, value),
|
|
169
|
+
f'None({owner_type} {{lvalue}}, {cpp_type})',
|
|
170
|
+
) from None
|
|
171
|
+
|
|
172
|
+
return apply
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _no_setter(owner):
|
|
176
|
+
def refuse(instance, value):
|
|
177
|
+
raise AttributeError(f"property of '{owner}' object has no setter")
|
|
178
|
+
|
|
179
|
+
return refuse
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _no_deleter(owner):
|
|
183
|
+
def refuse(instance):
|
|
184
|
+
raise AttributeError(f"property of '{owner}' object has no deleter")
|
|
185
|
+
|
|
186
|
+
return refuse
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class _Instance:
|
|
190
|
+
"""The base of every class, which prints as boost.python's and refuses pickling."""
|
|
191
|
+
|
|
192
|
+
def __repr__(self):
|
|
193
|
+
return f'<{_NAME}.{type(self).__name__} object at {hex(id(self))}>'
|
|
194
|
+
|
|
195
|
+
__str__ = __repr__
|
|
196
|
+
|
|
197
|
+
def __reduce_ex__(self, protocol):
|
|
198
|
+
raise RuntimeError(_PICKLING.format(type(self).__name__))
|
|
199
|
+
|
|
200
|
+
def __reduce__(self):
|
|
201
|
+
raise RuntimeError(_PICKLING.format(type(self).__name__))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
# Enumerations.
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class enum(int):
|
|
208
|
+
"""The base of every enumeration, as boost.python's `enum`."""
|
|
209
|
+
|
|
210
|
+
names: dict
|
|
211
|
+
values: dict
|
|
212
|
+
|
|
213
|
+
def __new__(cls, value=0):
|
|
214
|
+
return super().__new__(cls, int(value))
|
|
215
|
+
|
|
216
|
+
def __repr__(self):
|
|
217
|
+
name = self.__dict__.get('name')
|
|
218
|
+
kind = type(self).__name__
|
|
219
|
+
return f'{_NAME}.{kind}.{name}' if name is not None else f'{_NAME}.{kind}({int(self)})'
|
|
220
|
+
|
|
221
|
+
def __str__(self):
|
|
222
|
+
name = self.__dict__.get('name')
|
|
223
|
+
return name if name is not None else repr(self)
|
|
224
|
+
|
|
225
|
+
def __format__(self, spec):
|
|
226
|
+
return str(self) if not spec else int.__format__(int(self), spec)
|
|
227
|
+
|
|
228
|
+
def __reduce_ex__(self, protocol):
|
|
229
|
+
if protocol < 2:
|
|
230
|
+
raise pickle.PicklingError(
|
|
231
|
+
"Can't pickle <class 'Boost.Python.enum'>: import of module 'Boost.Python' failed"
|
|
232
|
+
)
|
|
233
|
+
return (type(self), (int(self),))
|
|
234
|
+
|
|
235
|
+
__hash__ = int.__hash__
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
enum.__module__ = 'Boost.Python'
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _make_enum(name, pairs):
|
|
242
|
+
kind = type(name, (enum,), {'__module__': __name__, '__qualname__': name})
|
|
243
|
+
kind.names = {}
|
|
244
|
+
kind.values = {}
|
|
245
|
+
for label, value in pairs:
|
|
246
|
+
member = kind(value)
|
|
247
|
+
member.name = label
|
|
248
|
+
kind.names[label] = member
|
|
249
|
+
kind.values[value] = member
|
|
250
|
+
setattr(kind, label, member)
|
|
251
|
+
return kind
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _enum_value(kind, value):
|
|
255
|
+
"""The named value of `kind` for `value`, or an unnamed one, as boost.python converts it."""
|
|
256
|
+
member = kind.values.get(value)
|
|
257
|
+
return member if member is not None and int(member) == value else kind(value)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
GameState = _make_enum(
|
|
261
|
+
'GameState',
|
|
262
|
+
[('game_created', 0), ('game_initiated', 1), ('game_running', 2), ('game_done', 3)],
|
|
263
|
+
)
|
|
264
|
+
e_PlayerRole = _make_enum(
|
|
265
|
+
'e_PlayerRole',
|
|
266
|
+
[
|
|
267
|
+
(f'e_PlayerRole_{role}', index)
|
|
268
|
+
for index, role in enumerate(('GK', 'CB', 'LB', 'RB', 'DM', 'CM', 'LM', 'RM', 'AM', 'CF'))
|
|
269
|
+
],
|
|
270
|
+
)
|
|
271
|
+
e_RenderingMode = _make_enum(
|
|
272
|
+
'e_RenderingMode', [('e_Disabled', 0), ('e_Onscreen', 1), ('e_Offscreen', 2)]
|
|
273
|
+
)
|
|
274
|
+
e_GameMode = _make_enum(
|
|
275
|
+
'e_GameMode',
|
|
276
|
+
[
|
|
277
|
+
(f'e_GameMode_{mode}', index)
|
|
278
|
+
for index, mode in enumerate(
|
|
279
|
+
('Normal', 'KickOff', 'GoalKick', 'FreeKick', 'Corner', 'ThrowIn', 'Penalty')
|
|
280
|
+
)
|
|
281
|
+
],
|
|
282
|
+
)
|
|
283
|
+
_ACTIONS = (
|
|
284
|
+
'idle left top_left top top_right right bottom_right bottom bottom_left long_pass high_pass '
|
|
285
|
+
'short_pass '
|
|
286
|
+
'shot keeper_rush sliding pressure team_pressure switch sprint dribble release_direction '
|
|
287
|
+
'release_long_pass release_high_pass release_short_pass release_shot release_keeper_rush '
|
|
288
|
+
'release_sliding release_pressure release_team_pressure release_switch release_sprint '
|
|
289
|
+
'release_dribble builtin_ai'
|
|
290
|
+
).split()
|
|
291
|
+
e_BackendAction = _make_enum(
|
|
292
|
+
'e_BackendAction', [(name, index) for index, name in enumerate(_ACTIONS)]
|
|
293
|
+
)
|
|
294
|
+
e_Team = _make_enum('e_Team', [('e_Left', 0), ('e_Right', 1)])
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
# Records, which hold the values that several wrappers may share. A record of a `ScenarioConfig`
|
|
298
|
+
# counts its changes in `version`, and every record inside it points at it through `root`.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
class _Root:
|
|
302
|
+
__slots__ = ('version',)
|
|
303
|
+
|
|
304
|
+
def __init__(self):
|
|
305
|
+
self.version = 0
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _touch(record):
|
|
309
|
+
if record.root is not None:
|
|
310
|
+
record.root.version += 1
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
class _VectorRecord:
|
|
314
|
+
__slots__ = ('root', 'values')
|
|
315
|
+
|
|
316
|
+
def __init__(self, values=(0.0, 0.0, 0.0), root=None):
|
|
317
|
+
self.values = list(values)
|
|
318
|
+
self.root = root
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class _EntryRecord:
|
|
322
|
+
__slots__ = ('controllable', 'lazy', 'position', 'role', 'root', 'start_position')
|
|
323
|
+
|
|
324
|
+
def copy(self, root=None):
|
|
325
|
+
record = _EntryRecord()
|
|
326
|
+
record.position = list(self.position)
|
|
327
|
+
record.start_position = list(self.start_position)
|
|
328
|
+
record.role = self.role
|
|
329
|
+
record.lazy = self.lazy
|
|
330
|
+
record.controllable = self.controllable
|
|
331
|
+
record.root = root
|
|
332
|
+
return record
|
|
333
|
+
|
|
334
|
+
def same(self, other):
|
|
335
|
+
# GRF: `FormationEntry::operator==` leaves out the start position.
|
|
336
|
+
return (
|
|
337
|
+
self.role == other.role
|
|
338
|
+
and self.lazy == other.lazy
|
|
339
|
+
and self.position == other.position
|
|
340
|
+
and self.controllable == other.controllable
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class Vector3(_Instance):
|
|
345
|
+
"""GRF's `blunted::Vector3`, three floats that `ScenarioConfig.ball_position` holds."""
|
|
346
|
+
|
|
347
|
+
def __init__(self, *arguments, **keywords):
|
|
348
|
+
x, y, z = _arguments(
|
|
349
|
+
'Vector3',
|
|
350
|
+
'__init__',
|
|
351
|
+
'__init__(_object*, float, float, float)',
|
|
352
|
+
(self, *arguments),
|
|
353
|
+
keywords,
|
|
354
|
+
[_instance(Vector3), _to_float, _to_float, _to_float],
|
|
355
|
+
)[1:]
|
|
356
|
+
self._record = _VectorRecord((x, y, z))
|
|
357
|
+
|
|
358
|
+
@classmethod
|
|
359
|
+
def _over(cls, record):
|
|
360
|
+
vector = cls.__new__(cls)
|
|
361
|
+
vector._record = record
|
|
362
|
+
return vector
|
|
363
|
+
|
|
364
|
+
def __getitem__(self, *arguments):
|
|
365
|
+
(index,) = _arguments(
|
|
366
|
+
'Vector3',
|
|
367
|
+
'__getitem__',
|
|
368
|
+
'__getitem__(blunted::Vector3 {lvalue}, int)',
|
|
369
|
+
(self, *arguments),
|
|
370
|
+
{},
|
|
371
|
+
[_instance(Vector3), _to_int],
|
|
372
|
+
)[1:]
|
|
373
|
+
if not 0 <= index <= 2:
|
|
374
|
+
# GRF logs a fatal error, which ends the process.
|
|
375
|
+
raise IndexError(f'expected a Vector3 index from 0 to 2, found {index}')
|
|
376
|
+
return self._record.values[index]
|
|
377
|
+
|
|
378
|
+
def __setitem__(self, *arguments):
|
|
379
|
+
index, value = _arguments(
|
|
380
|
+
'Vector3',
|
|
381
|
+
'__setitem__',
|
|
382
|
+
'__setitem__(blunted::Vector3 {lvalue}, int, float)',
|
|
383
|
+
(self, *arguments),
|
|
384
|
+
{},
|
|
385
|
+
[_instance(Vector3), _to_int, _to_float],
|
|
386
|
+
)[1:]
|
|
387
|
+
if not 0 <= index <= 2:
|
|
388
|
+
raise IndexError(f'expected a Vector3 index from 0 to 2, found {index}')
|
|
389
|
+
self._record.values[index] = value
|
|
390
|
+
_touch(self._record)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
class FormationEntry(_Instance):
|
|
394
|
+
"""GRF's `FormationEntry(x, y, role, lazy, controllable)`, in environment coordinates."""
|
|
395
|
+
|
|
396
|
+
def __init__(self, *arguments, **keywords):
|
|
397
|
+
x, y, role, lazy, controllable = _arguments(
|
|
398
|
+
'FormationEntry',
|
|
399
|
+
'__init__',
|
|
400
|
+
'__init__(_object*, float, float, e_PlayerRole, bool, bool)',
|
|
401
|
+
(self, *arguments),
|
|
402
|
+
keywords,
|
|
403
|
+
_ENTRY_ARGUMENTS,
|
|
404
|
+
)[1:]
|
|
405
|
+
record = _EntryRecord()
|
|
406
|
+
# GRF: `position(x, y * FORMATION_Y_SCALE, 0)`, a float product.
|
|
407
|
+
record.position = [x, _float32(y * _Y_SCALE), 0.0]
|
|
408
|
+
record.start_position = list(record.position)
|
|
409
|
+
record.role = int(role)
|
|
410
|
+
record.lazy = lazy
|
|
411
|
+
record.controllable = controllable
|
|
412
|
+
record.root = None
|
|
413
|
+
self._record = record
|
|
414
|
+
|
|
415
|
+
@classmethod
|
|
416
|
+
def _over(cls, record):
|
|
417
|
+
entry = cls.__new__(cls)
|
|
418
|
+
entry._record = record
|
|
419
|
+
return entry
|
|
420
|
+
|
|
421
|
+
@property
|
|
422
|
+
def role(self):
|
|
423
|
+
return _enum_value(e_PlayerRole, self._record.role)
|
|
424
|
+
|
|
425
|
+
role = role.setter(_no_setter('FormationEntry')).deleter(_no_deleter('FormationEntry'))
|
|
426
|
+
|
|
427
|
+
@property
|
|
428
|
+
def position(self):
|
|
429
|
+
# GRF: `position_env()`, a new vector whose writes change nothing.
|
|
430
|
+
x, y, z = self._record.position
|
|
431
|
+
return Vector3._over(_VectorRecord((x, _float32(y / _Y_SCALE), z)))
|
|
432
|
+
|
|
433
|
+
position = position.setter(_no_setter('FormationEntry')).deleter(_no_deleter('FormationEntry'))
|
|
434
|
+
|
|
435
|
+
def _get_lazy(self):
|
|
436
|
+
return self._record.lazy
|
|
437
|
+
|
|
438
|
+
def _set_lazy(self, value):
|
|
439
|
+
self._record.lazy = _setter('FormationEntry', 'bool', _to_bool)(self, value)
|
|
440
|
+
_touch(self._record)
|
|
441
|
+
|
|
442
|
+
lazy = property(_get_lazy, _set_lazy, _no_deleter('FormationEntry'))
|
|
443
|
+
|
|
444
|
+
def _get_controllable(self):
|
|
445
|
+
return self._record.controllable
|
|
446
|
+
|
|
447
|
+
def _set_controllable(self, value):
|
|
448
|
+
self._record.controllable = _setter('FormationEntry', 'bool', _to_bool)(self, value)
|
|
449
|
+
_touch(self._record)
|
|
450
|
+
|
|
451
|
+
controllable = property(_get_controllable, _set_controllable, _no_deleter('FormationEntry'))
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
_ENTRY_ARGUMENTS = [
|
|
455
|
+
_instance(FormationEntry),
|
|
456
|
+
_to_float,
|
|
457
|
+
_to_float,
|
|
458
|
+
_instance(e_PlayerRole),
|
|
459
|
+
_to_bool,
|
|
460
|
+
_to_bool,
|
|
461
|
+
]
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
# Vectors, as boost.python's `vector_indexing_suite` gives them.
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
class _ListRecord:
|
|
468
|
+
__slots__ = ('items', 'root')
|
|
469
|
+
|
|
470
|
+
def __init__(self, items=None, root=None):
|
|
471
|
+
self.items = items if items is not None else []
|
|
472
|
+
self.root = root
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
class _Vector(_Instance):
|
|
476
|
+
"""A `std::vector` of GRF, with the semantics of boost.python's `vector_indexing_suite`.
|
|
477
|
+
|
|
478
|
+
`_store` turns a Python value into a stored item or raises `_MismatchError`, `_load` turns a
|
|
479
|
+
stored item into the value that indexing returns, and `_same` is the C++ equality of two items.
|
|
480
|
+
"""
|
|
481
|
+
|
|
482
|
+
def __init__(self, *arguments, **keywords):
|
|
483
|
+
name = type(self).__name__
|
|
484
|
+
_arguments(
|
|
485
|
+
name,
|
|
486
|
+
'__init__',
|
|
487
|
+
'__init__(_object*)',
|
|
488
|
+
(self, *arguments),
|
|
489
|
+
keywords,
|
|
490
|
+
[_instance(_Vector)],
|
|
491
|
+
)
|
|
492
|
+
self._record = _ListRecord()
|
|
493
|
+
|
|
494
|
+
@classmethod
|
|
495
|
+
def _over(cls, record):
|
|
496
|
+
vector = cls.__new__(cls)
|
|
497
|
+
vector._record = record
|
|
498
|
+
return vector
|
|
499
|
+
|
|
500
|
+
def _store(self, value):
|
|
501
|
+
raise NotImplementedError
|
|
502
|
+
|
|
503
|
+
def _load(self, item):
|
|
504
|
+
return item
|
|
505
|
+
|
|
506
|
+
def _same(self, first, second):
|
|
507
|
+
return first == second
|
|
508
|
+
|
|
509
|
+
def _owned(self, item):
|
|
510
|
+
return item
|
|
511
|
+
|
|
512
|
+
def _index(self, index):
|
|
513
|
+
items = self._record.items
|
|
514
|
+
if isinstance(index, slice):
|
|
515
|
+
if index.step is not None:
|
|
516
|
+
raise IndexError('slice step size not supported.')
|
|
517
|
+
return index
|
|
518
|
+
if not isinstance(index, int):
|
|
519
|
+
raise TypeError('Invalid index type')
|
|
520
|
+
if index < 0:
|
|
521
|
+
index += len(items)
|
|
522
|
+
if not 0 <= index < len(items):
|
|
523
|
+
raise IndexError('Index out of range')
|
|
524
|
+
return index
|
|
525
|
+
|
|
526
|
+
def __len__(self):
|
|
527
|
+
return len(self._record.items)
|
|
528
|
+
|
|
529
|
+
def __getitem__(self, index):
|
|
530
|
+
position = self._index(index)
|
|
531
|
+
items = self._record.items
|
|
532
|
+
if isinstance(position, slice):
|
|
533
|
+
return type(self)._over(_ListRecord([self._copy(item) for item in items[position]]))
|
|
534
|
+
return self._load(items[position])
|
|
535
|
+
|
|
536
|
+
def _copy(self, item):
|
|
537
|
+
return item.copy() if hasattr(item, 'copy') else item
|
|
538
|
+
|
|
539
|
+
def __setitem__(self, index, value):
|
|
540
|
+
position = self._index(index)
|
|
541
|
+
items = self._record.items
|
|
542
|
+
try:
|
|
543
|
+
if isinstance(position, slice):
|
|
544
|
+
stored = [self._adopt(self._store(element)) for element in value]
|
|
545
|
+
else:
|
|
546
|
+
stored = self._adopt(self._store(value))
|
|
547
|
+
except _MismatchError:
|
|
548
|
+
raise TypeError('Invalid assignment') from None
|
|
549
|
+
items[position] = stored
|
|
550
|
+
_touch(self._record)
|
|
551
|
+
|
|
552
|
+
def __delitem__(self, index):
|
|
553
|
+
position = self._index(index)
|
|
554
|
+
del self._record.items[position]
|
|
555
|
+
_touch(self._record)
|
|
556
|
+
|
|
557
|
+
def __iter__(self):
|
|
558
|
+
for item in list(self._record.items):
|
|
559
|
+
yield self._load(item)
|
|
560
|
+
|
|
561
|
+
def __contains__(self, value):
|
|
562
|
+
try:
|
|
563
|
+
stored = self._store(value)
|
|
564
|
+
except _MismatchError:
|
|
565
|
+
return False
|
|
566
|
+
return any(self._same(item, stored) for item in self._record.items)
|
|
567
|
+
|
|
568
|
+
def _adopt(self, item):
|
|
569
|
+
if hasattr(item, 'root'):
|
|
570
|
+
item.root = self._record.root
|
|
571
|
+
return item
|
|
572
|
+
|
|
573
|
+
def append(self, *arguments):
|
|
574
|
+
if len(arguments) != 1:
|
|
575
|
+
raise _signature_error(type(self).__name__, 'append', (self, *arguments), 'append')
|
|
576
|
+
try:
|
|
577
|
+
stored = self._adopt(self._store(arguments[0]))
|
|
578
|
+
except _MismatchError:
|
|
579
|
+
raise TypeError('Attempting to append an invalid type') from None
|
|
580
|
+
self._record.items.append(stored)
|
|
581
|
+
_touch(self._record)
|
|
582
|
+
|
|
583
|
+
def extend(self, *arguments):
|
|
584
|
+
if len(arguments) != 1:
|
|
585
|
+
raise _signature_error(type(self).__name__, 'extend', (self, *arguments), 'extend')
|
|
586
|
+
try:
|
|
587
|
+
stored = [self._adopt(self._store(element)) for element in arguments[0]]
|
|
588
|
+
except _MismatchError:
|
|
589
|
+
raise TypeError('Incompatible Data Type') from None
|
|
590
|
+
self._record.items.extend(stored)
|
|
591
|
+
_touch(self._record)
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
class FloatVec(_Vector):
|
|
595
|
+
"""GRF's `std::vector<float>`."""
|
|
596
|
+
|
|
597
|
+
__slots__ = ()
|
|
598
|
+
|
|
599
|
+
def _store(self, value):
|
|
600
|
+
return _to_float(value)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
class IntVec(_Vector):
|
|
604
|
+
"""GRF's `std::vector<int>`."""
|
|
605
|
+
|
|
606
|
+
__slots__ = ()
|
|
607
|
+
|
|
608
|
+
def _store(self, value):
|
|
609
|
+
return _to_int(value)
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
class StringVector(_Vector):
|
|
613
|
+
"""GRF's `std::vector<std::string>`."""
|
|
614
|
+
|
|
615
|
+
__slots__ = ()
|
|
616
|
+
|
|
617
|
+
def _store(self, value):
|
|
618
|
+
return _to_string(value).decode('utf-8', 'surrogateescape')
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
class FormationEntryVec(_Vector):
|
|
622
|
+
"""GRF's `std::vector<FormationEntry>`, whose items stay shared with the vector."""
|
|
623
|
+
|
|
624
|
+
__slots__ = ()
|
|
625
|
+
|
|
626
|
+
def _store(self, value):
|
|
627
|
+
if not isinstance(value, FormationEntry):
|
|
628
|
+
raise _MismatchError
|
|
629
|
+
return value._record.copy()
|
|
630
|
+
|
|
631
|
+
def _load(self, item):
|
|
632
|
+
return FormationEntry._over(item)
|
|
633
|
+
|
|
634
|
+
def _same(self, first, second):
|
|
635
|
+
return first.same(second)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
class Position(_Instance):
|
|
639
|
+
"""GRF's `Position`, a raw vector of the engine that indexes in environment coordinates."""
|
|
640
|
+
|
|
641
|
+
def __init__(self, *arguments, **keywords):
|
|
642
|
+
_arguments(
|
|
643
|
+
'Position',
|
|
644
|
+
'__init__',
|
|
645
|
+
'__init__(_object*)',
|
|
646
|
+
(self, *arguments),
|
|
647
|
+
keywords,
|
|
648
|
+
[_instance(Position)],
|
|
649
|
+
)
|
|
650
|
+
self._values = (0.0, 0.0, 0.0)
|
|
651
|
+
|
|
652
|
+
@classmethod
|
|
653
|
+
def _of(cls, values):
|
|
654
|
+
position = cls.__new__(cls)
|
|
655
|
+
position._values = tuple(values)
|
|
656
|
+
return position
|
|
657
|
+
|
|
658
|
+
def __getitem__(self, *arguments):
|
|
659
|
+
(index,) = _arguments(
|
|
660
|
+
'Position',
|
|
661
|
+
'__getitem__',
|
|
662
|
+
'__getitem__(Position {lvalue}, int)',
|
|
663
|
+
(self, *arguments),
|
|
664
|
+
{},
|
|
665
|
+
[_instance(Position), _to_int],
|
|
666
|
+
)[1:]
|
|
667
|
+
# GRF: `X_FIELD_SCALE` and `Y_FIELD_SCALE` are doubles, and z divides by the integer 1.
|
|
668
|
+
if index == 0:
|
|
669
|
+
return _float32(self._values[0] / 54.4)
|
|
670
|
+
if index == 1:
|
|
671
|
+
return _float32(self._values[1] / -83.6)
|
|
672
|
+
if index == 2:
|
|
673
|
+
return self._values[2]
|
|
674
|
+
raise IndexError(f'expected a Position index from 0 to 2, found {index}')
|
|
675
|
+
|
|
676
|
+
def __str__(self):
|
|
677
|
+
x, y, z = self._values
|
|
678
|
+
return f'{x:f},{y:f},{z:f}'
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
class PlayerInfo(_Instance):
|
|
682
|
+
"""GRF's `PlayerInfo`, one player of `SharedInfo`."""
|
|
683
|
+
|
|
684
|
+
def __init__(self, *arguments, **keywords):
|
|
685
|
+
_arguments(
|
|
686
|
+
'PlayerInfo',
|
|
687
|
+
'__init__',
|
|
688
|
+
'__init__(_object*)',
|
|
689
|
+
(self, *arguments),
|
|
690
|
+
keywords,
|
|
691
|
+
[_instance(PlayerInfo)],
|
|
692
|
+
)
|
|
693
|
+
self._values = ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0), 0.0, False, True, False, 0)
|
|
694
|
+
|
|
695
|
+
@classmethod
|
|
696
|
+
def _of(cls, values):
|
|
697
|
+
info = cls.__new__(cls)
|
|
698
|
+
info._values = values
|
|
699
|
+
return info
|
|
700
|
+
|
|
701
|
+
def _field(index, convert=None):
|
|
702
|
+
def get(self):
|
|
703
|
+
value = self._values[index]
|
|
704
|
+
return convert(value) if convert else value
|
|
705
|
+
|
|
706
|
+
return property(get, _no_setter('PlayerInfo'), _no_deleter('PlayerInfo'))
|
|
707
|
+
|
|
708
|
+
position = _field(0, Position._of)
|
|
709
|
+
direction = _field(1, Position._of)
|
|
710
|
+
tired_factor = _field(2)
|
|
711
|
+
has_card = _field(3)
|
|
712
|
+
is_active = _field(4)
|
|
713
|
+
designated_player = _field(5)
|
|
714
|
+
role = _field(6, lambda value: _enum_value(e_PlayerRole, value))
|
|
715
|
+
del _field
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
class PlayerInfoVec(_Vector):
|
|
719
|
+
"""GRF's `std::vector<PlayerInfo>`."""
|
|
720
|
+
|
|
721
|
+
__slots__ = ()
|
|
722
|
+
|
|
723
|
+
def _store(self, value):
|
|
724
|
+
if not isinstance(value, PlayerInfo):
|
|
725
|
+
raise _MismatchError
|
|
726
|
+
return value._values
|
|
727
|
+
|
|
728
|
+
def _load(self, item):
|
|
729
|
+
return PlayerInfo._of(item)
|
|
730
|
+
|
|
731
|
+
def _same(self, first, second):
|
|
732
|
+
return first == second
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
class ControllerInfo(_Instance):
|
|
736
|
+
"""GRF's `ControllerInfo(controlled_player)`."""
|
|
737
|
+
|
|
738
|
+
def __init__(self, *arguments, **keywords):
|
|
739
|
+
(player,) = _arguments(
|
|
740
|
+
'ControllerInfo',
|
|
741
|
+
'__init__',
|
|
742
|
+
'__init__(_object*, int)',
|
|
743
|
+
(self, *arguments),
|
|
744
|
+
keywords,
|
|
745
|
+
[_instance(ControllerInfo), _to_int],
|
|
746
|
+
)[1:]
|
|
747
|
+
self._player = player
|
|
748
|
+
|
|
749
|
+
@classmethod
|
|
750
|
+
def _of(cls, player):
|
|
751
|
+
info = cls.__new__(cls)
|
|
752
|
+
info._player = player
|
|
753
|
+
return info
|
|
754
|
+
|
|
755
|
+
controlled_player = property(
|
|
756
|
+
lambda self: self._player, _no_setter('ControllerInfo'), _no_deleter('ControllerInfo')
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
class ControllerInfoVec(_Vector):
|
|
761
|
+
"""GRF's `std::vector<ControllerInfo>`."""
|
|
762
|
+
|
|
763
|
+
__slots__ = ()
|
|
764
|
+
|
|
765
|
+
def _store(self, value):
|
|
766
|
+
if not isinstance(value, ControllerInfo):
|
|
767
|
+
raise _MismatchError
|
|
768
|
+
return value._player
|
|
769
|
+
|
|
770
|
+
def _load(self, item):
|
|
771
|
+
return ControllerInfo._of(item)
|
|
772
|
+
|
|
773
|
+
def _same(self, first, second):
|
|
774
|
+
return False
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
class SharedInfo(_Instance):
|
|
778
|
+
"""GRF's `SharedInfo`, what `GameEnv.get_info` returns."""
|
|
779
|
+
|
|
780
|
+
def __init__(self, *arguments, **keywords):
|
|
781
|
+
_arguments(
|
|
782
|
+
'SharedInfo',
|
|
783
|
+
'__init__',
|
|
784
|
+
'__init__(_object*)',
|
|
785
|
+
(self, *arguments),
|
|
786
|
+
keywords,
|
|
787
|
+
[_instance(SharedInfo)],
|
|
788
|
+
)
|
|
789
|
+
self._info = None
|
|
790
|
+
|
|
791
|
+
@classmethod
|
|
792
|
+
def _of(cls, info):
|
|
793
|
+
shared = cls.__new__(cls)
|
|
794
|
+
shared._info = info
|
|
795
|
+
return shared
|
|
796
|
+
|
|
797
|
+
def _read(name, convert, default):
|
|
798
|
+
def get(self):
|
|
799
|
+
if self._info is None:
|
|
800
|
+
return default()
|
|
801
|
+
return convert(self, name)
|
|
802
|
+
|
|
803
|
+
return property(get, _no_setter('SharedInfo'), _no_deleter('SharedInfo'))
|
|
804
|
+
|
|
805
|
+
def _team(self, name):
|
|
806
|
+
cache = self.__dict__.setdefault('_teams', {})
|
|
807
|
+
if name in cache:
|
|
808
|
+
return PlayerInfoVec._over(cache[name])
|
|
809
|
+
info = self._info
|
|
810
|
+
players = getattr(info, name)
|
|
811
|
+
count = info.left_size if name == 'left_team' else info.right_size
|
|
812
|
+
items = []
|
|
813
|
+
for index in range(count):
|
|
814
|
+
player = players[index]
|
|
815
|
+
items.append(
|
|
816
|
+
(
|
|
817
|
+
tuple(player.position),
|
|
818
|
+
tuple(player.direction),
|
|
819
|
+
player.tired_factor,
|
|
820
|
+
bool(player.has_card),
|
|
821
|
+
bool(player.is_active),
|
|
822
|
+
bool(player.designated_player),
|
|
823
|
+
player.role,
|
|
824
|
+
)
|
|
825
|
+
)
|
|
826
|
+
cache[name] = _ListRecord(items)
|
|
827
|
+
return PlayerInfoVec._over(cache[name])
|
|
828
|
+
|
|
829
|
+
def _controllers(self, name):
|
|
830
|
+
info = self._info
|
|
831
|
+
# GRF: `Match::GetState` sizes the controllers to the team of the scenario.
|
|
832
|
+
count = info.left_size if name == 'left_controllers' else info.right_size
|
|
833
|
+
values = getattr(info, name)
|
|
834
|
+
return ControllerInfoVec._over(_ListRecord([values[index] for index in range(count)]))
|
|
835
|
+
|
|
836
|
+
def _plain(self, name):
|
|
837
|
+
return getattr(self._info, name)
|
|
838
|
+
|
|
839
|
+
def _flag(self, name):
|
|
840
|
+
return bool(getattr(self._info, name))
|
|
841
|
+
|
|
842
|
+
ball_position = _read(
|
|
843
|
+
'ball_position',
|
|
844
|
+
lambda i, n: Position._of(i._info.ball_position),
|
|
845
|
+
lambda: Position._of((0,) * 3),
|
|
846
|
+
)
|
|
847
|
+
ball_rotation = _read(
|
|
848
|
+
'ball_rotation',
|
|
849
|
+
lambda i, n: Position._of(i._info.ball_rotation),
|
|
850
|
+
lambda: Position._of((0,) * 3),
|
|
851
|
+
)
|
|
852
|
+
ball_direction = _read(
|
|
853
|
+
'ball_direction',
|
|
854
|
+
lambda i, n: Position._of(i._info.ball_direction),
|
|
855
|
+
lambda: Position._of((0,) * 3),
|
|
856
|
+
)
|
|
857
|
+
left_team = _read('left_team', _team, lambda: PlayerInfoVec._over(_ListRecord()))
|
|
858
|
+
right_team = _read('right_team', _team, lambda: PlayerInfoVec._over(_ListRecord()))
|
|
859
|
+
left_goals = _read('left_goals', _plain, lambda: 0)
|
|
860
|
+
right_goals = _read('right_goals', _plain, lambda: 0)
|
|
861
|
+
is_in_play = _read('is_in_play', _flag, lambda: False)
|
|
862
|
+
ball_owned_team = _read('ball_owned_team', _plain, lambda: 0)
|
|
863
|
+
ball_owned_player = _read('ball_owned_player', _plain, lambda: 0)
|
|
864
|
+
left_controllers = _read(
|
|
865
|
+
'left_controllers', _controllers, lambda: ControllerInfoVec._over(_ListRecord())
|
|
866
|
+
)
|
|
867
|
+
right_controllers = _read(
|
|
868
|
+
'right_controllers', _controllers, lambda: ControllerInfoVec._over(_ListRecord())
|
|
869
|
+
)
|
|
870
|
+
game_mode = _read(
|
|
871
|
+
'game_mode',
|
|
872
|
+
lambda i, n: _enum_value(e_GameMode, i._info.game_mode),
|
|
873
|
+
lambda: e_GameMode.e_GameMode_Normal,
|
|
874
|
+
)
|
|
875
|
+
step = _read('step', _plain, lambda: 0)
|
|
876
|
+
del _read, _team, _controllers, _plain, _flag
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
# The configurations.
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
class _ScenarioRecord(_Root):
|
|
883
|
+
__slots__ = (
|
|
884
|
+
'ball',
|
|
885
|
+
'cache',
|
|
886
|
+
'control_all_players',
|
|
887
|
+
'deterministic',
|
|
888
|
+
'end_episode_on_out_of_play',
|
|
889
|
+
'end_episode_on_possession_change',
|
|
890
|
+
'end_episode_on_score',
|
|
891
|
+
'game_duration',
|
|
892
|
+
'game_engine_random_seed',
|
|
893
|
+
'left_agents',
|
|
894
|
+
'left_team',
|
|
895
|
+
'left_team_difficulty',
|
|
896
|
+
'offsides',
|
|
897
|
+
'real_time',
|
|
898
|
+
'reverse_team_processing',
|
|
899
|
+
'right_agents',
|
|
900
|
+
'right_team',
|
|
901
|
+
'right_team_difficulty',
|
|
902
|
+
'second_half',
|
|
903
|
+
'use_magnet',
|
|
904
|
+
)
|
|
905
|
+
|
|
906
|
+
def __init__(self):
|
|
907
|
+
super().__init__()
|
|
908
|
+
self.ball = _VectorRecord(root=self)
|
|
909
|
+
self.left_team = _ListRecord(root=self)
|
|
910
|
+
self.right_team = _ListRecord(root=self)
|
|
911
|
+
self.left_agents = 1
|
|
912
|
+
self.right_agents = 0
|
|
913
|
+
self.use_magnet = True
|
|
914
|
+
self.offsides = True
|
|
915
|
+
self.real_time = False
|
|
916
|
+
self.game_engine_random_seed = 42
|
|
917
|
+
self.reverse_team_processing = False
|
|
918
|
+
self.left_team_difficulty = 1.0
|
|
919
|
+
self.right_team_difficulty = _float32(0.6)
|
|
920
|
+
self.deterministic = False
|
|
921
|
+
self.end_episode_on_score = False
|
|
922
|
+
self.end_episode_on_possession_change = False
|
|
923
|
+
self.end_episode_on_out_of_play = False
|
|
924
|
+
self.game_duration = 3000
|
|
925
|
+
self.control_all_players = False
|
|
926
|
+
self.second_half = 999999999
|
|
927
|
+
# GRF's cache: computed, the dynamic player selection and the controllable counts.
|
|
928
|
+
self.cache = [False, False, -1, -1]
|
|
929
|
+
|
|
930
|
+
def assign(self, other):
|
|
931
|
+
"""Copies `other` in, as GRF's `ScenarioConfig` assignment does, the cache included."""
|
|
932
|
+
for name in _SCENARIO_FIELDS:
|
|
933
|
+
setattr(self, name, getattr(other, name))
|
|
934
|
+
self.ball.values = list(other.ball.values)
|
|
935
|
+
self.left_team.items = [item.copy(self) for item in other.left_team.items]
|
|
936
|
+
self.right_team.items = [item.copy(self) for item in other.right_team.items]
|
|
937
|
+
self.cache = list(other.cache)
|
|
938
|
+
self.version += 1
|
|
939
|
+
|
|
940
|
+
def compute_cache(self):
|
|
941
|
+
"""GRF: `ScenarioConfig::ComputeCache`."""
|
|
942
|
+
if self.cache[0]:
|
|
943
|
+
return
|
|
944
|
+
left = sum(1 for item in self.left_team.items if item.controllable)
|
|
945
|
+
right = sum(1 for item in self.right_team.items if item.controllable)
|
|
946
|
+
dynamic = not (
|
|
947
|
+
(left == self.left_agents or self.left_agents == 0)
|
|
948
|
+
and (right == self.right_agents or self.right_agents == 0)
|
|
949
|
+
)
|
|
950
|
+
self.cache = [True, dynamic, left, right]
|
|
951
|
+
self.version += 1
|
|
952
|
+
|
|
953
|
+
def to_native(self):
|
|
954
|
+
"""Returns `cuju_engine_scenario` of the record and the entry arrays it points at."""
|
|
955
|
+
teams = []
|
|
956
|
+
for team in (self.left_team.items, self.right_team.items):
|
|
957
|
+
if len(team) > _native.TEAM_PLAYERS:
|
|
958
|
+
raise ScenarioError(
|
|
959
|
+
f'a team holds {len(team)} formation entries, more than the 11 players that '
|
|
960
|
+
'GRF plays, where GRF crashes'
|
|
961
|
+
)
|
|
962
|
+
entries = (_native.Entry * max(1, len(team)))()
|
|
963
|
+
for index, item in enumerate(team):
|
|
964
|
+
entry = entries[index]
|
|
965
|
+
entry.position[:] = item.position
|
|
966
|
+
entry.start_position[:] = item.start_position
|
|
967
|
+
entry.role = item.role
|
|
968
|
+
entry.lazy = item.lazy
|
|
969
|
+
entry.controllable = item.controllable
|
|
970
|
+
teams.append(entries)
|
|
971
|
+
scenario = _native.Scenario()
|
|
972
|
+
scenario.version = _native.VERSION
|
|
973
|
+
scenario.ball_position[:] = self.ball.values
|
|
974
|
+
scenario.left_team = ctypes.cast(teams[0], ctypes.POINTER(_native.Entry))
|
|
975
|
+
scenario.left_size = len(self.left_team.items)
|
|
976
|
+
scenario.right_team = ctypes.cast(teams[1], ctypes.POINTER(_native.Entry))
|
|
977
|
+
scenario.right_size = len(self.right_team.items)
|
|
978
|
+
for name in _SCENARIO_FIELDS:
|
|
979
|
+
setattr(scenario, name, getattr(self, name))
|
|
980
|
+
(
|
|
981
|
+
scenario.cache_computed,
|
|
982
|
+
scenario.cache_dynamic_player_selection,
|
|
983
|
+
scenario.cache_controllable_left,
|
|
984
|
+
scenario.cache_controllable_right,
|
|
985
|
+
) = self.cache
|
|
986
|
+
return scenario, teams
|
|
987
|
+
|
|
988
|
+
def from_native(self, scenario):
|
|
989
|
+
"""Copies `cuju_engine_scenario` in, its entries included."""
|
|
990
|
+
for name in _SCENARIO_FIELDS:
|
|
991
|
+
value = getattr(scenario, name)
|
|
992
|
+
if isinstance(getattr(self, name), bool):
|
|
993
|
+
value = bool(value)
|
|
994
|
+
setattr(self, name, value)
|
|
995
|
+
self.ball.values = list(scenario.ball_position)
|
|
996
|
+
for team, entries, size in (
|
|
997
|
+
(self.left_team, scenario.left_team, scenario.left_size),
|
|
998
|
+
(self.right_team, scenario.right_team, scenario.right_size),
|
|
999
|
+
):
|
|
1000
|
+
items = []
|
|
1001
|
+
for index in range(size):
|
|
1002
|
+
entry = entries[index]
|
|
1003
|
+
item = _EntryRecord()
|
|
1004
|
+
item.position = list(entry.position)
|
|
1005
|
+
item.start_position = list(entry.start_position)
|
|
1006
|
+
item.role = entry.role
|
|
1007
|
+
item.lazy = bool(entry.lazy)
|
|
1008
|
+
item.controllable = bool(entry.controllable)
|
|
1009
|
+
item.root = self
|
|
1010
|
+
items.append(item)
|
|
1011
|
+
team.items = items
|
|
1012
|
+
self.cache = [
|
|
1013
|
+
bool(scenario.cache_computed),
|
|
1014
|
+
bool(scenario.cache_dynamic_player_selection),
|
|
1015
|
+
scenario.cache_controllable_left,
|
|
1016
|
+
scenario.cache_controllable_right,
|
|
1017
|
+
]
|
|
1018
|
+
self.version += 1
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
# Each field of `ScenarioConfig` with its C++ type and its conversion.
|
|
1022
|
+
_SCENARIO_TYPES = {
|
|
1023
|
+
'left_agents': ('int', _to_int),
|
|
1024
|
+
'right_agents': ('int', _to_int),
|
|
1025
|
+
'use_magnet': ('bool', _to_bool),
|
|
1026
|
+
'offsides': ('bool', _to_bool),
|
|
1027
|
+
'real_time': ('bool', _to_bool),
|
|
1028
|
+
'game_engine_random_seed': ('unsigned int', _to_unsigned),
|
|
1029
|
+
'reverse_team_processing': ('bool', _to_bool),
|
|
1030
|
+
'left_team_difficulty': ('float', _to_float),
|
|
1031
|
+
'right_team_difficulty': ('float', _to_float),
|
|
1032
|
+
'deterministic': ('bool', _to_bool),
|
|
1033
|
+
'end_episode_on_score': ('bool', _to_bool),
|
|
1034
|
+
'end_episode_on_possession_change': ('bool', _to_bool),
|
|
1035
|
+
'end_episode_on_out_of_play': ('bool', _to_bool),
|
|
1036
|
+
'game_duration': ('int', _to_int),
|
|
1037
|
+
'second_half': ('int', _to_int),
|
|
1038
|
+
'control_all_players': ('bool', _to_bool),
|
|
1039
|
+
}
|
|
1040
|
+
_SCENARIO_FIELDS = tuple(_SCENARIO_TYPES)
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
def _scenario_field(name, cpp_type, convert):
|
|
1044
|
+
check = _setter('ScenarioConfig', cpp_type, convert)
|
|
1045
|
+
|
|
1046
|
+
def get(self):
|
|
1047
|
+
return getattr(self._record, name)
|
|
1048
|
+
|
|
1049
|
+
def set_(self, value):
|
|
1050
|
+
setattr(self._record, name, check(self, value))
|
|
1051
|
+
self._record.version += 1
|
|
1052
|
+
|
|
1053
|
+
return property(get, set_, _no_deleter('ScenarioConfig'))
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
def _cached(index):
|
|
1057
|
+
def get(self):
|
|
1058
|
+
self._record.compute_cache()
|
|
1059
|
+
return self._record.cache[index]
|
|
1060
|
+
|
|
1061
|
+
return property(get, _no_setter('ScenarioConfig'), _no_deleter('ScenarioConfig'))
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
class ScenarioConfig(_Instance):
|
|
1065
|
+
"""GRF's `ScenarioConfig`, which `ScenarioConfig.make()` creates."""
|
|
1066
|
+
|
|
1067
|
+
def __init__(self, *arguments, **keywords):
|
|
1068
|
+
raise RuntimeError('This class cannot be instantiated from Python')
|
|
1069
|
+
|
|
1070
|
+
@staticmethod
|
|
1071
|
+
def make(*arguments, **keywords):
|
|
1072
|
+
_arguments(
|
|
1073
|
+
'ScenarioConfig',
|
|
1074
|
+
'make',
|
|
1075
|
+
'make()',
|
|
1076
|
+
arguments,
|
|
1077
|
+
keywords,
|
|
1078
|
+
[],
|
|
1079
|
+
)
|
|
1080
|
+
return ScenarioConfig._over(_ScenarioRecord())
|
|
1081
|
+
|
|
1082
|
+
@classmethod
|
|
1083
|
+
def _over(cls, record):
|
|
1084
|
+
config = cls.__new__(cls)
|
|
1085
|
+
config._record = record
|
|
1086
|
+
return config
|
|
1087
|
+
|
|
1088
|
+
def _get_ball(self):
|
|
1089
|
+
return Vector3._over(self._record.ball)
|
|
1090
|
+
|
|
1091
|
+
def _set_ball(self, value):
|
|
1092
|
+
_setter('ScenarioConfig', 'blunted::Vector3', _instance(Vector3))(self, value)
|
|
1093
|
+
self._record.ball.values = list(value._record.values)
|
|
1094
|
+
self._record.version += 1
|
|
1095
|
+
|
|
1096
|
+
ball_position = property(_get_ball, _set_ball, _no_deleter('ScenarioConfig'))
|
|
1097
|
+
|
|
1098
|
+
def _team_property(name):
|
|
1099
|
+
def get(self):
|
|
1100
|
+
return FormationEntryVec._over(getattr(self._record, name))
|
|
1101
|
+
|
|
1102
|
+
def set_(self, value):
|
|
1103
|
+
_setter(
|
|
1104
|
+
'ScenarioConfig',
|
|
1105
|
+
'std::vector<FormationEntry, std::allocator<FormationEntry> >',
|
|
1106
|
+
_instance(FormationEntryVec),
|
|
1107
|
+
)(self, value)
|
|
1108
|
+
record = self._record
|
|
1109
|
+
getattr(record, name).items = [item.copy(record) for item in value._record.items]
|
|
1110
|
+
record.version += 1
|
|
1111
|
+
|
|
1112
|
+
return property(get, set_, _no_deleter('ScenarioConfig'))
|
|
1113
|
+
|
|
1114
|
+
left_team = _team_property('left_team')
|
|
1115
|
+
right_team = _team_property('right_team')
|
|
1116
|
+
del _team_property
|
|
1117
|
+
|
|
1118
|
+
dynamic_player_selection = _cached(1)
|
|
1119
|
+
controllable_left_players = _cached(2)
|
|
1120
|
+
controllable_right_players = _cached(3)
|
|
1121
|
+
|
|
1122
|
+
for _name, (_cpp, _convert) in _SCENARIO_TYPES.items():
|
|
1123
|
+
locals()[_name] = _scenario_field(_name, _cpp, _convert)
|
|
1124
|
+
del _name, _cpp, _convert
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
class _GameRecord:
|
|
1128
|
+
__slots__ = ('physics_steps_per_frame', 'render', 'render_resolution_x', 'render_resolution_y')
|
|
1129
|
+
|
|
1130
|
+
def __init__(self):
|
|
1131
|
+
self.render = False
|
|
1132
|
+
self.physics_steps_per_frame = 10
|
|
1133
|
+
self.render_resolution_x = 1280
|
|
1134
|
+
self.render_resolution_y = 720
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
def _game_field(name, cpp_type, convert):
|
|
1138
|
+
check = _setter('GameConfig', cpp_type, convert)
|
|
1139
|
+
|
|
1140
|
+
def get(self):
|
|
1141
|
+
return getattr(self._record, name)
|
|
1142
|
+
|
|
1143
|
+
def set_(self, value):
|
|
1144
|
+
setattr(self._record, name, check(self, value))
|
|
1145
|
+
|
|
1146
|
+
return property(get, set_, _no_deleter('GameConfig'))
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
class GameConfig(_Instance):
|
|
1150
|
+
"""GRF's `GameConfig`, which `GameConfig.make()` creates."""
|
|
1151
|
+
|
|
1152
|
+
def __init__(self, *arguments, **keywords):
|
|
1153
|
+
raise RuntimeError('This class cannot be instantiated from Python')
|
|
1154
|
+
|
|
1155
|
+
@staticmethod
|
|
1156
|
+
def make(*arguments, **keywords):
|
|
1157
|
+
_arguments('GameConfig', 'make', 'make()', arguments, keywords, [])
|
|
1158
|
+
return GameConfig._over(_GameRecord())
|
|
1159
|
+
|
|
1160
|
+
@classmethod
|
|
1161
|
+
def _over(cls, record):
|
|
1162
|
+
config = cls.__new__(cls)
|
|
1163
|
+
config._record = record
|
|
1164
|
+
return config
|
|
1165
|
+
|
|
1166
|
+
render = _game_field('render', 'bool', _to_bool)
|
|
1167
|
+
physics_steps_per_frame = _game_field('physics_steps_per_frame', 'int', _to_int)
|
|
1168
|
+
render_resolution_x = _game_field('render_resolution_x', 'int', _to_int)
|
|
1169
|
+
render_resolution_y = _game_field('render_resolution_y', 'int', _to_int)
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
# GRF's tracker, which plays two engines of a process in lockstep and compares their states.
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
class _Tracker:
|
|
1176
|
+
def __init__(self):
|
|
1177
|
+
self.condition = threading.Condition()
|
|
1178
|
+
self.start = 0
|
|
1179
|
+
self.end = 1000000000
|
|
1180
|
+
self.waiting = None
|
|
1181
|
+
# The failure of the comparison that the waiting engine takes up when it wakes.
|
|
1182
|
+
self.failure = None
|
|
1183
|
+
|
|
1184
|
+
def setup(self, env, start, end):
|
|
1185
|
+
self.start = start
|
|
1186
|
+
self.end = end
|
|
1187
|
+
env._tracker_disabled = 0
|
|
1188
|
+
env._tracker_position = 0
|
|
1189
|
+
|
|
1190
|
+
def verify(self, env):
|
|
1191
|
+
if env._tracker_disabled:
|
|
1192
|
+
return
|
|
1193
|
+
env._tracker_position += 1
|
|
1194
|
+
position = env._tracker_position
|
|
1195
|
+
if position < self.start or position > self.end:
|
|
1196
|
+
return
|
|
1197
|
+
with self.condition:
|
|
1198
|
+
if self.waiting is None:
|
|
1199
|
+
if position % 10000 == 0:
|
|
1200
|
+
print(f'Validating: {position}', flush=True)
|
|
1201
|
+
self.waiting = env
|
|
1202
|
+
self.failure = None
|
|
1203
|
+
# GRF: a wait without a predicate, which the engine that verifies ends.
|
|
1204
|
+
self.condition.wait()
|
|
1205
|
+
if self.failure is not None and self.failure[0] is env:
|
|
1206
|
+
failure = self.failure[1]
|
|
1207
|
+
self.failure = None
|
|
1208
|
+
raise failure
|
|
1209
|
+
return
|
|
1210
|
+
env._tracker_disabled += 1
|
|
1211
|
+
waiting = self.waiting
|
|
1212
|
+
try:
|
|
1213
|
+
failure = self._snapshot(env, waiting, position)
|
|
1214
|
+
except BaseException as error:
|
|
1215
|
+
failure = error
|
|
1216
|
+
finally:
|
|
1217
|
+
env._tracker_disabled -= 1
|
|
1218
|
+
self.waiting = None
|
|
1219
|
+
if failure is not None:
|
|
1220
|
+
self.failure = (waiting, failure)
|
|
1221
|
+
self.condition.notify()
|
|
1222
|
+
if failure is not None:
|
|
1223
|
+
raise failure
|
|
1224
|
+
|
|
1225
|
+
def _snapshot(self, env, waiting, position):
|
|
1226
|
+
waiting_position = waiting._tracker_position
|
|
1227
|
+
detail = ''
|
|
1228
|
+
failed = position != waiting_position
|
|
1229
|
+
if not failed:
|
|
1230
|
+
env._push()
|
|
1231
|
+
offset = ctypes.c_longlong(-1)
|
|
1232
|
+
status = _native.library().cuju_engine_verify(
|
|
1233
|
+
env._engine, waiting._engine, ctypes.byref(offset)
|
|
1234
|
+
)
|
|
1235
|
+
env._raise(status if status < 0 else 0)
|
|
1236
|
+
env._pull_cache()
|
|
1237
|
+
failed = status == 1
|
|
1238
|
+
detail = f'\nState position: {offset.value}'
|
|
1239
|
+
if not failed:
|
|
1240
|
+
return None
|
|
1241
|
+
return _errors.TrackerError(
|
|
1242
|
+
f'Validation range: {self.start} - {self.end}\n'
|
|
1243
|
+
f'Position: {position} vs {waiting_position}{detail}\n'
|
|
1244
|
+
'State comparison failure, where GRF ends the process'
|
|
1245
|
+
)
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
_TRACKER = _Tracker()
|
|
1249
|
+
|
|
1250
|
+
# The engines of finalized `GameEnv`s, each with a weak reference to its `GameEnv`, which a
|
|
1251
|
+
# resurrected one keeps alive.
|
|
1252
|
+
_RELEASED = []
|
|
1253
|
+
_RELEASED_LOCK = threading.Lock()
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
def _free_released():
|
|
1257
|
+
"""Frees the engines of every finalized `GameEnv` that no object refers to any more."""
|
|
1258
|
+
with _RELEASED_LOCK:
|
|
1259
|
+
kept = []
|
|
1260
|
+
for reference, engine in _RELEASED:
|
|
1261
|
+
if reference() is None:
|
|
1262
|
+
_native.library().cuju_engine_destroy(engine)
|
|
1263
|
+
else:
|
|
1264
|
+
kept.append((reference, engine))
|
|
1265
|
+
_RELEASED[:] = kept
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
class GameEnv(_Instance):
|
|
1269
|
+
"""GRF's `GameEnv`, one engine, on cuju's simulation."""
|
|
1270
|
+
|
|
1271
|
+
def __init__(self, *arguments, **keywords):
|
|
1272
|
+
_arguments(
|
|
1273
|
+
'GameEnv',
|
|
1274
|
+
'__init__',
|
|
1275
|
+
'__init__(_object*)',
|
|
1276
|
+
(self, *arguments),
|
|
1277
|
+
keywords,
|
|
1278
|
+
[_instance(GameEnv)],
|
|
1279
|
+
)
|
|
1280
|
+
from .._batch.assets import _DATA_DIRECTORY
|
|
1281
|
+
|
|
1282
|
+
library = _native.library()
|
|
1283
|
+
_free_released()
|
|
1284
|
+
path = os.path.join(_DATA_DIRECTORY, 'animations.bin')
|
|
1285
|
+
self._engine = library.cuju_engine_create(path.encode())
|
|
1286
|
+
if not self._engine:
|
|
1287
|
+
raise _errors.LibraryError(_native.last_error())
|
|
1288
|
+
self._config = _ScenarioRecord()
|
|
1289
|
+
self._game = _GameRecord()
|
|
1290
|
+
self._pushed = -1
|
|
1291
|
+
self._match = False
|
|
1292
|
+
self._started = False
|
|
1293
|
+
self._info = _native.Info()
|
|
1294
|
+
self._info.version = _native.VERSION
|
|
1295
|
+
self._tracker_disabled = 1
|
|
1296
|
+
self._tracker_position = 0
|
|
1297
|
+
self._last_step_rendered_frames = 1
|
|
1298
|
+
self._render = None
|
|
1299
|
+
self._render_mode = False
|
|
1300
|
+
|
|
1301
|
+
def __del__(self):
|
|
1302
|
+
# A finalizer may resurrect the engine, as GRF's core does when it returns an engine to its
|
|
1303
|
+
# pool during a collection, so the engine is freed only once nothing refers to it.
|
|
1304
|
+
engine = getattr(self, '_engine', None)
|
|
1305
|
+
if engine:
|
|
1306
|
+
with _RELEASED_LOCK:
|
|
1307
|
+
_RELEASED.append((weakref.ref(self), engine))
|
|
1308
|
+
|
|
1309
|
+
def _raise(self, status):
|
|
1310
|
+
if status >= 0:
|
|
1311
|
+
return
|
|
1312
|
+
message = _native.last_error()
|
|
1313
|
+
if status == -2:
|
|
1314
|
+
raise _errors.UndefinedPathError(message)
|
|
1315
|
+
if status == -3:
|
|
1316
|
+
raise _errors.StateError(message)
|
|
1317
|
+
if status == -4:
|
|
1318
|
+
raise ScenarioError(message)
|
|
1319
|
+
if status == -5:
|
|
1320
|
+
raise _errors.LibraryError(message)
|
|
1321
|
+
raise _errors.ArgumentError(message)
|
|
1322
|
+
|
|
1323
|
+
def _push(self):
|
|
1324
|
+
"""Writes `config` into the engine if it changed since the engine last saw it."""
|
|
1325
|
+
if self._match and self._config.version != self._pushed:
|
|
1326
|
+
scenario, _entries = self._config.to_native()
|
|
1327
|
+
self._raise(_native.library().cuju_engine_set_config(self._engine, scenario))
|
|
1328
|
+
self._pushed = self._config.version
|
|
1329
|
+
|
|
1330
|
+
def _pull_cache(self):
|
|
1331
|
+
"""Reads the engine's cache of the scenario, which a step or a state may change."""
|
|
1332
|
+
cache = (ctypes.c_int * 4)()
|
|
1333
|
+
_native.library().cuju_engine_config_cache(self._engine, cache)
|
|
1334
|
+
values = [bool(cache[0]), bool(cache[1]), cache[2], cache[3]]
|
|
1335
|
+
if values != self._config.cache:
|
|
1336
|
+
self._config.cache = values
|
|
1337
|
+
if self._pushed == self._config.version:
|
|
1338
|
+
self._config.version += 1
|
|
1339
|
+
self._pushed = self._config.version
|
|
1340
|
+
else:
|
|
1341
|
+
self._config.version += 1
|
|
1342
|
+
|
|
1343
|
+
def _ticks(self):
|
|
1344
|
+
return self._game.physics_steps_per_frame
|
|
1345
|
+
|
|
1346
|
+
def _sync_render(self):
|
|
1347
|
+
"""Tells the engine whether it renders, as GRF's graphics read `game_config.render`."""
|
|
1348
|
+
mode = self._render is not None and bool(self._game.render)
|
|
1349
|
+
if mode != self._render_mode:
|
|
1350
|
+
_native.library().cuju_engine_set_render(self._engine, 1 if mode else 0)
|
|
1351
|
+
self._render_mode = mode
|
|
1352
|
+
|
|
1353
|
+
def start_game(self, *arguments, **keywords):
|
|
1354
|
+
_arguments(
|
|
1355
|
+
'GameEnv',
|
|
1356
|
+
'start_game',
|
|
1357
|
+
'start_game(GameEnv_Python {lvalue})',
|
|
1358
|
+
(self, *arguments),
|
|
1359
|
+
keywords,
|
|
1360
|
+
[_instance(GameEnv)],
|
|
1361
|
+
)
|
|
1362
|
+
self._raise(_native.library().cuju_engine_start(self._engine))
|
|
1363
|
+
self._started = True
|
|
1364
|
+
# GRF: the first reset plays `ScenarioConfig::make()`, whose ball `setConfig` scales.
|
|
1365
|
+
record = _ScenarioRecord()
|
|
1366
|
+
record.ball.values = [0.0, -0.0, 0.0]
|
|
1367
|
+
self._config.assign(record)
|
|
1368
|
+
if self._game.render:
|
|
1369
|
+
self._render = _render_hooks.open_session(self)
|
|
1370
|
+
self._sync_render()
|
|
1371
|
+
|
|
1372
|
+
def reset(self, *arguments, **keywords):
|
|
1373
|
+
scenario, animations = _arguments(
|
|
1374
|
+
'GameEnv',
|
|
1375
|
+
'reset',
|
|
1376
|
+
'reset(GameEnv_Python {lvalue}, ScenarioConfig {lvalue}, bool)',
|
|
1377
|
+
(self, *arguments),
|
|
1378
|
+
keywords,
|
|
1379
|
+
[_instance(GameEnv), _instance(ScenarioConfig), _to_bool],
|
|
1380
|
+
)[1:]
|
|
1381
|
+
# GRF: a reset disables the tracker until `tracker_setup`.
|
|
1382
|
+
self._tracker_disabled += 1
|
|
1383
|
+
self._sync_render()
|
|
1384
|
+
record = scenario._record
|
|
1385
|
+
native, _entries = record.to_native()
|
|
1386
|
+
status = _native.library().cuju_engine_reset(
|
|
1387
|
+
self._engine, native, 1 if animations else 0, self._ticks()
|
|
1388
|
+
)
|
|
1389
|
+
self._raise(status)
|
|
1390
|
+
# GRF: `setConfig` scales the caller's ball in place before the copy.
|
|
1391
|
+
record.ball.values = list(native.ball_position)
|
|
1392
|
+
record.version += 1
|
|
1393
|
+
self._config.assign(record)
|
|
1394
|
+
self._pushed = self._config.version
|
|
1395
|
+
self._match = True
|
|
1396
|
+
if self._render is not None:
|
|
1397
|
+
self._render.reset(self, animations)
|
|
1398
|
+
|
|
1399
|
+
def get_info(self, *arguments, **keywords):
|
|
1400
|
+
_arguments(
|
|
1401
|
+
'GameEnv',
|
|
1402
|
+
'get_info',
|
|
1403
|
+
'get_info(GameEnv_Python {lvalue})',
|
|
1404
|
+
(self, *arguments),
|
|
1405
|
+
keywords,
|
|
1406
|
+
[_instance(GameEnv)],
|
|
1407
|
+
)
|
|
1408
|
+
info = _native.Info()
|
|
1409
|
+
info.version = _native.VERSION
|
|
1410
|
+
self._raise(_native.library().cuju_engine_info(self._engine, self._ticks(), info))
|
|
1411
|
+
return SharedInfo._of(info)
|
|
1412
|
+
|
|
1413
|
+
def get_frame(self, *arguments, **keywords):
|
|
1414
|
+
_arguments(
|
|
1415
|
+
'GameEnv',
|
|
1416
|
+
'get_frame',
|
|
1417
|
+
'get_frame(GameEnv_Python {lvalue})',
|
|
1418
|
+
(self, *arguments),
|
|
1419
|
+
keywords,
|
|
1420
|
+
[_instance(GameEnv)],
|
|
1421
|
+
)
|
|
1422
|
+
return _render_hooks.require(self._render).frame()
|
|
1423
|
+
|
|
1424
|
+
def perform_action(self, *arguments, **keywords):
|
|
1425
|
+
action, left_team, player = _arguments(
|
|
1426
|
+
'GameEnv',
|
|
1427
|
+
'perform_action',
|
|
1428
|
+
'perform_action(GameEnv_Python {lvalue}, int, bool, int)',
|
|
1429
|
+
(self, *arguments),
|
|
1430
|
+
keywords,
|
|
1431
|
+
[_instance(GameEnv), _to_int, _to_bool, _to_int],
|
|
1432
|
+
)[1:]
|
|
1433
|
+
self._raise(
|
|
1434
|
+
_native.library().cuju_engine_action(
|
|
1435
|
+
self._engine, action, 1 if left_team else 0, player
|
|
1436
|
+
)
|
|
1437
|
+
)
|
|
1438
|
+
|
|
1439
|
+
def sticky_action_state(self, *arguments, **keywords):
|
|
1440
|
+
action, left_team, player = _arguments(
|
|
1441
|
+
'GameEnv',
|
|
1442
|
+
'sticky_action_state',
|
|
1443
|
+
'sticky_action_state(GameEnv_Python {lvalue}, int, bool, int)',
|
|
1444
|
+
(self, *arguments),
|
|
1445
|
+
keywords,
|
|
1446
|
+
[_instance(GameEnv), _to_int, _to_bool, _to_int],
|
|
1447
|
+
)[1:]
|
|
1448
|
+
status = _native.library().cuju_engine_sticky(
|
|
1449
|
+
self._engine, action, 1 if left_team else 0, player
|
|
1450
|
+
)
|
|
1451
|
+
self._raise(status)
|
|
1452
|
+
return status == 1
|
|
1453
|
+
|
|
1454
|
+
def step(self, *arguments, **keywords):
|
|
1455
|
+
_arguments(
|
|
1456
|
+
'GameEnv',
|
|
1457
|
+
'step',
|
|
1458
|
+
'step(GameEnv_Python {lvalue})',
|
|
1459
|
+
(self, *arguments),
|
|
1460
|
+
keywords,
|
|
1461
|
+
[_instance(GameEnv)],
|
|
1462
|
+
)
|
|
1463
|
+
library = _native.library()
|
|
1464
|
+
self._push()
|
|
1465
|
+
self._sync_render()
|
|
1466
|
+
ticks = self._ticks()
|
|
1467
|
+
tracked = not self._tracker_disabled
|
|
1468
|
+
if self._config.real_time:
|
|
1469
|
+
# GRF: a tick at a time, rendered on a schedule that follows the wall clock.
|
|
1470
|
+
started = time.monotonic()
|
|
1471
|
+
frames = self._last_step_rendered_frames
|
|
1472
|
+
for tick in range(1, ticks + 1):
|
|
1473
|
+
status = library.cuju_engine_ticks(self._engine, ticks, 1)
|
|
1474
|
+
self._raise(status)
|
|
1475
|
+
if status == 1 and tracked:
|
|
1476
|
+
_TRACKER.verify(self)
|
|
1477
|
+
if tick * frames // ticks != (tick - 1) * frames // ticks:
|
|
1478
|
+
self._render_now()
|
|
1479
|
+
elapsed = int((time.monotonic() - started) * 1000)
|
|
1480
|
+
if elapsed > 9 * (ticks + 1) and frames > 1:
|
|
1481
|
+
self._last_step_rendered_frames -= 1
|
|
1482
|
+
elif elapsed < 9 * (ticks - 1) and frames < ticks:
|
|
1483
|
+
self._last_step_rendered_frames += 1
|
|
1484
|
+
self._raise(library.cuju_engine_finish_step(self._engine))
|
|
1485
|
+
elif tracked or self._game.render:
|
|
1486
|
+
status = library.cuju_engine_ticks(self._engine, ticks, ticks)
|
|
1487
|
+
self._raise(status)
|
|
1488
|
+
if status == 1 and tracked:
|
|
1489
|
+
_TRACKER.verify(self)
|
|
1490
|
+
if self._game.render:
|
|
1491
|
+
self._render_now()
|
|
1492
|
+
self._raise(library.cuju_engine_finish_step(self._engine))
|
|
1493
|
+
else:
|
|
1494
|
+
self._raise(library.cuju_engine_step(self._engine, ticks))
|
|
1495
|
+
self._pull_cache()
|
|
1496
|
+
|
|
1497
|
+
def _render_now(self):
|
|
1498
|
+
self._prepare_render().render(self, True)
|
|
1499
|
+
|
|
1500
|
+
def _state_processed(self):
|
|
1501
|
+
"""GRF: `ProcessState` of a save or a load makes the graphics draw the nets afresh."""
|
|
1502
|
+
processed = getattr(self._render, 'state_processed', None)
|
|
1503
|
+
if processed is not None:
|
|
1504
|
+
processed(self)
|
|
1505
|
+
|
|
1506
|
+
def _prepare_render(self):
|
|
1507
|
+
"""Runs GRF's `PrepareRender` on the match and returns the renderer's session."""
|
|
1508
|
+
session = _render_hooks.require(self._render)
|
|
1509
|
+
self._sync_render()
|
|
1510
|
+
self._raise(_native.library().cuju_engine_prepare_render(self._engine))
|
|
1511
|
+
return session
|
|
1512
|
+
|
|
1513
|
+
def render(self, *arguments, **keywords):
|
|
1514
|
+
(swap_buffer,) = _arguments(
|
|
1515
|
+
'GameEnv',
|
|
1516
|
+
'render',
|
|
1517
|
+
'render(GameEnv_Python {lvalue}, bool)',
|
|
1518
|
+
(self, *arguments),
|
|
1519
|
+
keywords,
|
|
1520
|
+
[_instance(GameEnv), _to_bool],
|
|
1521
|
+
)[1:]
|
|
1522
|
+
self._prepare_render().render(self, swap_buffer)
|
|
1523
|
+
|
|
1524
|
+
def get_state(self, *arguments, **keywords):
|
|
1525
|
+
(pickled,) = _arguments(
|
|
1526
|
+
'GameEnv',
|
|
1527
|
+
'get_state',
|
|
1528
|
+
f'get_state(GameEnv_Python {{lvalue}}, {_STRING})',
|
|
1529
|
+
(self, *arguments),
|
|
1530
|
+
keywords,
|
|
1531
|
+
[_instance(GameEnv), _to_string],
|
|
1532
|
+
)[1:]
|
|
1533
|
+
self._push()
|
|
1534
|
+
self._sync_render()
|
|
1535
|
+
pickled = _pickle_names.to_grf(pickled)
|
|
1536
|
+
size = ctypes.c_ulonglong()
|
|
1537
|
+
data = ctypes.POINTER(ctypes.c_char)()
|
|
1538
|
+
self._raise(
|
|
1539
|
+
_native.library().cuju_engine_get_state(
|
|
1540
|
+
self._engine, pickled, len(pickled), ctypes.byref(data), ctypes.byref(size)
|
|
1541
|
+
)
|
|
1542
|
+
)
|
|
1543
|
+
state = ctypes.string_at(data, size.value)
|
|
1544
|
+
self._pull_cache()
|
|
1545
|
+
self._state_processed()
|
|
1546
|
+
return state
|
|
1547
|
+
|
|
1548
|
+
def set_state(self, *arguments, **keywords):
|
|
1549
|
+
(state,) = _arguments(
|
|
1550
|
+
'GameEnv',
|
|
1551
|
+
'set_state',
|
|
1552
|
+
f'set_state(GameEnv_Python {{lvalue}}, {_STRING})',
|
|
1553
|
+
(self, *arguments),
|
|
1554
|
+
keywords,
|
|
1555
|
+
[_instance(GameEnv), _to_string],
|
|
1556
|
+
)[1:]
|
|
1557
|
+
self._push()
|
|
1558
|
+
self._sync_render()
|
|
1559
|
+
offset, size = ctypes.c_ulonglong(), ctypes.c_ulonglong()
|
|
1560
|
+
self._raise(
|
|
1561
|
+
_native.library().cuju_engine_set_state(
|
|
1562
|
+
self._engine, state, len(state), ctypes.byref(offset), ctypes.byref(size)
|
|
1563
|
+
)
|
|
1564
|
+
)
|
|
1565
|
+
self._read_config()
|
|
1566
|
+
self._state_processed()
|
|
1567
|
+
return _pickle_names.from_grf(state[offset.value : offset.value + size.value])
|
|
1568
|
+
|
|
1569
|
+
def _read_config(self):
|
|
1570
|
+
entries = [(_native.Entry * _native.TEAM_PLAYERS)() for _ in range(2)]
|
|
1571
|
+
scenario = _native.Scenario()
|
|
1572
|
+
scenario.left_team = ctypes.cast(entries[0], ctypes.POINTER(_native.Entry))
|
|
1573
|
+
scenario.right_team = ctypes.cast(entries[1], ctypes.POINTER(_native.Entry))
|
|
1574
|
+
self._raise(_native.library().cuju_engine_config(self._engine, scenario))
|
|
1575
|
+
self._config.from_native(scenario)
|
|
1576
|
+
self._pushed = self._config.version
|
|
1577
|
+
|
|
1578
|
+
def tracker_setup(self, *arguments, **keywords):
|
|
1579
|
+
start, end = _arguments(
|
|
1580
|
+
'GameEnv',
|
|
1581
|
+
'tracker_setup',
|
|
1582
|
+
'tracker_setup(GameEnv_Python {lvalue}, long, long)',
|
|
1583
|
+
(self, *arguments),
|
|
1584
|
+
keywords,
|
|
1585
|
+
[_instance(GameEnv), _to_long, _to_long],
|
|
1586
|
+
)[1:]
|
|
1587
|
+
_TRACKER.setup(self, start, end)
|
|
1588
|
+
|
|
1589
|
+
def _get_config(self):
|
|
1590
|
+
return ScenarioConfig._over(self._config)
|
|
1591
|
+
|
|
1592
|
+
def _set_config(self, value):
|
|
1593
|
+
_setter('GameEnv_Python', 'ScenarioConfig', _instance(ScenarioConfig))(self, value)
|
|
1594
|
+
self._config.assign(value._record)
|
|
1595
|
+
|
|
1596
|
+
config = property(_get_config, _set_config, _no_deleter('GameEnv'))
|
|
1597
|
+
|
|
1598
|
+
def _get_game_config(self):
|
|
1599
|
+
return GameConfig._over(self._game)
|
|
1600
|
+
|
|
1601
|
+
def _set_game_config(self, value):
|
|
1602
|
+
_setter('GameEnv_Python', 'GameConfig', _instance(GameConfig))(self, value)
|
|
1603
|
+
for name in _GameRecord.__slots__:
|
|
1604
|
+
setattr(self._game, name, getattr(value._record, name))
|
|
1605
|
+
|
|
1606
|
+
game_config = property(_get_game_config, _set_game_config, _no_deleter('GameEnv'))
|
|
1607
|
+
|
|
1608
|
+
def _get_state(self):
|
|
1609
|
+
return _enum_value(GameState, _native.library().cuju_engine_game_state(self._engine))
|
|
1610
|
+
|
|
1611
|
+
def _set_state(self, value):
|
|
1612
|
+
value = _setter('GameEnv_Python', 'GameState', _instance(GameState))(self, value)
|
|
1613
|
+
_native.library().cuju_engine_set_game_state(self._engine, int(value))
|
|
1614
|
+
|
|
1615
|
+
state = property(_get_state, _set_state, _no_deleter('GameEnv'))
|
|
1616
|
+
|
|
1617
|
+
def _get_waiting(self):
|
|
1618
|
+
return _native.library().cuju_engine_waiting_count(self._engine)
|
|
1619
|
+
|
|
1620
|
+
def _set_waiting(self, value):
|
|
1621
|
+
value = _setter('GameEnv_Python', 'int', _to_int)(self, value)
|
|
1622
|
+
_native.library().cuju_engine_set_waiting_count(self._engine, value)
|
|
1623
|
+
|
|
1624
|
+
waiting_for_game_count = property(_get_waiting, _set_waiting, _no_deleter('GameEnv'))
|