openai健身房的tic-tac-toe环境
gym-tictactoe的Python项目详细描述
在openai健身房进行的tic tac toe游戏
tic-tac-toe的3d版本是作为openai的健身房环境实现的。这个^{
复杂性
传统的(2d)tic tac toe游戏空间非常小(9^3)。相比之下,本回购协议中的3D版本空间更大,约为81^3。这使得基于计算机的玩家使用搜索和剪枝技术的游戏空间代价高昂。
相反,目前的学习模式是基于政策梯度和深度q-学习。DQN model产生了非常有希望的结果。如果你感兴趣的话,可以自己去体验和贡献。PG-based model需要更多的工作:)
贡献
在游戏开发和学习中,回购协议也对拉取请求和协作开放。
依赖关系
- 基依赖项:
gym
。 - 绘图呈现依赖项:
numpy
,matplotlib
。 - 学习依赖:
tensorflow
,numpy
。
安装
要安装,请运行:
# In your virtual environment pip install gym-tictactoe
用法
目前支持两种不同渲染模式的环境。
文本呈现
要使用文本呈现,请将环境创建为tictactoe-v0
,如下所示:
importgymimportgym_tictactoedefplay_game(actions,step_fn=input):env=gym.make('tictactoe-v0')env.reset()# Play actions in action profileforactioninactions:print(env.step(action))env.render()ifstep_fn:step_fn()returnenvactions=['1021','2111','1221','2222','1121']_=play_game(actions,None)
产生的输出是:
Step 1:
- - - - - - - - -
- - x - - - - - -
- - - - - - - - -
Step 2:
- - - - - - - - -
- - x - o - - - -
- - - - - - - - -
Step 3:
- - - - - - - - -
- - x - o - - - x
- - - - - - - - -
Step 4:
- - - - - - - - -
- - x - o - - - x
- - - - - - - - o
Step 5:
- - - - - - - - -
- - X - o X - - X
- - - - - - - - o
游戏结束后的获胜顺序:(0,2,1), (1,2,1), (2,2,1)
。
绘制渲染
要使用文本呈现,请将环境创建为tictactoe-plt-v0
,如下所示:
importgymimportgym_tictactoedefplay_game(actions,step_fn=input):env=gym.make('tictactoe-plt-v0')env.reset()# Play actions in action profileforactioninactions:print(env.step(action))env.render()ifstep_fn:step_fn()returnenvactions=['1021','2111','1221','2222','1121']_=play_game(actions,None)
这将产生以下游戏性:
第一步:
步骤2: 步骤3: 步骤4: 步骤5:dqn学习
当前模型位于^{
由训练模型生成的游戏示例(获胜顺序为(0,0,0), (1,0,0), (2,0,0)
):