paddlepaddle百度飞桨七日打卡营——强化学习parl##
百度七日打卡营来到了强化学习领域,主要学习parl等工具,非常给力。话不多说,奥利给!
作业任务实现Sarsa算法玩迷宫游戏
预期效果:最终输出的 test reward 为1.0
加粗样式Step1 安装依赖
!pip install gym
Step2 导入依赖
import gym
import numpy as np
import time
Step3 Agent
Agent是和环境environment交互的主体。
predict()方法:输入观察值observation(或者说状态state),输出动作值
sample()方法:在predict()方法基础上使用ε-greedy增加探索
learn()方法:输入训练数据,完成一轮Q表格的更新
class SarsaAgent(object):
def __init__(self, obs_n, act_n, learning_rate=0.01, gamma=0.9, e_greed=0.1):
self.act_n = act_n # 动作维度,有几个动作可选
self.lr = learning_rate # 学习率
self.gamma = gamma # reward的衰减率
self.epsilon = e_greed # 按一定概率随机选动作
self.Q = np.zeros((obs_n, act_n))
# 根据输入观察值,采样输出的动作值,带探索
def sample(self, obs):
if np.random.uniform(0,1) < (1.0 - self.epsilon):
action = self.predict(obs)
else:
action = np.random.choice(self.act_n)
return action
# 根据输入观察值,预测输出的动作值
def predict(self, obs):
Q_list = self.Q[obs, :]
maxQ = np.max(Q_list)
action_list = np.where(Q_list == maxQ)[0]
action = np.random.choice(action_list)
return action
# 学习方法,也就是更新Q-table的方法
def learn(self, obs, action, reward, next_obs, next_action, done):
""" on-policy
obs: 交互前的obs, s_t
action: 本次交互选择的action, a_t
reward: 本次动作获得的奖励r
next_obs: 本次交互后的obs, s_t+1
next_action: 根据当前Q表格, 针对next_obs会选择的动作, a_t+1
done: episode是否结束
"""
predict_Q = self.Q[obs,action]
if done:
target_Q = reward
else:
target_Q = reward + self.gamma * self.Q[next_obs,next_action]
self.Q[obs,action] += self.lr * (target_Q - predict_Q)
# 保存Q表格数据到文件
def save(self):
npy_file = './q_table.npy'
np.save(npy_file, self.Q)
print(npy_file + ' saved.')
# 从文件中读取数据到Q表格中
def restore(self, npy_file='./q_table.npy'):
self.Q = np.load(npy_file)
print(npy_file + ' loaded.')
Step4 Training && Test(训练&&测试)
def run_episode(env, agent, render=False):
total_steps = 0 # 记录每个episode走了多少step
total_reward = 0
obs = env.reset() # 重置环境, 重新开一局(即开始新的一个episode)
action = agent.sample(obs) # 根据算法选择一个动作
while True:
next_obs, reward, done, _ = env.step(action) # 与环境进行一个交互
next_action = agent.sample(next_obs) # 根据算法选择一个动作
# 训练 Sarsa 算法
agent.learn(obs, action, reward, next_obs, next_action, done)
action = next_action
obs = next_obs # 存储上一个观察值
total_reward += reward
total_steps += 1 # 计算step数
if render:
env.render() #渲染新的一帧图形
if done:
break
return total_reward, total_steps
def test_episode(env, agent):
total_reward = 0
obs = env.reset()
while True:
action = agent.predict(obs) # greedy
next_obs, reward, done, _ = env.step(action)
total_reward += reward
obs = next_obs
# time.sleep(0.5)
# env.render()
if done:
break
return total_reward
Step 5 创建环境和Agent,启动训练
# 使用gym创建迷宫环境,设置is_slippery为False降低环境难度
env = gym.make("FrozenLake-v0", is_slippery=False) # 0 left, 1 down, 2 right, 3 up
# 创建一个agent实例,输入超参数
agent = SarsaAgent(
obs_n=env.observation_space.n,
act_n=env.action_space.n,
learning_rate=0.1,
gamma=0.9,
e_greed=0.1)
# 训练500个episode,打印每个episode的分数
for episode in range(500):
ep_reward, ep_steps = run_episode(env, agent, False)
print('Episode %s: steps = %s , reward = %.1f' % (episode, ep_steps, ep_reward))
# 全部训练结束,查看算法效果
test_reward = test_episode(env, agent)
print('test reward = %.1f' % (test_reward))
运行结果:
Episode 0: steps = 11 , reward = 0.0
Episode 1: steps = 8 , reward = 0.0
Episode 2: steps = 7 , reward = 0.0
Episode 3: steps = 5 , reward = 0.0
Episode 4: steps = 8 , reward = 0.0
Episode 5: steps = 2 , reward = 0.0
Episode 6: steps = 9 , reward = 0.0
Episode 7: steps = 2 , reward = 0.0
Episode 8: steps = 12 , reward = 0.0
Episode 9: steps = 2 , reward = 0.0
Episode 10: steps = 18 , reward = 0.0
Episode 11: steps = 2 , reward = 0.0
Episode 12: steps = 3 , reward = 0.0
Episode 13: steps = 5 , reward = 0.0
Episode 14: steps = 5 , reward = 0.0
Episode 15: steps = 5 , reward = 0.0
Episode 16: steps = 2 , reward = 0.0
Episode 17: steps = 11 , reward = 0.0
Episode 18: steps = 12 , reward = 0.0
Episode 19: steps = 7 , reward = 0.0
Episode 20: steps = 11 , reward = 0.0
Episode 21: steps = 19 , reward = 0.0
Episode 22: steps = 3 , reward = 0.0
Episode 23: steps = 4 , reward = 0.0
Episode 24: steps = 28 , reward = 1.0
Episode 25: steps = 6 , reward = 0.0
Episode 26: steps = 5 , reward = 0.0
Episode 27: steps = 2 , reward = 0.0
Episode 28: steps = 16 , reward = 0.0
Episode 29: steps = 11 , reward = 0.0
Episode 30: steps = 12 , reward = 0.0
Episode 31: steps = 2 , reward = 0.0
Episode 32: steps = 5 , reward = 0.0
Episode 33: steps = 9 , reward = 0.0
Episode 34: steps = 5 , reward = 0.0
Episode 35: steps = 9 , reward = 0.0
Episode 36: steps = 4 , reward = 0.0
Episode 37: steps = 6 , reward = 0.0
Episode 38: steps = 6 , reward = 0.0
Episode 39: steps = 3 , reward = 0.0
Episode 40: steps = 5 , reward = 0.0
Episode 41: steps = 4 , reward = 0.0
Episode 42: steps = 13 , reward = 0.0
Episode 43: steps = 8 , reward = 0.0
Episode 44: steps = 16 , reward = 0.0
Episode 45: steps = 20 , reward = 0.0
Episode 46: steps = 6 , reward = 0.0
Episode 47: steps = 9 , reward = 0.0
Episode 48: steps = 10 , reward = 0.0
Episode 49: steps = 26 , reward = 0.0
Episode 50: steps = 11 , reward = 0.0
Episode 51: steps = 28 , reward = 0.0
Episode 52: steps = 3 , reward = 0.0
Episode 53: steps = 9 , reward = 1.0
Episode 54: steps = 5 , reward = 0.0
Episode 55: steps = 17 , reward = 0.0
Episode 56: steps = 5 , reward = 0.0
Episode 57: steps = 9 , reward = 0.0
Episode 58: steps = 6 , reward = 1.0
Episode 59: steps = 12 , reward = 0.0
Episode 60: steps = 3 , reward = 0.0
Episode 61: steps = 3 , reward = 0.0
Episode 62: steps = 2 , reward = 0.0
Episode 63: steps = 15 , reward = 0.0
Episode 64: steps = 5 , reward = 0.0
Episode 65: steps = 10 , reward = 0.0
Episode 66: steps = 6 , reward = 0.0
Episode 67: steps = 4 , reward = 0.0
Episode 68: steps = 10 , reward = 1.0
Episode 69: steps = 12 , reward = 1.0
Episode 70: steps = 9 , reward = 1.0
Episode 71: steps = 6 , reward = 1.0
Episode 72: steps = 6 , reward = 1.0
Episode 73: steps = 3 , reward = 0.0
Episode 74: steps = 8 , reward = 1.0
Episode 75: steps = 6 , reward = 1.0
Episode 76: steps = 8 , reward = 0.0
Episode 77: steps = 9 , reward = 1.0
Episode 78: steps = 10 , reward = 1.0
Episode 79: steps = 6 , reward = 1.0
Episode 80: steps = 6 , reward = 1.0
Episode 81: steps = 6 , reward = 1.0
Episode 82: steps = 6 , reward = 1.0
Episode 83: steps = 6 , reward = 0.0
Episode 84: steps = 6 , reward = 1.0
Episode 85: steps = 6 , reward = 1.0
Episode 86: steps = 6 , reward = 1.0
Episode 87: steps = 6 , reward = 1.0
Episode 88: steps = 6 , reward = 1.0
Episode 89: steps = 6 , reward = 0.0
Episode 90: steps = 6 , reward = 1.0
Episode 91: steps = 5 , reward = 0.0
Episode 92: steps = 6 , reward = 1.0
Episode 93: steps = 6 , reward = 1.0
Episode 94: steps = 6 , reward = 1.0
Episode 95: steps = 6 , reward = 1.0
Episode 96: steps = 6 , reward = 1.0
Episode 97: steps = 6 , reward = 1.0
Episode 98: steps = 6 , reward = 1.0
Episode 99: steps = 6 , reward = 1.0
Episode 100: steps = 6 , reward = 1.0
Episode 101: steps = 6 , reward = 1.0
Episode 102: steps = 7 , reward = 1.0
Episode 103: steps = 6 , reward = 1.0
Episode 104: steps = 8 , reward = 1.0
Episode 105: steps = 7 , reward = 1.0
Episode 106: steps = 2 , reward = 0.0
Episode 107: steps = 2 , reward = 0.0
Episode 108: steps = 3 , reward = 0.0
Episode 109: steps = 6 , reward = 1.0
Episode 110: steps = 6 , reward = 1.0
Episode 111: steps = 6 , reward = 1.0
Episode 112: steps = 2 , reward = 0.0
Episode 113: steps = 6 , reward = 1.0
Episode 114: steps = 6 , reward = 1.0
Episode 115: steps = 6 , reward = 1.0
Episode 116: steps = 2 , reward = 0.0
Episode 117: steps = 6 , reward = 1.0
Episode 118: steps = 6 , reward = 1.0
Episode 119: steps = 6 , reward = 1.0
Episode 120: steps = 6 , reward = 1.0
Episode 121: steps = 6 , reward = 1.0
Episode 122: steps = 6 , reward = 1.0
Episode 123: steps = 6 , reward = 1.0
Episode 124: steps = 6 , reward = 1.0
Episode 125: steps = 2 , reward = 0.0
Episode 126: steps = 8 , reward = 1.0
Episode 127: steps = 6 , reward = 1.0
Episode 128: steps = 7 , reward = 1.0
Episode 129: steps = 2 , reward = 0.0
Episode 130: steps = 6 , reward = 1.0
Episode 131: steps = 6 , reward = 0.0
Episode 132: steps = 6 , reward = 1.0
Episode 133: steps = 6 , reward = 1.0
Episode 134: steps = 6 , reward = 0.0
Episode 135: steps = 6 , reward = 1.0
Episode 136: steps = 7 , reward = 1.0
Episode 137: steps = 6 , reward = 1.0
Episode 138: steps = 6 , reward = 1.0
Episode 139: steps = 4 , reward = 0.0
Episode 140: steps = 6 , reward = 1.0
Episode 141: steps = 6 , reward = 1.0
Episode 142: steps = 6 , reward = 1.0
Episode 143: steps = 6 , reward = 1.0
Episode 144: steps = 6 , reward = 1.0
Episode 145: steps = 6 , reward = 1.0
Episode 146: steps = 6 , reward = 1.0
Episode 147: steps = 8 , reward = 1.0
Episode 148: steps = 6 , reward = 1.0
Episode 149: steps = 6 , reward = 1.0
Episode 150: steps = 10 , reward = 1.0
Episode 151: steps = 6 , reward = 1.0
Episode 152: steps = 6 , reward = 1.0
Episode 153: steps = 6 , reward = 1.0
Episode 154: steps = 6 , reward = 1.0
Episode 155: steps = 7 , reward = 1.0
Episode 156: steps = 8 , reward = 1.0
Episode 157: steps = 6 , reward = 1.0
Episode 158: steps = 6 , reward = 1.0
Episode 159: steps = 4 , reward = 0.0
Episode 160: steps = 6 , reward = 1.0
Episode 161: steps = 6 , reward = 1.0
Episode 162: steps = 7 , reward = 1.0
Episode 163: steps = 6 , reward = 1.0
Episode 164: steps = 6 , reward = 1.0
Episode 165: steps = 6 , reward = 1.0
Episode 166: steps = 6 , reward = 1.0
Episode 167: steps = 6 , reward = 1.0
Episode 168: steps = 6 , reward = 1.0
Episode 169: steps = 4 , reward = 0.0
Episode 170: steps = 6 , reward = 1.0
Episode 171: steps = 6 , reward = 1.0
Episode 172: steps = 6 , reward = 1.0
Episode 173: steps = 8 , reward = 1.0
Episode 174: steps = 6 , reward = 1.0
Episode 175: steps = 6 , reward = 1.0
Episode 176: steps = 6 , reward = 1.0
Episode 177: steps = 6 , reward = 1.0
Episode 178: steps = 6 , reward = 1.0
Episode 179: steps = 10 , reward = 1.0
Episode 180: steps = 6 , reward = 1.0
Episode 181: steps = 6 , reward = 1.0
Episode 182: steps = 9 , reward = 1.0
Episode 183: steps = 6 , reward = 1.0
Episode 184: steps = 6 , reward = 1.0
Episode 185: steps = 6 , reward = 1.0
Episode 186: steps = 6 , reward = 1.0
Episode 187: steps = 9 , reward = 0.0
Episode 188: steps = 6 , reward = 1.0
Episode 189: steps = 4 , reward = 0.0
Episode 190: steps = 6 , reward = 1.0
Episode 191: steps = 6 , reward = 1.0
Episode 192: steps = 6 , reward = 1.0
Episode 193: steps = 6 , reward = 1.0
Episode 194: steps = 10 , reward = 1.0
Episode 195: steps = 4 , reward = 0.0
Episode 196: steps = 6 , reward = 1.0
Episode 197: steps = 6 , reward = 0.0
Episode 198: steps = 6 , reward = 1.0
Episode 199: steps = 6 , reward = 1.0
Episode 200: steps = 5 , reward = 0.0
Episode 201: steps = 6 , reward = 1.0
Episode 202: steps = 6 , reward = 1.0
Episode 203: steps = 8 , reward = 1.0
Episode 204: steps = 6 , reward = 1.0
Episode 205: steps = 6 , reward = 1.0
Episode 206: steps = 6 , reward = 1.0
Episode 207: steps = 6 , reward = 1.0
Episode 208: steps = 6 , reward = 1.0
Episode 209: steps = 6 , reward = 1.0
Episode 210: steps = 6 , reward = 1.0
Episode 211: steps = 6 , reward = 1.0
Episode 212: steps = 6 , reward = 1.0
Episode 213: steps = 6 , reward = 1.0
Episode 214: steps = 2 , reward = 0.0
Episode 215: steps = 6 , reward = 1.0
Episode 216: steps = 7 , reward = 1.0
Episode 217: steps = 6 , reward = 1.0
Episode 218: steps = 11 , reward = 0.0
Episode 219: steps = 9 , reward = 1.0
Episode 220: steps = 6 , reward = 1.0
Episode 221: steps = 6 , reward = 1.0
Episode 222: steps = 6 , reward = 1.0
Episode 223: steps = 7 , reward = 1.0
Episode 224: steps = 6 , reward = 1.0
Episode 225: steps = 6 , reward = 1.0
Episode 226: steps = 6 , reward = 1.0
Episode 227: steps = 6 , reward = 1.0
Episode 228: steps = 6 , reward = 1.0
Episode 229: steps = 8 , reward = 1.0
Episode 230: steps = 6 , reward = 1.0
Episode 231: steps = 8 , reward = 1.0
Episode 232: steps = 6 , reward = 1.0
Episode 233: steps = 6 , reward = 1.0
Episode 234: steps = 6 , reward = 1.0
Episode 235: steps = 6 , reward = 1.0
Episode 236: steps = 6 , reward = 1.0
Episode 237: steps = 6 , reward = 1.0
Episode 238: steps = 6 , reward = 1.0
Episode 239: steps = 6 , reward = 1.0
Episode 240: steps = 6 , reward = 1.0
Episode 241: steps = 10 , reward = 1.0
Episode 242: steps = 6 , reward = 1.0
Episode 243: steps = 6 , reward = 1.0
Episode 244: steps = 6 , reward = 1.0
Episode 245: steps = 6 , reward = 1.0
Episode 246: steps = 6 , reward = 1.0
Episode 247: steps = 6 , reward = 1.0
Episode 248: steps = 6 , reward = 0.0
Episode 249: steps = 6 , reward = 1.0
Episode 250: steps = 6 , reward = 1.0
Episode 251: steps = 6 , reward = 1.0
Episode 252: steps = 6 , reward = 1.0
Episode 253: steps = 6 , reward = 1.0
Episode 254: steps = 6 , reward = 1.0
Episode 255: steps = 7 , reward = 1.0
Episode 256: steps = 7 , reward = 1.0
Episode 257: steps = 6 , reward = 1.0
Episode 258: steps = 6 , reward = 1.0
Episode 259: steps = 6 , reward = 1.0
Episode 260: steps = 11 , reward = 1.0
Episode 261: steps = 6 , reward = 1.0
Episode 262: steps = 10 , reward = 1.0
Episode 263: steps = 6 , reward = 1.0
Episode 264: steps = 6 , reward = 1.0
Episode 265: steps = 7 , reward = 1.0
Episode 266: steps = 2 , reward = 0.0
Episode 267: steps = 6 , reward = 1.0
Episode 268: steps = 6 , reward = 1.0
Episode 269: steps = 10 , reward = 1.0
Episode 270: steps = 6 , reward = 1.0
Episode 271: steps = 6 , reward = 1.0
Episode 272: steps = 6 , reward = 1.0
Episode 273: steps = 2 , reward = 0.0
Episode 274: steps = 8 , reward = 1.0
Episode 275: steps = 7 , reward = 1.0
Episode 276: steps = 6 , reward = 1.0
Episode 277: steps = 6 , reward = 1.0
Episode 278: steps = 6 , reward = 1.0
Episode 279: steps = 6 , reward = 0.0
Episode 280: steps = 6 , reward = 1.0
Episode 281: steps = 10 , reward = 1.0
Episode 282: steps = 7 , reward = 1.0
Episode 283: steps = 7 , reward = 1.0
Episode 284: steps = 6 , reward = 1.0
Episode 285: steps = 4 , reward = 0.0
Episode 286: steps = 6 , reward = 1.0
Episode 287: steps = 5 , reward = 0.0
Episode 288: steps = 6 , reward = 1.0
Episode 289: steps = 7 , reward = 1.0
Episode 290: steps = 6 , reward = 0.0
Episode 291: steps = 8 , reward = 1.0
Episode 292: steps = 6 , reward = 1.0
Episode 293: steps = 6 , reward = 1.0
Episode 294: steps = 6 , reward = 1.0
Episode 295: steps = 8 , reward = 1.0
Episode 296: steps = 6 , reward = 1.0
Episode 297: steps = 5 , reward = 0.0
Episode 298: steps = 7 , reward = 1.0
Episode 299: steps = 6 , reward = 1.0
Episode 300: steps = 4 , reward = 0.0
Episode 301: steps = 6 , reward = 1.0
Episode 302: steps = 8 , reward = 1.0
Episode 303: steps = 6 , reward = 1.0
Episode 304: steps = 6 , reward = 1.0
Episode 305: steps = 6 , reward = 1.0
Episode 306: steps = 6 , reward = 1.0
Episode 307: steps = 7 , reward = 1.0
Episode 308: steps = 2 , reward = 0.0
Episode 309: steps = 12 , reward = 1.0
Episode 310: steps = 8 , reward = 1.0
Episode 311: steps = 6 , reward = 1.0
Episode 312: steps = 6 , reward = 1.0
Episode 313: steps = 8 , reward = 1.0
Episode 314: steps = 9 , reward = 1.0
Episode 315: steps = 5 , reward = 0.0
Episode 316: steps = 2 , reward = 0.0
Episode 317: steps = 8 , reward = 1.0
Episode 318: steps = 10 , reward = 1.0
Episode 319: steps = 7 , reward = 1.0
Episode 320: steps = 6 , reward = 1.0
Episode 321: steps = 6 , reward = 1.0
Episode 322: steps = 6 , reward = 1.0
Episode 323: steps = 6 , reward = 1.0
Episode 324: steps = 6 , reward = 1.0
Episode 325: steps = 6 , reward = 1.0
Episode 326: steps = 6 , reward = 1.0
Episode 327: steps = 5 , reward = 0.0
Episode 328: steps = 2 , reward = 0.0
Episode 329: steps = 6 , reward = 1.0
Episode 330: steps = 2 , reward = 0.0
Episode 331: steps = 6 , reward = 1.0
Episode 332: steps = 6 , reward = 1.0
Episode 333: steps = 6 , reward = 1.0
Episode 334: steps = 6 , reward = 1.0
Episode 335: steps = 6 , reward = 1.0
Episode 336: steps = 10 , reward = 1.0
Episode 337: steps = 7 , reward = 1.0
Episode 338: steps = 7 , reward = 1.0
Episode 339: steps = 6 , reward = 1.0
Episode 340: steps = 6 , reward = 1.0
Episode 341: steps = 6 , reward = 1.0
Episode 342: steps = 9 , reward = 1.0
Episode 343: steps = 6 , reward = 1.0
Episode 344: steps = 10 , reward = 1.0
Episode 345: steps = 6 , reward = 1.0
Episode 346: steps = 9 , reward = 1.0
Episode 347: steps = 6 , reward = 1.0
Episode 348: steps = 9 , reward = 1.0
Episode 349: steps = 6 , reward = 1.0
Episode 350: steps = 8 , reward = 1.0
Episode 351: steps = 6 , reward = 1.0
Episode 352: steps = 8 , reward = 1.0
Episode 353: steps = 6 , reward = 1.0
Episode 354: steps = 6 , reward = 1.0
Episode 355: steps = 6 , reward = 1.0
Episode 356: steps = 8 , reward = 1.0
Episode 357: steps = 5 , reward = 0.0
Episode 358: steps = 4 , reward = 0.0
Episode 359: steps = 8 , reward = 1.0
Episode 360: steps = 8 , reward = 1.0
Episode 361: steps = 8 , reward = 1.0
Episode 362: steps = 4 , reward = 0.0
Episode 363: steps = 6 , reward = 1.0
Episode 364: steps = 6 , reward = 1.0
Episode 365: steps = 6 , reward = 1.0
Episode 366: steps = 8 , reward = 1.0
Episode 367: steps = 7 , reward = 1.0
Episode 368: steps = 6 , reward = 1.0
Episode 369: steps = 8 , reward = 1.0
Episode 370: steps = 6 , reward = 0.0
Episode 371: steps = 6 , reward = 1.0
Episode 372: steps = 6 , reward = 1.0
Episode 373: steps = 6 , reward = 1.0
Episode 374: steps = 6 , reward = 1.0
Episode 375: steps = 6 , reward = 1.0
Episode 376: steps = 8 , reward = 1.0
Episode 377: steps = 5 , reward = 0.0
Episode 378: steps = 7 , reward = 0.0
Episode 379: steps = 6 , reward = 1.0
Episode 380: steps = 6 , reward = 1.0
Episode 381: steps = 6 , reward = 1.0
Episode 382: steps = 2 , reward = 0.0
Episode 383: steps = 6 , reward = 1.0
Episode 384: steps = 7 , reward = 1.0
Episode 385: steps = 8 , reward = 1.0
Episode 386: steps = 12 , reward = 1.0
Episode 387: steps = 6 , reward = 1.0
Episode 388: steps = 8 , reward = 1.0
Episode 389: steps = 11 , reward = 1.0
Episode 390: steps = 6 , reward = 1.0
Episode 391: steps = 6 , reward = 1.0
Episode 392: steps = 7 , reward = 1.0
Episode 393: steps = 6 , reward = 1.0
Episode 394: steps = 4 , reward = 0.0
Episode 395: steps = 6 , reward = 1.0
Episode 396: steps = 6 , reward = 1.0
Episode 397: steps = 6 , reward = 1.0
Episode 398: steps = 5 , reward = 0.0
Episode 399: steps = 6 , reward = 1.0
Episode 400: steps = 6 , reward = 1.0
Episode 401: steps = 6 , reward = 1.0
Episode 402: steps = 6 , reward = 1.0
Episode 403: steps = 8 , reward = 1.0
Episode 404: steps = 6 , reward = 1.0
Episode 405: steps = 6 , reward = 1.0
Episode 406: steps = 6 , reward = 1.0
Episode 407: steps = 6 , reward = 1.0
Episode 408: steps = 7 , reward = 0.0
Episode 409: steps = 6 , reward = 1.0
Episode 410: steps = 8 , reward = 1.0
Episode 411: steps = 6 , reward = 1.0
Episode 412: steps = 8 , reward = 1.0
Episode 413: steps = 6 , reward = 1.0
Episode 414: steps = 6 , reward = 1.0
Episode 415: steps = 6 , reward = 1.0
Episode 416: steps = 6 , reward = 1.0
Episode 417: steps = 6 , reward = 1.0
Episode 418: steps = 7 , reward = 1.0
Episode 419: steps = 6 , reward = 1.0
Episode 420: steps = 7 , reward = 1.0
Episode 421: steps = 8 , reward = 1.0
Episode 422: steps = 6 , reward = 1.0
Episode 423: steps = 6 , reward = 1.0
Episode 424: steps = 9 , reward = 1.0
Episode 425: steps = 6 , reward = 1.0
Episode 426: steps = 7 , reward = 1.0
Episode 427: steps = 5 , reward = 0.0
Episode 428: steps = 6 , reward = 1.0
Episode 429: steps = 6 , reward = 1.0
Episode 430: steps = 6 , reward = 1.0
Episode 431: steps = 4 , reward = 0.0
Episode 432: steps = 6 , reward = 1.0
Episode 433: steps = 6 , reward = 1.0
Episode 434: steps = 6 , reward = 1.0
Episode 435: steps = 6 , reward = 1.0
Episode 436: steps = 6 , reward = 1.0
Episode 437: steps = 6 , reward = 1.0
Episode 438: steps = 7 , reward = 1.0
Episode 439: steps = 6 , reward = 1.0
Episode 440: steps = 6 , reward = 1.0
Episode 441: steps = 6 , reward = 1.0
Episode 442: steps = 6 , reward = 1.0
Episode 443: steps = 8 , reward = 1.0
Episode 444: steps = 6 , reward = 1.0
Episode 445: steps = 6 , reward = 1.0
Episode 446: steps = 6 , reward = 1.0
Episode 447: steps = 6 , reward = 1.0
Episode 448: steps = 6 , reward = 1.0
Episode 449: steps = 8 , reward = 1.0
Episode 450: steps = 6 , reward = 1.0
Episode 451: steps = 6 , reward = 1.0
Episode 452: steps = 9 , reward = 1.0
Episode 453: steps = 6 , reward = 1.0
Episode 454: steps = 4 , reward = 0.0
Episode 455: steps = 8 , reward = 1.0
Episode 456: steps = 10 , reward = 1.0
Episode 457: steps = 6 , reward = 1.0
Episode 458: steps = 2 , reward = 0.0
Episode 459: steps = 6 , reward = 1.0
Episode 460: steps = 9 , reward = 1.0
Episode 461: steps = 6 , reward = 1.0
Episode 462: steps = 6 , reward = 1.0
Episode 463: steps = 9 , reward = 1.0
Episode 464: steps = 6 , reward = 1.0
Episode 465: steps = 6 , reward = 1.0
Episode 466: steps = 6 , reward = 1.0
Episode 467: steps = 9 , reward = 1.0
Episode 468: steps = 6 , reward = 1.0
Episode 469: steps = 6 , reward = 1.0
Episode 470: steps = 6 , reward = 1.0
Episode 471: steps = 6 , reward = 1.0
Episode 472: steps = 2 , reward = 0.0
Episode 473: steps = 6 , reward = 1.0
Episode 474: steps = 8 , reward = 1.0
Episode 475: steps = 6 , reward = 0.0
Episode 476: steps = 6 , reward = 1.0
Episode 477: steps = 8 , reward = 1.0
Episode 478: steps = 7 , reward = 1.0
Episode 479: steps = 6 , reward = 1.0
Episode 480: steps = 6 , reward = 1.0
Episode 481: steps = 8 , reward = 1.0
Episode 482: steps = 7 , reward = 1.0
Episode 483: steps = 8 , reward = 1.0
Episode 484: steps = 6 , reward = 1.0
Episode 485: steps = 2 , reward = 0.0
Episode 486: steps = 6 , reward = 1.0
Episode 487: steps = 6 , reward = 1.0
Episode 488: steps = 7 , reward = 1.0
Episode 489: steps = 6 , reward = 1.0
Episode 490: steps = 6 , reward = 1.0
Episode 491: steps = 2 , reward = 0.0
Episode 492: steps = 6 , reward = 1.0
Episode 493: steps = 6 , reward = 1.0
Episode 494: steps = 6 , reward = 1.0
Episode 495: steps = 6 , reward = 1.0
Episode 496: steps = 6 , reward = 1.0
Episode 497: steps = 8 , reward = 1.0
Episode 498: steps = 4 , reward = 0.0
Episode 499: steps = 6 , reward = 1.0
test reward = 1.0
完全收敛到1.0,OK