mirror of
https://github.com/wassname/ray.git
synced 2026-09-09 11:32:43 +08:00
[RLlib] Unity3D integration (n Unity3D clients vs learning server). (#8590)
This commit is contained in:
Vendored
+8
-4
@@ -4,12 +4,16 @@ from ray.rllib.env.multi_agent_env import MultiAgentEnv
|
||||
from ray.rllib.tests.test_rollout_worker import MockEnv, MockEnv2
|
||||
|
||||
|
||||
def make_multiagent(env_name):
|
||||
def make_multiagent(env_name_or_creator):
|
||||
class MultiEnv(MultiAgentEnv):
|
||||
def __init__(self, config):
|
||||
self.agents = [
|
||||
gym.make(env_name) for _ in range(config["num_agents"])
|
||||
]
|
||||
num = config.pop("num_agents", 1)
|
||||
if isinstance(env_name_or_creator, str):
|
||||
self.agents = [
|
||||
gym.make(env_name_or_creator) for _ in range(num)
|
||||
]
|
||||
else:
|
||||
self.agents = [env_name_or_creator(config) for _ in range(num)]
|
||||
self.dones = set()
|
||||
self.observation_space = self.agents[0].observation_space
|
||||
self.action_space = self.agents[0].action_space
|
||||
|
||||
Vendored
+9
-3
@@ -1,7 +1,9 @@
|
||||
import gym
|
||||
from gym.spaces import Tuple
|
||||
from gym.spaces import Discrete, Tuple
|
||||
import numpy as np
|
||||
|
||||
from ray.rllib.examples.env.multi_agent import make_multiagent
|
||||
|
||||
|
||||
class RandomEnv(gym.Env):
|
||||
"""A randomly acting environment.
|
||||
@@ -14,9 +16,9 @@ class RandomEnv(gym.Env):
|
||||
|
||||
def __init__(self, config):
|
||||
# Action space.
|
||||
self.action_space = config["action_space"]
|
||||
self.action_space = config.get("action_space", Discrete(2))
|
||||
# Observation space from which to sample.
|
||||
self.observation_space = config["observation_space"]
|
||||
self.observation_space = config.get("observation_space", Discrete(2))
|
||||
# Reward space from which to sample.
|
||||
self.reward_space = config.get(
|
||||
"reward_space",
|
||||
@@ -43,3 +45,7 @@ class RandomEnv(gym.Env):
|
||||
bool(np.random.choice(
|
||||
[True, False], p=[self.p_done, 1.0 - self.p_done]
|
||||
)), {}
|
||||
|
||||
|
||||
# Multi-agent version of the RandomEnv.
|
||||
RandomMultiAgentEnv = make_multiagent(lambda c: RandomEnv(c))
|
||||
|
||||
Reference in New Issue
Block a user