rlgym-rlbot 0.3.0__tar.gz

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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.4
2
+ Name: rlgym-rlbot
3
+ Version: 0.3.0
4
+ Summary: Wrapper logic to use bots trained with RLGym v2 using the RocketSimTransitionEngine in RLBot v5
5
+ Author: Jonathan Keegan
6
+ Project-URL: Repository, https://github.com/JPK314/rlgym-rlbot.git
7
+ Project-URL: Issues, https://github.com/JPK314/rlgym-rlbot/issues
8
+ Keywords: rocket-league,gym,reinforcement-learning,simulation,rlgym,rocketsim
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: <3.13,>=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: rlbot==2.0.0b52
14
+ Requires-Dist: rlbot_flatbuffers>=0.18.8
15
+ Requires-Dist: rlgym[api]>=2.0.1
16
+ Requires-Dist: rlgym-compat>=2.0.0
17
+ Provides-Extra: rocketsim
18
+ Requires-Dist: rocketsim>=2.2.1; extra == "rocketsim"
19
+ Dynamic: license-file
20
+
21
+ # RLBot v5 - RLGym v2 Wrapper
22
+
23
+ A high accuracy wrapper interface allowing bots trained with [RLGym v2](https://rlgym.org/) using the [RocketSimEngine transition engine](https://github.com/lucas-emery/rocket-league-gym/blob/main/rlgym/rocket_league/sim/rocketsim_engine.py) to play in [RLBot v5](https://wiki.rlbot.org/v5/) with minimal configuration required by the user.
24
+
25
+ ## Making a bot with this wrapper
26
+
27
+ Below is a simple snippet from what the main file in the folder of a bot using this wrapper might look like:
28
+
29
+ ```py
30
+ from rlgym_rlbot import RLGymBot, RLGymBotConfig
31
+
32
+ class MyBot(RLGymBot):
33
+ def __init__(self):
34
+ super().__init__(
35
+ obs_builder=MyObsBuilder(),
36
+ action_parser=RepeatAction(LookupTableAction(), 8),
37
+ default_agent_id="jpk314/mybot/v0.1",
38
+ config=RLGymBotConfig(above_240_fps_mode=True),
39
+ )
40
+ self.agent = Agent()
41
+
42
+ def get_action(self, obs, game_state, packet):
43
+ return self.agent.act(obs)
44
+
45
+
46
+ if __name__ == "__main__":
47
+ MyBot().run()
48
+ ```
49
+ In the above example, I am using a custom obs builder (implementation not shown) and a standard action parser using imports from the RLGym[rl] Python package. Where you put your configuration objects' implementations so that they can be used in the above snippet is up to you. The other missing definition is the Agent class - this is an abstraction you might have in your learning framework that takes something of type ObsType and converts it to something of type ActionType. Typically this is something that converts a batch of ObsType to a Torch tensor, runs it through your model, and then converts the result to a batch of ActionType. You will need to know what you're using and how to rip it out of the learning framework you're using to use it here instead.
50
+
51
+ The `RLGymBotConfig` class contains a couple useful knobs which are described in the following section.
52
+
53
+ Other mandatory configuration files that need to go in your bot's folder are described [here](https://wiki.rlbot.org/v5/botmaking/config-files/) on the RLBot v5 wiki.
54
+
55
+ ### Optional Overridable Methods
56
+
57
+ #### Mixing with hard-coded actions or action sequences
58
+ The method `get_hardcoded_action` allows you to override whatever your model was planning to do and instead do whatever `ControllerState` you return from this method. The default return value is `None` which means the model will continue with whatever it was doing. This is most valuable for hard coding kickoff maneuvers. You can manage the maneuver state in your subclass of RLGymBot. If you ever return a non-`None` value and then return `None` again, the wrapper will simulate an on-the-fly reset of the environment for your config objects so that the model can resume playing.
59
+
60
+ #### Sending messages
61
+ Sending messages to other bots or in the chat can be done during the `get_hardcoded_action` call (which happens every tick during gameplay) or during the `get_other_packet_output` call (which happens the rest of the time) by calling `self.send_match_comm`.
62
+
63
+ #### Recovering from one or more incorrectly taken actions
64
+ The method `decide_missed_action_recovery_style` allows for custom logic to decide which recovery style to use - either `MissedActionRecoveryStyle.RESET` or `MissedActionRecoveryStyle.IGNORE`. The inputs to this method provide a bunch of useful values that you may want in order to determine how to handle this, including
65
+ - The current packet and game state
66
+ - The number of ticks left in the currently in use action (remember that the output of your action parser is an action which corresponds to a sequence of ControllerStates, one per tick)
67
+ - The past ticks where an incorrect `ControllerState` was used and the `ControllerState` that was intended based on the output of your action parser
68
+
69
+ The default return value is `IGNORE`. There are situations where you may want to perform an on-the-fly reset to generate a new action from the current state instead. You probably do NOT want to perform an on-the-fly reset if you're currently in the middle of a flip, for example, because it's not possible with the RocketSimEngine to start an episode in the middle of a flip.
70
+
71
+ #### Recovering from a missed tick needed for stepping the environment
72
+ The method `decide_missed_step_tick_recovery_style` allows for custom logic to decide which recovery style to use - either `MissedStepTickRecoveryStyle.RESET` or `MissedStepTickRecoveryStyle.USE_NEAREST`. The inputs to this method provide a bunch of useful values that you may want in order to determine how to handle this, including
73
+ - The current packet and game state
74
+ - The number of ticks left in the currently in use action (remember that the output of your action parser is an action which corresponds to a sequence of ControllerStates, one per tick)
75
+ - The last `ControllerState` used by the bot
76
+
77
+ The default return value is `USE_NEAREST`. Unless your config objects are really sensitive, this is probably good enough for all situations. However, if you come up with a scenario where you think it would be preferable to perform an on-the-fly reset instead of using a slightly inaccurate (or temporally shifted, whatever way you want to think about it) game state for your config objects, you can return `RESET` in that scenario instead.
78
+
79
+ #### Handling cosmetic actions (kickoff wiggle)
80
+ The method `get_other_packet_output` can be used to return `ControllerState`s during times where your actions don't actually matter, in particularly during the Countdown match phase. For the first 440 ticks of countdown, you can do whatever wheel wiggling you desire by returning controller states here. Why 440? Countdown always lasts at least 479 ticks from my testing, and so this is just a safe margin.
81
+
82
+ #### Handling reward function output
83
+ The method `handle_reward` is called if you pass in a `RewardFunction` to the `RLGymBot` constructor on every step. You can decide what to do with this (display it on screen? write it to a file?) by overwriting this method. By default it is a no-op.
84
+
85
+ #### Various standard Bot python interface methods and fields
86
+ Many convenience methods from the `Bot` class in the [python interface](https://github.com/RLBot/python-interface) are available here as well. These include:
87
+ - `initialize`
88
+ - `retire`
89
+ - `set_loadout`
90
+ - `handle_match_comm`
91
+ - `send_match_comm`
92
+ - `set_game_state`
93
+
94
+ There are convenience fields as well:
95
+ - `self.player_id`
96
+ - `self.name`
97
+ - `self.index`
98
+ - `self.team`
99
+ - `self.match_config`
100
+ - `self.field_info`
101
+ - `self.ball_prediction`
102
+ - `self.logger`
103
+ - `self.renderer`
104
+
105
+ ## Config Options
106
+ The `RLGymBotConfig` class contains the following options:
107
+
108
+ ### step_offset
109
+ StepOffset dataclass with fields `offset` and `relative_to` - default `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END`. This option determines when during the course of executing the last action a game state is taken to be used for simulating a step of the env (most importantly, for building your observation). See below for specific notes on how this works.
110
+ - Use `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END` if you use the [RocketSimEngine transition engine](https://github.com/lucas-emery/rocket-league-gym/blob/main/rlgym/rocket_league/sim/rocketsim_engine.py) with `rlbot_delay=True`
111
+ - Use `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_END` if you use the above with `rlbot_delay=False`
112
+ - Use `offset=1` and `relative_to=StepOffsetRelativeTo.ACTION_START` if you are using RLGym v1 or rlgym-sim
113
+
114
+ Here is a helpful diagram explaining how these values fully work. For simplicity, let's say every action (by this I mean result from the action parser) has a shape of (4,8) i.e. it defines 4 ticks worth of actions sent to Rocket League. `.` represents a regular state, and `-` represents a state transition.
115
+
116
+ Values `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_START` would look like the below - in particular, the (n+1)th action is decided using the state that the nth action is about to start from:
117
+ ```
118
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
119
+ || | | ||| | | ||| | | └Action 3 tick 4, etc
120
+ || | | ||| | | ||| | └Action 3 tick 3
121
+ || | | ||| | | ||| └Action 3 tick 2
122
+ || | | ||| | | ||└Action 3 tick 1
123
+ || | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
124
+ || | | ||| | | └Action 2 tick 4
125
+ || | | ||| | └Action 2 tick 3
126
+ || | | ||| └Action 2 tick 2
127
+ || | | ||└Action 2 tick 1
128
+ || | | |└Obs 3 created using this state, action 3 decided using obs 3
129
+ || | | └Action 1 tick 4
130
+ || | └Action 1 tick 3
131
+ || └Action 1 tick 2
132
+ |└Action 1 tick 1
133
+ └Reset occurs, obs 1 and 2 created using this state, actions 1 and 2 decided using obs 1 and 2 respectively
134
+ ```
135
+
136
+ Values `offset=1` and `relative_to=StepOffsetRelativeTo.ACTION_START` would look like the below - in particular, an action is decided using the state one tick after the last action's env action ticks began:
137
+ ```
138
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
139
+ |||| | | ||| | | ||| | └Action 3 tick 4, etc
140
+ |||| | | ||| | | ||| └Action 3 tick 3
141
+ |||| | | ||| | | ||└Action 3 tick 2
142
+ |||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
143
+ |||| | | ||| | | └Action 3 tick 1
144
+ |||| | | ||| | └Action 2 tick 4
145
+ |||| | | ||| └Action 2 tick 3
146
+ |||| | | ||└Action 2 tick 2
147
+ |||| | | |└Obs 3 created using this state, action 3 decided using obs 3
148
+ |||| | | └Action 2 tick 1
149
+ |||| | └Action 1 tick 4
150
+ |||| └Action 1 tick 3
151
+ |||└Action 1 tick 2
152
+ ||└Obs 2 created using this state, action 2 decided using obs 2
153
+ |└Action 1 tick 1
154
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
155
+ ```
156
+
157
+ Values `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_END` would look like the below - in particular, the next action action is decided using the state after the last action's env action ticks are done:
158
+ ```
159
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
160
+ || | | ||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4, etc
161
+ || | | ||| | | ||| | | └Action 3 tick 4
162
+ || | | ||| | | ||| | └Action 3 tick 3
163
+ || | | ||| | | ||| └Action 3 tick 2
164
+ || | | ||| | | ||└Action 3 tick 1
165
+ || | | ||| | | |└Obs 3 created using this state, action 3 decided using obs 3
166
+ || | | ||| | | └Action 2 tick 4
167
+ || | | ||| | └Action 2 tick 3
168
+ || | | ||| └Action 2 tick 2
169
+ || | | ||└Action 2 tick 1
170
+ || | | |└Obs 2 created using this state, action 2 decided using obs 2
171
+ || | | └Action 1 tick 4
172
+ || | └Action 1 tick 3
173
+ || └Action 1 tick 2
174
+ |└Action 1 tick 1
175
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
176
+ ```
177
+
178
+ Values `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END` would look like the below - in particular, an action is decided using the state one tick before the last action's env action ticks are done:
179
+ ```
180
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
181
+ || | | ||| | | ||| | | ||└Action 3 tick 4, etc
182
+ || | | ||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
183
+ || | | ||| | | ||| | | └Action 3 tick 3
184
+ || | | ||| | | ||| | └Action 3 tick 2
185
+ || | | ||| | | ||| └Action 3 tick 1
186
+ || | | ||| | | ||└Action 2 tick 4
187
+ || | | ||| | | |└Obs 3 created using this state, action 3 decided using obs 3
188
+ || | | ||| | | └Action 2 tick 3
189
+ || | | ||| | └Action 2 tick 2
190
+ || | | ||| └Action 2 tick 1
191
+ || | | ||└Action 1 tick 4
192
+ || | | |└Obs 2 created using this state, action 2 decided using obs 2
193
+ || | | └Action 1 tick 3
194
+ || | └Action 1 tick 2
195
+ || └Action 1 tick 1
196
+ |└"void" state transition where sim is stepped without any cars' controls being set
197
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
198
+ ```
199
+ ### standard_map
200
+ Boolean - default `true`. This option is passed to [rlgym-compat](https://github.com/JPK314/rlgym-compat)'s GameState in order to configure boost pad ordering.
201
+
202
+ ### sim_extra_info
203
+ Boolean - default `false`. This option determines whether rlgym-compat's [SimExtraInfo](https://github.com/JPK314/rlgym-compat/blob/main/rlgym_compat/sim_extra_info.py) is used for extra information that otherwise cannot be derived from the RLBot GamePacket.
204
+
205
+ ### agent_ids_fn
206
+ Optional Callable - default `None`. This option determines how rlgym-compat assigns `AgentID`s to players when creating the compat GameState from the RLBot v5's `flat.GamePacket`. The input is a `GamePacket` and the output is a map from `PlayerInfo.player_id` to your desired `AgentID` data type and value for your config objects. Normally this would be handled by your `StateMutator`, but that functionality is not implemented yet and this acts as a simple override without the other potential `StateMutator` behavior.
207
+
208
+
209
+ ## What does "accurate" mean? What is this wrapper doing?
210
+ This wrapper attempts to replicate the training conditions of your bot in RLGym as accurately as possible. This means a lot of consideration is put into tick-perfectly matching everything where possible while maintaining the flow and functionality expected by arbitrary config objects and by proxy your model during training using RLGym v2.
211
+
212
+ ### Tick perfectly matching actions
213
+ This wrapper assumes that your computer is running Rocket League in such a way that you have enough time for your actions to always get submitted for use between the latest received packet's physics frame and the next physics frame. The optimal conditions for this are when you play using a capped frame rate that is either 120 or 240, because these frame rates have the largest windows between when the wrapper receives a packet from RLBot Core and when you can no longer submit an action and have it be used during the state transition between the latest received packet's physics tick and the next physics tick. This window is about 6 milliseconds on average with a small standard deviation when the framerate is capped to 120 or 240 (NOT 360!), and is about 4 milliseconds on average with a much wider standard deviation when left uncapped. Other frame rates do very poorly and are not recommended. Possibly if you modify the command line argument RLBot passes for packet send rate from 240 to another number you may be able to get up to a 6 millisecond window using another frame rate, but it's untested and annoying to configure. Just use 120 or 240 capped, or hope for the best uncapped.
214
+
215
+ ### On-the-fly resets and countdown actions
216
+ This wrapper tries to tick perfectly match how your config objects and model interact with each other and the sim in RLGym v2. However, there are some situations where this is just not possible. One such situation is when an on-the-fly reset is performed. These can happen if your `decide_*_recovery_style` methods return `RESET` or if you stop taking a hard-coded action. Due to an implementation detail, in RLGym v2's RocketSimEngine with the default constructor parameter (`rlbot_delay=True`), after resetting, all agents will do one tick of an all-zeros action before beginning the action generated due to the reset state's observation. In the language of this wrapper, this means that after resetting, if you have `offset < 0` and `relative_to = StepOffsetRelativeTo.ACTION_END`, in theory you should take `offset` ticks of the zero action in order to perfectly match how everything works during training. This is obviously not desirable against an opponent with no such restrictions, and so instead the observation is generated using the game state from `offset` ticks ago, and the fact that a non-all-zeros action was taken for the ticks since that point until this new action is due to start (this tick) is assumed to come out in the wash.
217
+
218
+ Due to the duration of the Countdown phase being unreliable, it is impossible to perfectly time the reset so that you start the action as soon as Countdown ends (your actions start getting used on the state transition between the last packet of Countdown and the first packet of Kickoff). During the Countdown match phase, the cars settle onto the ground and cannot move (wheel wiggling is purely cosmetic), so the difference between using the proper tick of Countdown and some older tick of countdown is essentially zero. This wrapper uses the 440th (or next available after) tick after the Countdown phase began as the tick on which to generate the observation that will be used once Countdown ends, and simply sends the first ControllerState of this action every tick from then on until the latest packet is Kickoff instead of Countdown. This should work essentially perfectly UNLESS you intend to jump on the first tick. Because the ControllerState is sent repeatedly during Countdown, the game will think you are just holding jump and so once you can actually move you won't jump, you'll just be holding jump. So... don't do that!
@@ -0,0 +1,198 @@
1
+ # RLBot v5 - RLGym v2 Wrapper
2
+
3
+ A high accuracy wrapper interface allowing bots trained with [RLGym v2](https://rlgym.org/) using the [RocketSimEngine transition engine](https://github.com/lucas-emery/rocket-league-gym/blob/main/rlgym/rocket_league/sim/rocketsim_engine.py) to play in [RLBot v5](https://wiki.rlbot.org/v5/) with minimal configuration required by the user.
4
+
5
+ ## Making a bot with this wrapper
6
+
7
+ Below is a simple snippet from what the main file in the folder of a bot using this wrapper might look like:
8
+
9
+ ```py
10
+ from rlgym_rlbot import RLGymBot, RLGymBotConfig
11
+
12
+ class MyBot(RLGymBot):
13
+ def __init__(self):
14
+ super().__init__(
15
+ obs_builder=MyObsBuilder(),
16
+ action_parser=RepeatAction(LookupTableAction(), 8),
17
+ default_agent_id="jpk314/mybot/v0.1",
18
+ config=RLGymBotConfig(above_240_fps_mode=True),
19
+ )
20
+ self.agent = Agent()
21
+
22
+ def get_action(self, obs, game_state, packet):
23
+ return self.agent.act(obs)
24
+
25
+
26
+ if __name__ == "__main__":
27
+ MyBot().run()
28
+ ```
29
+ In the above example, I am using a custom obs builder (implementation not shown) and a standard action parser using imports from the RLGym[rl] Python package. Where you put your configuration objects' implementations so that they can be used in the above snippet is up to you. The other missing definition is the Agent class - this is an abstraction you might have in your learning framework that takes something of type ObsType and converts it to something of type ActionType. Typically this is something that converts a batch of ObsType to a Torch tensor, runs it through your model, and then converts the result to a batch of ActionType. You will need to know what you're using and how to rip it out of the learning framework you're using to use it here instead.
30
+
31
+ The `RLGymBotConfig` class contains a couple useful knobs which are described in the following section.
32
+
33
+ Other mandatory configuration files that need to go in your bot's folder are described [here](https://wiki.rlbot.org/v5/botmaking/config-files/) on the RLBot v5 wiki.
34
+
35
+ ### Optional Overridable Methods
36
+
37
+ #### Mixing with hard-coded actions or action sequences
38
+ The method `get_hardcoded_action` allows you to override whatever your model was planning to do and instead do whatever `ControllerState` you return from this method. The default return value is `None` which means the model will continue with whatever it was doing. This is most valuable for hard coding kickoff maneuvers. You can manage the maneuver state in your subclass of RLGymBot. If you ever return a non-`None` value and then return `None` again, the wrapper will simulate an on-the-fly reset of the environment for your config objects so that the model can resume playing.
39
+
40
+ #### Sending messages
41
+ Sending messages to other bots or in the chat can be done during the `get_hardcoded_action` call (which happens every tick during gameplay) or during the `get_other_packet_output` call (which happens the rest of the time) by calling `self.send_match_comm`.
42
+
43
+ #### Recovering from one or more incorrectly taken actions
44
+ The method `decide_missed_action_recovery_style` allows for custom logic to decide which recovery style to use - either `MissedActionRecoveryStyle.RESET` or `MissedActionRecoveryStyle.IGNORE`. The inputs to this method provide a bunch of useful values that you may want in order to determine how to handle this, including
45
+ - The current packet and game state
46
+ - The number of ticks left in the currently in use action (remember that the output of your action parser is an action which corresponds to a sequence of ControllerStates, one per tick)
47
+ - The past ticks where an incorrect `ControllerState` was used and the `ControllerState` that was intended based on the output of your action parser
48
+
49
+ The default return value is `IGNORE`. There are situations where you may want to perform an on-the-fly reset to generate a new action from the current state instead. You probably do NOT want to perform an on-the-fly reset if you're currently in the middle of a flip, for example, because it's not possible with the RocketSimEngine to start an episode in the middle of a flip.
50
+
51
+ #### Recovering from a missed tick needed for stepping the environment
52
+ The method `decide_missed_step_tick_recovery_style` allows for custom logic to decide which recovery style to use - either `MissedStepTickRecoveryStyle.RESET` or `MissedStepTickRecoveryStyle.USE_NEAREST`. The inputs to this method provide a bunch of useful values that you may want in order to determine how to handle this, including
53
+ - The current packet and game state
54
+ - The number of ticks left in the currently in use action (remember that the output of your action parser is an action which corresponds to a sequence of ControllerStates, one per tick)
55
+ - The last `ControllerState` used by the bot
56
+
57
+ The default return value is `USE_NEAREST`. Unless your config objects are really sensitive, this is probably good enough for all situations. However, if you come up with a scenario where you think it would be preferable to perform an on-the-fly reset instead of using a slightly inaccurate (or temporally shifted, whatever way you want to think about it) game state for your config objects, you can return `RESET` in that scenario instead.
58
+
59
+ #### Handling cosmetic actions (kickoff wiggle)
60
+ The method `get_other_packet_output` can be used to return `ControllerState`s during times where your actions don't actually matter, in particularly during the Countdown match phase. For the first 440 ticks of countdown, you can do whatever wheel wiggling you desire by returning controller states here. Why 440? Countdown always lasts at least 479 ticks from my testing, and so this is just a safe margin.
61
+
62
+ #### Handling reward function output
63
+ The method `handle_reward` is called if you pass in a `RewardFunction` to the `RLGymBot` constructor on every step. You can decide what to do with this (display it on screen? write it to a file?) by overwriting this method. By default it is a no-op.
64
+
65
+ #### Various standard Bot python interface methods and fields
66
+ Many convenience methods from the `Bot` class in the [python interface](https://github.com/RLBot/python-interface) are available here as well. These include:
67
+ - `initialize`
68
+ - `retire`
69
+ - `set_loadout`
70
+ - `handle_match_comm`
71
+ - `send_match_comm`
72
+ - `set_game_state`
73
+
74
+ There are convenience fields as well:
75
+ - `self.player_id`
76
+ - `self.name`
77
+ - `self.index`
78
+ - `self.team`
79
+ - `self.match_config`
80
+ - `self.field_info`
81
+ - `self.ball_prediction`
82
+ - `self.logger`
83
+ - `self.renderer`
84
+
85
+ ## Config Options
86
+ The `RLGymBotConfig` class contains the following options:
87
+
88
+ ### step_offset
89
+ StepOffset dataclass with fields `offset` and `relative_to` - default `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END`. This option determines when during the course of executing the last action a game state is taken to be used for simulating a step of the env (most importantly, for building your observation). See below for specific notes on how this works.
90
+ - Use `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END` if you use the [RocketSimEngine transition engine](https://github.com/lucas-emery/rocket-league-gym/blob/main/rlgym/rocket_league/sim/rocketsim_engine.py) with `rlbot_delay=True`
91
+ - Use `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_END` if you use the above with `rlbot_delay=False`
92
+ - Use `offset=1` and `relative_to=StepOffsetRelativeTo.ACTION_START` if you are using RLGym v1 or rlgym-sim
93
+
94
+ Here is a helpful diagram explaining how these values fully work. For simplicity, let's say every action (by this I mean result from the action parser) has a shape of (4,8) i.e. it defines 4 ticks worth of actions sent to Rocket League. `.` represents a regular state, and `-` represents a state transition.
95
+
96
+ Values `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_START` would look like the below - in particular, the (n+1)th action is decided using the state that the nth action is about to start from:
97
+ ```
98
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
99
+ || | | ||| | | ||| | | └Action 3 tick 4, etc
100
+ || | | ||| | | ||| | └Action 3 tick 3
101
+ || | | ||| | | ||| └Action 3 tick 2
102
+ || | | ||| | | ||└Action 3 tick 1
103
+ || | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
104
+ || | | ||| | | └Action 2 tick 4
105
+ || | | ||| | └Action 2 tick 3
106
+ || | | ||| └Action 2 tick 2
107
+ || | | ||└Action 2 tick 1
108
+ || | | |└Obs 3 created using this state, action 3 decided using obs 3
109
+ || | | └Action 1 tick 4
110
+ || | └Action 1 tick 3
111
+ || └Action 1 tick 2
112
+ |└Action 1 tick 1
113
+ └Reset occurs, obs 1 and 2 created using this state, actions 1 and 2 decided using obs 1 and 2 respectively
114
+ ```
115
+
116
+ Values `offset=1` and `relative_to=StepOffsetRelativeTo.ACTION_START` would look like the below - in particular, an action is decided using the state one tick after the last action's env action ticks began:
117
+ ```
118
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
119
+ |||| | | ||| | | ||| | └Action 3 tick 4, etc
120
+ |||| | | ||| | | ||| └Action 3 tick 3
121
+ |||| | | ||| | | ||└Action 3 tick 2
122
+ |||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
123
+ |||| | | ||| | | └Action 3 tick 1
124
+ |||| | | ||| | └Action 2 tick 4
125
+ |||| | | ||| └Action 2 tick 3
126
+ |||| | | ||└Action 2 tick 2
127
+ |||| | | |└Obs 3 created using this state, action 3 decided using obs 3
128
+ |||| | | └Action 2 tick 1
129
+ |||| | └Action 1 tick 4
130
+ |||| └Action 1 tick 3
131
+ |||└Action 1 tick 2
132
+ ||└Obs 2 created using this state, action 2 decided using obs 2
133
+ |└Action 1 tick 1
134
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
135
+ ```
136
+
137
+ Values `offset=0` and `relative_to=StepOffsetRelativeTo.ACTION_END` would look like the below - in particular, the next action action is decided using the state after the last action's env action ticks are done:
138
+ ```
139
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
140
+ || | | ||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4, etc
141
+ || | | ||| | | ||| | | └Action 3 tick 4
142
+ || | | ||| | | ||| | └Action 3 tick 3
143
+ || | | ||| | | ||| └Action 3 tick 2
144
+ || | | ||| | | ||└Action 3 tick 1
145
+ || | | ||| | | |└Obs 3 created using this state, action 3 decided using obs 3
146
+ || | | ||| | | └Action 2 tick 4
147
+ || | | ||| | └Action 2 tick 3
148
+ || | | ||| └Action 2 tick 2
149
+ || | | ||└Action 2 tick 1
150
+ || | | |└Obs 2 created using this state, action 2 decided using obs 2
151
+ || | | └Action 1 tick 4
152
+ || | └Action 1 tick 3
153
+ || └Action 1 tick 2
154
+ |└Action 1 tick 1
155
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
156
+ ```
157
+
158
+ Values `offset=-1` and `relative_to=StepOffsetRelativeTo.ACTION_END` would look like the below - in particular, an action is decided using the state one tick before the last action's env action ticks are done:
159
+ ```
160
+ .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
161
+ || | | ||| | | ||| | | ||└Action 3 tick 4, etc
162
+ || | | ||| | | ||| | | |└Obs 4 created using this state, action 4 decided using obs 4
163
+ || | | ||| | | ||| | | └Action 3 tick 3
164
+ || | | ||| | | ||| | └Action 3 tick 2
165
+ || | | ||| | | ||| └Action 3 tick 1
166
+ || | | ||| | | ||└Action 2 tick 4
167
+ || | | ||| | | |└Obs 3 created using this state, action 3 decided using obs 3
168
+ || | | ||| | | └Action 2 tick 3
169
+ || | | ||| | └Action 2 tick 2
170
+ || | | ||| └Action 2 tick 1
171
+ || | | ||└Action 1 tick 4
172
+ || | | |└Obs 2 created using this state, action 2 decided using obs 2
173
+ || | | └Action 1 tick 3
174
+ || | └Action 1 tick 2
175
+ || └Action 1 tick 1
176
+ |└"void" state transition where sim is stepped without any cars' controls being set
177
+ └Reset occurs, obs 1 created using this state, action 1 decided using obs 1
178
+ ```
179
+ ### standard_map
180
+ Boolean - default `true`. This option is passed to [rlgym-compat](https://github.com/JPK314/rlgym-compat)'s GameState in order to configure boost pad ordering.
181
+
182
+ ### sim_extra_info
183
+ Boolean - default `false`. This option determines whether rlgym-compat's [SimExtraInfo](https://github.com/JPK314/rlgym-compat/blob/main/rlgym_compat/sim_extra_info.py) is used for extra information that otherwise cannot be derived from the RLBot GamePacket.
184
+
185
+ ### agent_ids_fn
186
+ Optional Callable - default `None`. This option determines how rlgym-compat assigns `AgentID`s to players when creating the compat GameState from the RLBot v5's `flat.GamePacket`. The input is a `GamePacket` and the output is a map from `PlayerInfo.player_id` to your desired `AgentID` data type and value for your config objects. Normally this would be handled by your `StateMutator`, but that functionality is not implemented yet and this acts as a simple override without the other potential `StateMutator` behavior.
187
+
188
+
189
+ ## What does "accurate" mean? What is this wrapper doing?
190
+ This wrapper attempts to replicate the training conditions of your bot in RLGym as accurately as possible. This means a lot of consideration is put into tick-perfectly matching everything where possible while maintaining the flow and functionality expected by arbitrary config objects and by proxy your model during training using RLGym v2.
191
+
192
+ ### Tick perfectly matching actions
193
+ This wrapper assumes that your computer is running Rocket League in such a way that you have enough time for your actions to always get submitted for use between the latest received packet's physics frame and the next physics frame. The optimal conditions for this are when you play using a capped frame rate that is either 120 or 240, because these frame rates have the largest windows between when the wrapper receives a packet from RLBot Core and when you can no longer submit an action and have it be used during the state transition between the latest received packet's physics tick and the next physics tick. This window is about 6 milliseconds on average with a small standard deviation when the framerate is capped to 120 or 240 (NOT 360!), and is about 4 milliseconds on average with a much wider standard deviation when left uncapped. Other frame rates do very poorly and are not recommended. Possibly if you modify the command line argument RLBot passes for packet send rate from 240 to another number you may be able to get up to a 6 millisecond window using another frame rate, but it's untested and annoying to configure. Just use 120 or 240 capped, or hope for the best uncapped.
194
+
195
+ ### On-the-fly resets and countdown actions
196
+ This wrapper tries to tick perfectly match how your config objects and model interact with each other and the sim in RLGym v2. However, there are some situations where this is just not possible. One such situation is when an on-the-fly reset is performed. These can happen if your `decide_*_recovery_style` methods return `RESET` or if you stop taking a hard-coded action. Due to an implementation detail, in RLGym v2's RocketSimEngine with the default constructor parameter (`rlbot_delay=True`), after resetting, all agents will do one tick of an all-zeros action before beginning the action generated due to the reset state's observation. In the language of this wrapper, this means that after resetting, if you have `offset < 0` and `relative_to = StepOffsetRelativeTo.ACTION_END`, in theory you should take `offset` ticks of the zero action in order to perfectly match how everything works during training. This is obviously not desirable against an opponent with no such restrictions, and so instead the observation is generated using the game state from `offset` ticks ago, and the fact that a non-all-zeros action was taken for the ticks since that point until this new action is due to start (this tick) is assumed to come out in the wash.
197
+
198
+ Due to the duration of the Countdown phase being unreliable, it is impossible to perfectly time the reset so that you start the action as soon as Countdown ends (your actions start getting used on the state transition between the last packet of Countdown and the first packet of Kickoff). During the Countdown match phase, the cars settle onto the ground and cannot move (wheel wiggling is purely cosmetic), so the difference between using the proper tick of Countdown and some older tick of countdown is essentially zero. This wrapper uses the 440th (or next available after) tick after the Countdown phase began as the tick on which to generate the observation that will be used once Countdown ends, and simply sends the first ControllerState of this action every tick from then on until the latest packet is Kickoff instead of Countdown. This should work essentially perfectly UNLESS you intend to jump on the first tick. Because the ControllerState is sent repeatedly during Countdown, the game will think you are just holding jump and so once you can actually move you won't jump, you'll just be holding jump. So... don't do that!