-
Notifications
You must be signed in to change notification settings - Fork 6
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
13 changed files
with
133 additions
and
489 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
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
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 |
---|---|---|
@@ -1,17 +1,28 @@ | ||
# type: ignore | ||
import gymnasium as gym | ||
import numpy as np | ||
|
||
from generals.agents import RandomAgent, ExpanderAgent | ||
from generals.envs import GymnasiumGenerals | ||
|
||
# Initialize agents | ||
agent = RandomAgent() | ||
npc = ExpanderAgent() | ||
agent_names = ["007", "Generalissimo"] | ||
|
||
# Create environment | ||
env = gym.make("gym-generals-v0", agent=agent, npc=npc, render_mode="human") | ||
n_envs = 12 | ||
envs = gym.vector.AsyncVectorEnv( | ||
[lambda: GymnasiumGenerals(agents=agent_names, truncation=500) for _ in range(n_envs)], | ||
) | ||
|
||
observation, info = env.reset() | ||
terminated = truncated = False | ||
while not (terminated or truncated): | ||
action = agent.act(observation) | ||
observation, reward, terminated, truncated, info = env.step(action) | ||
env.render() | ||
|
||
observations, infos = envs.reset() | ||
terminated = [False] * len(observations) | ||
truncated = [False] * len(observations) | ||
|
||
while True: | ||
agent_actions = [envs.single_action_space.sample() for _ in range(n_envs)] | ||
npc_actions = [envs.single_action_space.sample() for _ in range(n_envs)] | ||
|
||
# Stack actions together | ||
actions = np.stack([agent_actions, npc_actions], axis=1) | ||
observations, rewards, terminated, truncated, infos = envs.step(actions) | ||
masks = [np.stack([info[-1] for info in infos[agent_name]]) for agent_name in agent_names] | ||
if any(terminated) or any(truncated): | ||
break |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,39 +1,18 @@ | ||
from gymnasium.envs.registration import register | ||
|
||
from generals.agents.agent import Agent | ||
from generals.core.game import Action | ||
from generals.core.grid import Grid, GridFactory | ||
from generals.core.observation import Observation | ||
from generals.core.replay import Replay | ||
from generals.envs.gymnasium_generals import GymnasiumGenerals | ||
from generals.envs.pettingzoo_generals import PettingZooGenerals | ||
|
||
__all__ = [ | ||
"Action", | ||
"Agent", | ||
"GridFactory", | ||
"PettingZooGenerals", | ||
"GymnasiumGenerals", | ||
"Grid", | ||
"Replay", | ||
"Observation", | ||
"GeneralsIOClientError", | ||
] | ||
|
||
|
||
def _register_gym_generals_envs(): | ||
register( | ||
id="gym-generals-v0", | ||
entry_point="generals.envs.gymnasium_generals:GymnasiumGenerals", | ||
) | ||
|
||
register( | ||
id="gym-generals-image-v0", | ||
entry_point="generals.envs.initializers:gym_image_observations", | ||
) | ||
|
||
register( | ||
id="gym-generals-rllib-v0", | ||
entry_point="generals.envs.initializers:gym_rllib", | ||
) | ||
|
||
|
||
_register_gym_generals_envs() |
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
# type: ignore | ||
from generals.envs.gymnasium_generals import GymnasiumGenerals | ||
from generals.envs.multiagent_gymnasium_generals import MultiAgentGymnasiumGenerals | ||
from generals.envs.pettingzoo_generals import PettingZooGenerals | ||
|
||
__all__ = [ | ||
"PettingZooGenerals", | ||
"GymnasiumGenerals", | ||
"MultiAgentGymnasiumGenerals", | ||
] |
Oops, something went wrong.