Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

特徴量を出す関数をobservationに追加(py) #1096

Merged
merged 22 commits into from
Aug 21, 2022

Conversation

OkanoShinri
Copy link
Collaborator

@OkanoShinri
Copy link
Collaborator Author

スクリーンショット 2022-07-27 190239

@OkanoShinri
Copy link
Collaborator Author

State -> Observation変換

def state2obs(state_json: str, who: int) -> Observation:
    state = State(state_json)
    state_proto = state.to_proto()
    observation_proto = mjxproto.Observation()
    # who
    observation_proto.who = who

    # public
    observation_proto.public_observation.CopyFrom(state_proto.public_observation)

    # private
    observation_proto.private_observation.CopyFrom(state_proto.private_observations[who])

    # round_terminal
    observation_proto.round_terminal.CopyFrom(state_proto.round_terminal)

    observation = Observation(
        Observation.add_legal_actions(Observation.from_proto(observation_proto).to_json())
    )
    return observation

現状のmjxを動かすスクリプト

readmeのままでは対応していない

from mjx import MjxEnv
from mjx.agent import RandomAgent

agent = RandomAgent()
env = MjxEnv()
_reset=list(env.reset().items())[0]
player_id=_reset[0] 
observation=_reset[1]
while not env.done():
    action = agent.act(observation)
    _step=list(env.step({player_id:action}).items())[0]
    player_id=_step[0] 
    observation=_step[1]
rewards = env.rewards()

@@ -125,6 +127,238 @@ def show(self, view_idx: Optional[int] = None) -> None:
observation = self.to_proto()
show_svg(observation, target_idx=view_idx)

def get_feature(self) -> np.ndarray:
Copy link
Collaborator

@sotetsuk sotetsuk Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_feature(self) -> np.ndarray:
def _get_han22_features(self) -> np.ndarray:

@OkanoShinri OkanoShinri merged commit 4934254 into master Aug 21, 2022
@OkanoShinri OkanoShinri deleted the okano/feat/mj-feature branch August 21, 2022 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants