-
大小: 3.86MB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-08-13
- 語言: 其他
- 標(biāo)簽: AlphaGo??AlphaZero??五子棋??TensorFlow??深度學(xué)習(xí)??
資源簡介
此次資源為期末Tensorflow實(shí)戰(zhàn)項(xiàng)目,實(shí)現(xiàn)了基本的人機(jī)對戰(zhàn)、機(jī)機(jī)對戰(zhàn)、有10*10-4*4規(guī)格,其中樣本已經(jīng)訓(xùn)練好,但是并不是很智能,大家可以自己訓(xùn)練。代碼完整可運(yùn)行,使用pycharm進(jìn)行編寫的

代碼片段和文件信息
#?-*-?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?=?0?and?y?????
????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?????????????????????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??五子棋\人工智障\.idea\Gobang-AlphaGo-Zero-master.iml
?????目錄???????????0??2020-01-10?16:30??五子棋\人工智障\.idea\inspectionProfiles\
?????文件?????????174??2019-12-12?14:38??五子棋\人工智障\.idea\inspectionProfiles\profiles_settings.xm
?????文件?????????313??2019-12-12?14:39??五子棋\人工智障\.idea\misc.xm
?????文件?????????311??2019-12-12?14:38??五子棋\人工智障\.idea\modules.xm
?????文件?????????239??2019-12-25?16:45??五子棋\人工智障\.idea\other.xm
?????文件???????20588??2019-12-30?14:40??五子棋\人工智障\.idea\workspace.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__\real_mcts.cpython-37.pyc
?????文件?????1771532??2019-12-20?01:51??五子棋\人工智障\code\best_policy.model.data-00000-of-00001
?????文件????????1757??2019-12-20?01:51??五子棋\人工智障\code\best_policy.model.index
?????文件??????142151??2019-12-20?01:51??五子棋\人工智障\code\best_policy.model.me
?????文件?????????145??2019-12-20?22:21??五子棋\人工智障\code\checkpoint
?????文件????????5372??2019-12-17?23:17??五子棋\人工智障\code\chessboard.py
?????文件?????1771532??2019-12-20?22:21??五子棋\人工智障\code\current_policy.model.data-00000-of-00001
?????文件????????1757??2019-12-20?22:21??五子棋\人工智障\code\current_policy.model.index
?????文件??????142151??2019-12-20?22:21??五子棋\人工智障\code\current_policy.model.me
?????文件???????13068??2019-12-29?19:33??五子棋\人工智障\code\interface.py
?????文件????????6672??2019-12-18?21:35??五子棋\人工智障\code\policy_value_net.py
?????文件????????5736??2019-12-21?01:26??五子棋\人工智障\code\pure_mcts.py
?????文件????????8380??2019-12-21?00:33??五子棋\人工智障\code\real_mcts.py
?????文件???????13147??2019-12-21?19:41??五子棋\人工智障\code\train_pipeline.py
?????文件????????4444??2018-07-21?08:51??五子棋\人工智障\README.md
?????文件??????695695??2020-04-13?16:06??五子棋\五子棋實(shí)驗(yàn)報(bào)告.docx
............此處省略0個文件信息
- 上一篇:STC51指紋密碼鎖.rar
- 下一篇:白日門相關(guān)修改教程合集.zip
評論
共有 條評論