TensorFlow五子棋
此次资源为期末Tensorflow实战项目,实现了基本的人机对战、机机对战、有10*10-4*4规格,其中样本已经训练好,但是并不是很智能,大家可以自己训练。代码完整可运行,使用pycharm进行编写的
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-01-10 16:30 五子棋人工智障
目录 0 2020-01-10 16:30 五子棋人工智障.idea
文件 559 2019-12-25 16:45 五子棋人工智障.ideaGobang-AlphaGo-Zero-master.iml
目录 0 2020-01-10 16:30 五子棋人工智障.ideainspectionProfiles
文件 174 2019-12-12 14:38 五子棋人工智障.ideainspectionProfilesprofiles_settings.xml
文件 313 2019-12-12 14:39 五子棋人工智障.ideamisc.xml
文件 311 2019-12-12 14:38 五子棋人工智障.ideamodules.xml
文件 239 2019-12-25 16:45 五子棋人工智障.ideaother.xml
文件 20588 2019-12-30 14:40 五子棋人工智障.ideaworkspace.xml
目录 0 2020-01-10 16:30 五子棋人工智障code
目录 0 2020-01-10 16:30 五子棋人工智障code\__pycache__
文件 3858 2019-12-17 23:19 五子棋人工智障code\__pycache__chessboard.cpython-37.pyc
文件 6472 2019-12-21 19:41 五子棋人工智障code\__pycache__interface.cpython-37.pyc
文件 3439 2019-12-19 08:23 五子棋人工智障code\__pycache__policy_value_net.cpython-37.pyc
文件 3403 2019-12-21 01:27 五子棋人工智障code\__pycache__pure_mcts.cpython-37.pyc
文件 3893 2019-12-21 00:39 五子棋人工智障code\__pycache__
eal_mcts.cpython-37.pyc
文件 1771532 2019-12-20 01:51 五子棋人工智障codeest_policy.model.data-00000-of-00001
文件 1757 2019-12-20 01:51 五子棋人工智障codeest_policy.model.index
文件 142151 2019-12-20 01:51 五子棋人工智障codeest_policy.model.meta
文件 145 2019-12-20 22:21 五子棋人工智障codecheckpoint
文件 5372 2019-12-17 23:17 五子棋人工智障codechessboard.py
文件 1771532 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.data-00000-of-00001
文件 1757 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.index
文件 142151 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.meta
文件 13068 2019-12-29 19:33 五子棋人工智障codeinterface.py
文件 6672 2019-12-18 21:35 五子棋人工智障codepolicy_value_net.py
文件 5736 2019-12-21 01:26 五子棋人工智障codepure_mcts.py
文件 8380 2019-12-21 00:33 五子棋人工智障code
eal_mcts.py
文件 13147 2019-12-21 19:41 五子棋人工智障code rain_pipeline.py
文件 4444 2018-07-21 08:51 五子棋人工智障README.md
文件 695695 2020-04-13 16:06 五子棋五子棋实验报告.docx
............此处省略0个文件信息
# -*- coding: utf-8 -*-
“““
Created on Sun Apr 8 17:23:01 2018
@author: sjt
“““
import numpy as np
base = [1]
for i in range(1 300):
base.append(base[i - 1] * 3)
class chessboard(object):
def __init__(self length = 10 n_in_rows = 5):
#chessboard size
self.n_in_rows = n_in_rows
self.length = length
self.player = int(1)
self.board = np.zeros((self.length self.length)).astype(int)#0 empty 1 black 2 white
#valid moves
self.availables = set()
limit = self.length * self.length
for i in range(limit):
self.availables.add(i)
#direction for check
self.direction_x = [1 -1 1 -1 0 0 1 -1]
self.direction_y = [1 -1 -1 1 1 -1 0 0]
#value for hashing
self.hash_board = 0
#record the history board
self.excuted_step = 0
self.history1 = [] #record the history of first player
self.history2 = [] #record the history of second player both are in value 0 or 1
def change_player(self):
self.player = 3 - self.player
def position_to_index(self position):
return self.length * position[0] + position[1]
def index_to_position(self index):
return (index // self.length index % self.length)
def point_in_chessboard(self x y):
return x >= 0 and x < self.length and y >= 0 and y < self.length
def check_point(self position):
x = position[0]
y = position[1]
player = self.board[position]
for i in range(4):
cnt = 1
for j in range(1 self.n_in_rows):
dx = x + j * self.direction_x[i * 2]
dy = y + j * self.direction_y[i * 2]
#print(dx dy)
if (self.point_in_chessboard(dx dy) and self.board[(dx dy)] == player):
cnt = cnt + 1
#print(dx dy)
else:
break
for j in range(1 self.n_in_rows):
dx = x + j * self.direction_x[i * 2 + 1]
dy = y + j * self.direction_y[i * 2 + 1]
if (self.point_in_chessboard(dx dy) and self.board[(dx dy)] == player):
cnt = cnt + 1
else:
break
if cnt >= self.n_in_rows:
return True
return False
def get_state(self num_history):#need to see as current player
if self.player == 1:
state = [np.zeros_like(self.board)]
for i in range(1 num_history + 1):
#print(‘get_state‘ i)
if i < self.excuted_step:
state = np.concatenate((state [self.history1[-i]]))
state = np.concatenate((state [self.history2[-i]]))
else:
state = np.concatenate((state [np.zeros_like(self.board)]))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-01-10 16:30 五子棋人工智障
目录 0 2020-01-10 16:30 五子棋人工智障.idea
文件 559 2019-12-25 16:45 五子棋人工智障.ideaGobang-AlphaGo-Zero-master.iml
目录 0 2020-01-10 16:30 五子棋人工智障.ideainspectionProfiles
文件 174 2019-12-12 14:38 五子棋人工智障.ideainspectionProfilesprofiles_settings.xm
文件 313 2019-12-12 14:39 五子棋人工智障.ideamisc.xm
文件 311 2019-12-12 14:38 五子棋人工智障.ideamodules.xm
文件 239 2019-12-25 16:45 五子棋人工智障.ideaother.xm
文件 20588 2019-12-30 14:40 五子棋人工智障.ideaworkspace.xm
目录 0 2020-01-10 16:30 五子棋人工智障code
目录 0 2020-01-10 16:30 五子棋人工智障code\__pycache__
文件 3858 2019-12-17 23:19 五子棋人工智障code\__pycache__chessboard.cpython-37.pyc
文件 6472 2019-12-21 19:41 五子棋人工智障code\__pycache__interface.cpython-37.pyc
文件 3439 2019-12-19 08:23 五子棋人工智障code\__pycache__policy_value_net.cpython-37.pyc
文件 3403 2019-12-21 01:27 五子棋人工智障code\__pycache__pure_mcts.cpython-37.pyc
文件 3893 2019-12-21 00:39 五子棋人工智障code\__pycache__
eal_mcts.cpython-37.pyc
文件 1771532 2019-12-20 01:51 五子棋人工智障codeest_policy.model.data-00000-of-00001
文件 1757 2019-12-20 01:51 五子棋人工智障codeest_policy.model.index
文件 142151 2019-12-20 01:51 五子棋人工智障codeest_policy.model.me
文件 145 2019-12-20 22:21 五子棋人工智障codecheckpoint
文件 5372 2019-12-17 23:17 五子棋人工智障codechessboard.py
文件 1771532 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.data-00000-of-00001
文件 1757 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.index
文件 142151 2019-12-20 22:21 五子棋人工智障codecurrent_policy.model.me
文件 13068 2019-12-29 19:33 五子棋人工智障codeinterface.py
文件 6672 2019-12-18 21:35 五子棋人工智障codepolicy_value_net.py
文件 5736 2019-12-21 01:26 五子棋人工智障codepure_mcts.py
文件 8380 2019-12-21 00:33 五子棋人工智障code
eal_mcts.py
文件 13147 2019-12-21 19:41 五子棋人工智障code rain_pipeline.py
文件 4444 2018-07-21 08:51 五子棋人工智障README.md
文件 695695 2020-04-13 16:06 五子棋五子棋实验报告.docx
............此处省略0个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)