iteration = 6 while iteration in range(7): print('Game ' + str(iteration)) net1 = Residual() net2 = Residual() net1.load_model('models/model' + str(iteration)) net2.load_model('models/model' + str(iteration + 1)) tree_search_1 = MCTS(net1, Node()) tree_search_2 = MCTS(net2, Node()) game = Game() # Starting 1 Self-play Game step = 1 draw = False while game.check_game_over() == 0: clone = game.clone() # Player 1 if step % 2 != 0: predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone()) game.play_action(predicted_action) # print('P1 Non Chain -> ', end='\t') # print(predicted_action) if clone.if_attack_move(predicted_action): while game.attack_move_available( game.remove_except_current(predicted_action)): predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone(), chain_move=True, action=predicted_action) game.play_action(predicted_action)
# Starting 1 Self-play -> Training Iteration iteration = 0 net = Residual() net.load_model('models/model' + str(iteration)) while iteration < 15: tree_search_1 = MCTS(net, Node()) tree_search_2 = MCTS(net, Node()) store = Store() game = Game() # Starting 1 Self-play Game step = 1 draw = False while game.check_game_over() == 0: clone = game.clone() # Player 1 if step % 2 != 0: predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone()) temp_policy = get_tree_policy(temp_children, temp_moves) store.update_store([game.clone().state, temp_policy, 0], player1=True) game.play_action(predicted_action) print('P1 Non Chain -> ', end='\t') print(predicted_action) if clone.if_attack_move(predicted_action): while game.attack_move_available( game.remove_except_current(predicted_action)): predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone(),
print('') pass if __name__ == '__main__': net = Residual() net.load_model('models/model11') tree_search_1 = MCTS(net, Node()) human = Human() game = Game() print('Game has started !') print_board(game.state) step = 1 while game.check_game_over() == 0: clone = game.clone() # Player 1 if step % 2 != 0: predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone()) game.play_action(predicted_action) print('Computer moved:', end='\t') print('(' + str(predicted_action[0]) + ',' + str(predicted_action[1]) + ') -> (' + str(predicted_action[2]) + ',' + str(predicted_action[3]) + ')') if clone.if_attack_move(predicted_action): while game.attack_move_available( game.remove_except_current(predicted_action)): predicted_action, temp_children, temp_moves = tree_search_1.search( game.clone(), chain_move=True, action=predicted_action)