-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplaytest.py
62 lines (46 loc) · 1.48 KB
/
playtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Playtest the models as a human
'''
from __future__ import print_function
from game import Board, Game
from MonteCarloTreeSearchBasic import MCTSPlayer as MCTS_Pure
from MonteCarloTreeSearch import MCTSPlayer
from policy_value_network import PolicyValueNetwork
class Human(object):
"""
human player
"""
def __init__(self):
self.player = None
def set_player(self, p):
self.player = p
def get_action(self, board):
try:
loc = input("Your move: ")
if isinstance(loc, str):
loc = [int(n, 10) for n in loc.split(",")]
move = board.loc_to_move(loc)
except Exception as e:
move = -1
if move == -1 or move not in board.available_moves:
print("invalid move")
move = self.get_action(board)
return move
def __str__(self):
return "Human {}".format(self.player)
def run():
k = 5
width, height = 7, 7
model_file = 'best_policy.model'
try:
board = Board(width=width, height=height, k_in_row=k)
game = Game(board)
best_policy = PolicyValueNetwork(width, height, model= model_file)
mcts_player = MCTSPlayer(best_policy.policy_value_function, c_puct=5, n_playout=400)
human = Human()
# set start_player=0 for human first
game.play(human, mcts_player, start_player=0, display=1)
except KeyboardInterrupt:
print('\n\rquit')
if __name__ == '__main__':
run()