Last active
October 14, 2019 10:34
-
-
Save pythonlessons/63e6d67b264143e850f8e52605ea4ec4 to your computer and use it in GitHub Desktop.
ramdp CartPole environment
This file contains hidden or 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
| import gym | |
| import random | |
| env = gym.make("CartPole-v0") | |
| env.reset() | |
| def Random_games(): | |
| # Each of this episode is its own game. | |
| for episode in range(10): | |
| env.reset() | |
| # this is each frame, up to 500...but we wont make it that far with random. | |
| for t in range(500): | |
| # This will display the environment | |
| # Only display if you really want to see it. | |
| # Takes much longer to display it. | |
| env.render() | |
| # This will just create a sample action in any environment. | |
| # In this environment, the action can be 0 or 1, which is left or right | |
| action = env.action_space.sample() | |
| # this executes the environment with an action, | |
| # and returns the observation of the environment, | |
| # the reward, if the env is over, and other info. | |
| next_state, reward, done, info = env.step(action) | |
| # lets print everything in one line: | |
| print(t, next_state, reward, done, info, action) | |
| if done: | |
| break | |
| Random_games() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment