forked from Trussin/Chinese-Chess-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
53 lines (44 loc) · 1.53 KB
/
Game.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
from Net import Net
from MCTS import MCTS
from Board import Board
net = Net('./best_policy_1900.model') #'./best_policy_4.model'
count = 5000 # 训练的局数
count_ai = 1
board_move_data = []
board_round = []
board_result = []
# 第一个和第二个棋手, ai 1 人0
for n in range(1, count + 1):
board = Board(1, 1)
m=1
mcts = MCTS(net, board)
#print("第%d局开始"% (n))
while 1:
board.not_end()
if not board.not_end_number:
break
if board.current_player:
board.next_move = mcts.get_move() # 格式 xyab
else:
board.next_move = int(input('请输入下一步棋,格式xy ab: ')) # 输入格式 xyab
board.all_move.append(board.next_move)
board.move()
mcts.board = board
mcts.update_with_move()
m += 1
#print("移动了%d步,%d" % (m,board.next_move))
board.print_result(n)
board_move_data.append(board.all_move)
board_round.append(board.all_round)
board_result.append(board.result)
net_train_data = board.decode_data(mcts)
net_train_data = net.get_equi_data(net_train_data)
net.policy_update(net_train_data)
if count_ai%100 == 0:
net.save_model('./best_policy_' + str(count_ai) + '.model')
board.save_data(board_move_data, board_round, board_result, count_ai//100+1)
count_ai += 1
board_move_data = []
board_round = []
board_result = []
print('%d次训练完成,程序结束!' % (count))