Skip to content

Commit

Permalink
chore: Fix performance test, add preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
strakam committed Oct 27, 2024
1 parent e01bbfd commit 57bb531
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Binary file added generals/assets/images/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified generals/assets/images/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 16 additions & 6 deletions tests/parallel_api_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
parallel_to_aec_wrapper,
turn_based_aec_to_parallel_wrapper,
)
from generals.envs import PettingZooGenerals
from pettingzoo.utils.env import ActionType, AgentID, ObsType, ParallelEnv
from pettingzoo.utils.wrappers import BaseWrapper

Expand All @@ -28,12 +29,22 @@ def sample_action(
# pick random index of the mask with a 1, it should be 3 numbers
valid_actions = np.argwhere(mask == 1)
if len(valid_actions) == 0:
return (1, np.array([0, 0]), 0, 0)
return {
"pass": 1,
"cell": np.array([0, 0]),
"direction": 0,
"split": 0,
}
action_index = np.random.choice(len(valid_actions))
action = valid_actions[action_index]
cell = action[:2]
direction = action[2]
return (0, cell, direction, 0)
return {
"pass": 0,
"cell": cell,
"direction": direction,
"split": 0,
}
return env.action_space(agent).sample()


Expand Down Expand Up @@ -128,14 +139,13 @@ def parallel_api_test(par_env: ParallelEnv, num_cycles=1000):


if __name__ == "__main__":
mapper = GridFactory()
agent1 = AgentFactory.make_agent("expander", id="A")
agent2 = AgentFactory.make_agent("random", id="B")
agent1 = AgentFactory.make_agent("Expander", id="A")
agent2 = AgentFactory.make_agent("Random", id="B")
agents = {
agent1.id: agent1,
agent2.id: agent2,
}
env = gym.make("pz-generals-v0", agents=list(agents.keys()), grid_factory=mapper)
env = PettingZooGenerals(agents=agents, render_mode=None)
# test the environment with parallel_api_test
import time

Expand Down

0 comments on commit 57bb531

Please sign in to comment.