Environment API¶
The main EldenGymEnv class implements the Gymnasium environment interface.
EldenGymEnv¶
EldenGymEnv ¶
Bases: Env
Elden Ring Gymnasium environment - OpenAI Five style approach.
Simple design philosophy: - Fixed timestep observations (like Dota/Atari) - Agent gets current game state every step - Let RL figure out action timing from animation_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario_name
|
str
|
Boss scenario. Default: 'margit' |
'margit'
|
host
|
str
|
Siphon client host. Default: 'localhost:50051' |
'localhost:50051'
|
action_mode
|
str
|
Action space type. - 'discrete': Single action per step (14 actions) - 'multi_binary': Multiple keys per step (11 keys) |
'discrete'
|
reward_function
|
RewardFunction
|
Custom reward function. |
None
|
frame_skip
|
int
|
Frames to skip between observations. Higher = faster but less responsive. Default: 4 |
4
|
game_speed
|
float
|
Game speed (0.1-1.0). Lower = easier for agent. Default: 1.0 |
1.0
|
freeze_game
|
bool
|
Whether to freeze the game. Default: False |
False
|
game_fps
|
int
|
Game FPS. Default: 60 |
60
|
max_step
|
int
|
Maximum number of steps. Default: None (infinite horizon) |
None
|
Action Spaces
discrete: Gym.spaces.Discrete(14) - Predefined combos (attack, dodge_forward, etc.) multi_binary: Gym.spaces.MultiBinary(11) - Individual keys (W, A, S, D, SPACE, SHIFT, etc.) - Agent can press multiple keys simultaneously - More flexible, closer to human input
Source code in eldengym/env.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
close ¶
Close the environment and clean up resources.
This method closes the connection to the siphon client.
reset ¶
Reset environment - start new episode.
Source code in eldengym/env.py
step ¶
Execute one step
send action, wait frame_skip frames, return observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
int (discrete mode) or array (multi_binary mode) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(observation, reward, terminated, truncated, info) |
Source code in eldengym/env.py
Methods¶
Core Gymnasium Methods¶
reset()¶
Reset the environment to initial state.
Returns:
- observation (np.ndarray): Initial observation
- info (dict): Additional information
Example:
step(action)¶
Execute one step in the environment.
Args:
- action (int | np.ndarray): Action to take
Returns:
- observation (np.ndarray): New observation
- reward (float): Reward for the action
- terminated (bool): Whether episode ended (boss defeated/player died)
- truncated (bool): Whether episode was truncated (max steps)
- info (dict): Additional information
Example:
obs, reward, terminated, truncated, info = env.step(action)
if terminated:
print(f"Episode ended! Final reward: {reward}")
close()¶
Clean up environment resources.
Rendering¶
render()¶
Return current game frame.
Returns:
- np.ndarray: RGB frame (H, W, 3)
Example:
Properties¶
Action Space¶
The action space depends on the action_mode parameter:
Discrete (default):
env.action_space # Discrete(9)
# 0: no-op
# 1: forward
# 2: backward
# 3: left
# 4: right
# 5: attack
# 6: dodge
# 7: lock-on
# 8: use-item
Multi-Binary:
env.action_space # MultiBinary(8)
# [forward, backward, left, right, attack, dodge, lock-on, use-item]
Observation Space¶
RGB Frame only:
With game state:
env.observation_space # Dict({
# 'frame': Box(0, 255, (H, W, 3), uint8),
# 'player_hp': Box(0, inf, (1,), float32),
# 'player_max_hp': Box(0, inf, (1,), float32),
# 'target_hp': Box(0, inf, (1,), float32),
# 'target_max_hp': Box(0, inf, (1,), float32),
# ...
# })
Info Dictionary¶
The info dict returned by step() and reset() contains:
| Key | Type | Description |
|---|---|---|
player_hp |
int | Player's current HP |
player_max_hp |
int | Player's maximum HP |
target_hp |
int | Target/boss current HP |
target_max_hp |
int | Target/boss maximum HP |
distance |
float | Distance to target |
player_animation_id |
int | Current player animation |
target_animation_id |
int | Current target animation |
step_count |
int | Steps in current episode |
Configuration¶
env = gym.make(
"EldenGym-v0",
# Scenario
scenario_name="margit", # Boss fight scenario
# Connection
host="localhost:50051", # Siphon server address
config_filepath="ER_1_16_1.toml", # Memory config
# Action space
action_mode="discrete", # "discrete", "multi_binary", or "continuous"
# Observation space
observation_mode="rgb", # "rgb" or "dict"
# Rewards
reward_function=None, # Custom reward function
# Game settings
frame_skip=4, # Frames to skip (like Atari)
game_speed=1.0, # Game speed multiplier
freeze_game=False, # Freeze game between steps
game_fps=60, # Target FPS
# Episode settings
max_step=None, # Max steps before truncation (None = no limit)
)