-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
305 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Version 0.4.0 | ||
|
||
- Multi-agent environment | ||
- Use polar representation instead of coordinates (except for the "full" environment) | ||
- Only two base environments (multi/mono-agent) and wrappers for the rest: this allows races to be organized with different set of wrappers (depending on the agent) | ||
- Added `distance_center_path` | ||
- Allow to change player name and camera mode | ||
- breaking: Agent spec is used for mono-kart environments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,14 @@ description = "Gymnasium wrapper for PySTK2" | |
authors = ["Benjamin Piwowarski <[email protected]>"] | ||
license = "GPL" | ||
readme = "README.md" | ||
|
||
homepage = "https://github.com/bpiwowar/pystk2-gymnasium" | ||
repository = "https://github.com/bpiwowar/pystk2-gymnasium" | ||
|
||
include = ["CHANGELOG.md"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
PySuperTuxKart2 = "=0.3.4" | ||
PySuperTuxKart2 = ">=0.3.5" | ||
gymnasium = ">0.29.0" | ||
|
||
[build-system] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
This module contains STK-specific wrappers | ||
""" | ||
|
||
from typing import Any, Dict, Optional, Tuple | ||
from dataclasses import dataclass | ||
import pystk2 | ||
|
||
import gymnasium as gym | ||
from gymnasium.core import ( | ||
Wrapper, | ||
WrapperActType, | ||
WrapperObsType, | ||
ObsType, | ||
ActType, | ||
SupportsFloat, | ||
) | ||
|
||
CameraMode = pystk2.PlayerConfig.CameraMode | ||
|
||
|
||
@dataclass | ||
class AgentSpec: | ||
#: The position of the controlled kart, defaults to None for random, 0 to | ||
# num_kart-1 assigns a rank, all the other values discard the controlled | ||
# kart. | ||
rank_start: Optional[int] = None | ||
#: Use the STK AI agent (ignores actions) | ||
use_ai: bool = False | ||
#: Player name | ||
name: str = "" | ||
#: Camera mode (AUTO, ON, OFF). By default, only non-AI agents get a camera | ||
camera_mode: CameraMode = CameraMode.AUTO | ||
|
||
|
||
class ActionObservationWrapper(Wrapper[ObsType, WrapperActType, ObsType, ActType]): | ||
"""Combines action and observation wrapper""" | ||
|
||
def action(self, action: WrapperActType) -> ActType: | ||
raise NotImplementedError | ||
|
||
def observation(self, observation: ObsType) -> WrapperObsType: | ||
raise NotImplementedError | ||
|
||
def __init__(self, env: gym.Env[ObsType, ActType]): | ||
"""Constructor for the action wrapper.""" | ||
Wrapper.__init__(self, env) | ||
|
||
def reset( | ||
self, *, seed: Optional[int] = None, options: Optional[Dict[str, Any]] = None | ||
) -> Tuple[WrapperObsType, Dict[str, Any]]: | ||
"""Modifies the :attr:`env` after calling :meth:`reset`, returning a | ||
modified observation using :meth:`self.observation`.""" | ||
obs, info = self.env.reset(seed=seed, options=options) | ||
return self.observation(obs), info | ||
|
||
def step( | ||
self, action: ActType | ||
) -> Tuple[WrapperObsType, SupportsFloat, bool, bool, Dict[str, Any]]: | ||
"""Modifies the :attr:`env` after calling :meth:`step` using | ||
:meth:`self.observation` on the returned observations.""" | ||
action = self.action(action) | ||
observation, reward, terminated, truncated, info = self.env.step(action) | ||
return self.observation(observation), reward, terminated, truncated, info |
Oops, something went wrong.