1 Star 0 Fork 0

gypsophila/gobang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
play.py 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
gypsophila 提交于 2023-07-10 10:31 . 可以跑了,第一代模型
from game import Board, Game
from mcts_alphaZero import MCTSPlayer
from policy_value_net_pytorch import PolicyValueNet
class Human(object):
"""human player"""
def __init__(self):
self.player = None
def set_player_ind(self, p):
self.player = p
def get_action(self, board):
try:
location = input("Your move:")
if isinstance(location, str): # for python3
location = [int(n, 10) for n in location.split(",")]
move = board.location_to_move(location)
except Exception as e:
move = -1
if move == -1 or move not in board.available:
print("invalid move")
move = self.get_action(board)
return move
def __str__(self):
return "Human {}".format(self.player)
def run():
n = 5
width, height = 8, 8
model_file = 'current_policy.pkl'
try:
board = Board(width=width, height=height, n_in_row=n)
game = Game(board)
# 创建AI player
best_policy = PolicyValueNet(width, height, model_file=model_file)
mcts_player = MCTSPlayer(best_policy.policy_value_fn, c_puct=5, n_playout=400)
# 创建 Human player ,输入样例:2,3
human = Human()
# 设置 start_player=0 可以让人类先手
game.start_play(human, mcts_player, start_player=1, is_shown=1)
except KeyboardInterrupt:
print('\n\rquit')
if __name__ == '__main__':
run()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/ma-canglong/gobang.git
git@gitee.com:ma-canglong/gobang.git
ma-canglong
gobang
gobang
master

搜索帮助