Enhanced learning Roman Games

Source: Internet
Author: User

The code found on the internet is easy to use in the test. Share the following.

Import gymimport timeenv = gym. make ('cartpole-v0') # obtain the game environment observation = Env. reset () # reset the game environment and print the game in a new game ('initial game observation = {}'. format (observation) for T in range (0, 200): Env. render () Action = Env. action_space.sample () # randomly select an action print ('{}: action = {}'. format (T, Action) observation, reward, done, info = Env. STEP (Action) # print the execution behavior ('{}: observation ={}, this step score ={}, end indicator ={}, other information = {}'. format (T, observation, reward, done, Info) if done: break time. sleep (1) # You can add or not, and then you can see the figure Env. close ()

 

 

 

 

 

The code for multiple rounds is as follows:

Import gymenv = gym. make ('cartpole-v0') n_episode = 20for I _episode in range (n_episode): Observation = Env. reset () episode_reward = 0 while true: # Env. render () Action = Env. action_space.sample () # randomly select observation, reward, done, _ = Env. STEP (Action) episode_reward + = reward state = observation if done: Break print ('score {}'. format (I _episode, episode_reward) ENV. close ()

 

This multi-round game has not been added to the drawing. If you need to draw, you can add env. Render.

 

Enhanced learning Roman Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.