代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。