https://github.com/ParkGyeongTae/dqn-atari-breakout/tree/main/2_cartpole-v1
### Step 1) 아나콘다 가상환경 만들기
conda create -n py37 python=3.7
### Step 2) 가상환경 접속
conda activate py37
### Step 3) 라이브러리 설치
pip install gym==0.23.1
pip install pygame==2.1.2
pip install tensorflow==2.8.0
pip install keras==2.8.0
pip install torch==1.11.0
pip install matplotlib==3.5.1
1_cartpole-v1-reward.py
import gym
import random
env = gym.make('CartPole-v1')
max_time_step = 100
episode_numbers = 10
random_action = random.randrange(0, 2)
for episode in range(episode_numbers):
observation = env.reset()
rewards = 0
for time_step in range(max_time_step):
env.render()
observation, reward, done, info = env.step(random_action)
rewards += reward
if done:
print("episode :", episode + 1, ", rewards :", rewards)
break
env.close()
python 1_cartpole-v1-reward.py