Student
Student

Reputation: 73

Start OpenAI gym on arbitrary initial state

Anybody knows any OpenAI Gym environments where we can set the initial state of the game? For example, I found the MountainCarContinuous-v0 can do such thing so that we can select at which point the car starts. However, I am looking for another more complex environment. Thanks in advance for your help!

Upvotes: 7

Views: 1610

Answers (1)

Simon
Simon

Reputation: 5422

You have to redefine the reset function of the class (for example, this). You may want to define it such that it gets as input your desired state, something like

def reset(self, state):
    self.state = state
    return np.array(self.state)

This should work for all OpenAI gym environments. If you want to do it for other simulators, things may be different. For instance, MuJoCo allows to do something like

saved_state = env.sim.get_state()
env.sim.set_state(saved_state)

Upvotes: 8

Related Questions