Exemplo n.º 1
0
def run_game(b1_role,
             mcts_role,
             mcts2_role,
             b1_N,
             mcts_N,
             mcts2_N,
             model,
             rand=0):
    print(f'b1 ({" ".join(b1_role)}), N={b1_N}')
    print(f'mcts ({" ".join(mcts_role)}), N={mcts_N}')
    print(f'mcts2 ({" ".join(mcts2_role)}), N={mcts2_N}')
    curb1 = B1Node(propnet, data, model=model)
    curmcts = MCTSNode(propnet, data)
    curmcts2 = MCTSNode(propnet, data)
    board = [list('.' * 10) for i in range(8)]
    for step in range(1000):
        print(*(''.join(b) for b in board[::-1]), sep='\n')
        legal = curb1.propnet.legal_moves_dict(curb1.data)
        b1_moves = choose_move(curb1, b1_role, b1_N, legal, step < rand)
        mcts_moves = choose_move(curmcts, mcts_role, mcts2_N, legal,
                                 step < rand)
        mcts2_moves = choose_move(curmcts2, mcts2_role, mcts_N, legal,
                                  step < rand)
        taken_moves = dict(
            list(zip(b1_role, b1_moves)) + list(zip(mcts_role, mcts_moves)) +
            list(zip(mcts2_role, mcts2_moves)))
        moves = tuple(taken_moves[role] for role in propnet.roles)
        curb1 = curb1.get_or_make_child(moves)
        curmcts = curmcts.get_or_make_child(moves)
        curmcts2 = curmcts2.get_or_make_child(moves)
        print('Moves were:')
        for move in propnet.legal:
            if move.id in moves and move.move_gdl.strip() != 'noop':
                print(move.move_role, move.move_gdl)
                if 'drop' in move.move_gdl:
                    col = int(move.move_gdl.split()[2]) - 1
                    for i in range(len(board)):
                        if board[i][col] == '.':
                            board[i][col] = move.move_role[0]
                            break
        if curb1.terminal:
            print(*(''.join(b) for b in board[::-1]), sep='\n')
            break
    print('Results:', curb1.scores)
    return (
        sum(curb1.scores[role] for role in b1_role),
        sum(curb1.scores[role] for role in mcts_role),
        sum(curb1.scores[role] for role in mcts2_role),
    )
Exemplo n.º 2
0
def run_game(b1_role, mcts_role, b1_N, mcts_N, model, rand=0):
    print(f'b1 ({" ".join(b1_role)}), N={b1_N}')
    print(f'mcts ({" ".join(mcts_role)}), N={mcts_N}')
    curb1 = B1Node(propnet, data, model=model)
    curmcts = MCTSNode(propnet, data)
    for step in range(1000):
        legal = curb1.propnet.legal_moves_dict(curb1.data)
        b1_moves = choose_move(curb1, b1_role, b1_N, legal, step < rand)
        mcts_moves = choose_move(curmcts, mcts_role, mcts_N, legal,
                                 step < rand)
        taken_moves = dict(
            list(zip(b1_role, b1_moves)) + list(zip(mcts_role, mcts_moves)))
        moves = tuple(taken_moves[role] for role in propnet.roles)
        curb1 = curb1.get_or_make_child(moves)
        curmcts = curmcts.get_or_make_child(moves)
        print('Moves were:')
        for move in propnet.legal:
            if move.id in moves and move.move_gdl.strip() != 'noop':
                print(move.move_role, move.move_gdl)
                if 'drop' in move.move_gdl:
                    col = int(move.move_gdl.split()[2]) - 1
        if curb1.terminal:
            break
    print('Results:', curb1.scores)
    return (sum(curb1.scores[role] for role in b1_role),
            sum(curb1.scores[role] for role in mcts_role))