Skip to content

Commit

Permalink
Merge pull request #271 from huangshiyu13/main
Browse files Browse the repository at this point in the history
fix rock paper scissors
  • Loading branch information
huangshiyu13 authored Nov 10, 2023
2 parents b44efad + 3e0d644 commit b71b07b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/custom_env/pettingzoo_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from openrl.selfplay.wrappers.random_opponent_wrapper import RandomOpponentWrapper

register("RockPaperScissors", RockPaperScissors)

env = make(
"RockPaperScissors",
env_num=10,
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_env/rock_paper_scissors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RockPaperScissors(AECEnv):

metadata = {"render_modes": ["human"], "name": "rps_v2"}

def __init__(self, render_mode=None):
def __init__(self, id, render_mode=None):
"""
The init method takes in environment arguments and
should define the following attributes:
Expand Down Expand Up @@ -122,8 +122,8 @@ def observe(self, agent):
"""
# observation of one agent is the previous state of the other
# return np.array(self.observations[agent])
obs = np.zeros(4, dtype=np.int64)
obs[self.observations[agent]] = 1
obs = np.zeros([1, 4], dtype=np.int64)
obs[0, self.observations[agent]] = 1
return obs

def close(self):
Expand Down
12 changes: 10 additions & 2 deletions openrl/selfplay/wrappers/base_multiplayer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ def _step(self, action):
if termination or truncation:
return (
copy.copy(self.env.observe(self.self_player)),
self.env.rewards[self.self_player],
(
self.env.rewards[self.self_player]
if self.self_player in self.env.rewards
else 0
),
termination,
truncation,
self.env.infos[self.self_player],
(
self.env.infos[self.self_player]
if self.self_player in self.env.rewards
else {}
),
)

else:
Expand Down

0 comments on commit b71b07b

Please sign in to comment.