-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
39 lines (30 loc) · 919 Bytes
/
test.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
from mcts.mcts import MCTS
from tablut.game import Game, Player
from tablut.rules.ashton import Board
from tablut.player import RandomPlayer
import time
from copy import deepcopy
import pprint
board = Board()
game = Game(board)
black_player = RandomPlayer(game, Player.BLACK)
# mcts parameters
num_reads = 100
max_depth = 50
mcts = MCTS(deepcopy(game), max_depth=max_depth)
node = None
while not game.ended:
tick = time.time()
start, end = mcts.search(num_reads)
# TODO: Reuse the tree
tock = time.time()
print("%s -> %s _ %.2fs" % (start, end, tock - tick))
game.white_move(start, end)
mcts.game.white_move(start, end)
black_player.play()
# infer black player move and reuse the old subtree
mcts_board = mcts.game.board
opp_start, opp_end = mcts_board.infer_move(game.board.board)
mcts.new_root(opp_start, opp_end)
pprint.pprint(game.board.pack(game.board.board))
print(game.winner)