更新时间:2024-08-15 GMT+08:00

gym

在FunctionGraph 页面将gym添加为公共依赖

图1 gym添加为公共依赖

在代码中导入gym并使用

# 导入 gym 依赖
import gym
env = gym.make('CartPole-v0')
env.reset()
 
def handler(event,context):
    for _ in range(10):
        env.render()
        observation, reward, done, info, _ = env.step(env.action_space.sample()) # take a random action
        temp = env.step(env.action_space.sample()) # take a random action
        print('observation:{}, reward:{}, done:{}, info:{}'.format(observation, reward, done, info))
    env.close()