我正在使用openai gym为21点制作一个AI。在
但我不擅长python和gym,所以我想知道如何完成代码。在
我一直在尝试写一个简单的代码,用Q-learning来制作人工智能。在
但我对开放式人工智能健身房和python还不够熟悉。在
我不知道如何检查一个州的大小(环境观测空间.n不起作用。。只有环境行动空间.n显示它的“2”) 我的代码有点像其他体育游戏的例子(frozenlake)
帮我完成这个简单的代码,这样我就可以像DQN一样自己改进了。在
import gym
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
env=gym.make('Blackjack-v0')
Q=np.zeros([400,env.action_space.n])
num_episodes=10000
dis=0.99
rList=[]
for i in range(num_episodes):
state = env.reset()
rALL = 0
done = False
while not done:
action=np.argmax(Q[state,:]+np.random.randn(1
,env.action_space.n)/(i+1))
new_state,reward,done,_=env.step(action)
Q[state, action] = reward + dis * np.max(Q[new_state, :])
print(rList)
rALL += reward
state = new_state
rList.append(rALL)\
print(Q)
我想看到奖励列表(rList)不断上升(如果我的算法有效)
同时也想知道如何使用健身模块。在
我将更新此回复,因为我完全理解您的需求
env.observation_space.n
来获得操作的数量,如果您使用的是最新版本的gym
,则可以通过env.unwrapped.get_action_meanings()
获得操作的含义。在env.render()
来可视化游戏。在下面是一个使用python3和最新版本的gym版本'0.10.9'呈现游戏的最小工作示例(您可以通过
gym.__version__
获得您的gym版本):相关问题 更多 >
编程相关推荐