Exemplo n.º 1
0
def accept_invitation_and_play(server_url, auth, invitation_id, bot_cls,
                               finished):
    # make sure this process doesn't react to interrupt signals
    signal.signal(signal.SIGTERM, signal.SIG_IGN)
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    print('[{}] Accepting invitation {}.'.format(datetime.now(),
                                                 invitation_id))

    server = RBCServer(server_url, auth)
    game_id = server.accept_invitation(invitation_id)

    print('[{}] Invitation {} accepted. Playing game {}.'.format(
        datetime.now(), invitation_id, game_id))

    try:
        play_remote_game(server_url, game_id, auth, bot_cls())
        print('[{}] Finished game {}'.format(datetime.now(), game_id))
    except:
        print('[{}] Fatal error in game {}:'.format(datetime.now(), game_id))
        traceback.print_exc()
        server.error_resign(game_id)
    finally:
        server.finish_invitation(invitation_id)
        finished.value = True
Exemplo n.º 2
0
def accept_invitation_and_play(server_url, auth, invitation_id, bot_cls):
    print('[{}] Accepting invitation {}.'.format(datetime.now(),
                                                 invitation_id))

    server = RBCServer(server_url, auth)
    game_id = server.accept_invitation(invitation_id)

    print('[{}] Invitation {} accepted. Playing game {}.'.format(
        datetime.now(), invitation_id, game_id))

    play_remote_game(server_url, game_id, auth, bot_cls())

    print('[{}] Finished game {}'.format(datetime.now(), game_id))
Exemplo n.º 3
0
def accept_invitation_and_play(server_url, auth, invitation_id, bot_cls):
    print('[{}] Accepting invitation {}.'.format(datetime.now(), invitation_id))

    server = RBCServer(server_url, auth)
    game_id = server.accept_invitation(invitation_id)

    print('[{}] Invitation {} accepted. Playing game {}.'.format(datetime.now(), invitation_id, game_id))

    try:
        play_remote_game(server_url, game_id, auth, bot_cls())
        print('[{}] Finished game {}'.format(datetime.now(), game_id))
    except:
        print('[{}] Fatal error in game {}:'.format(datetime.now(), game_id))
        traceback.print_exc()
        server.error_resign(game_id)
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--color',
                        default='random',
                        choices=['white', 'black', 'random'],
                        help='The color you want to play as.')
    parser.add_argument('--server-url',
                        default='https://rbc.jhuapl.edu',
                        help='URL of the server.')
    args = parser.parse_args()

    auth = ask_for_auth()

    server = RBCServer(args.server_url, auth)

    usernames = server.get_active_users()

    if auth[0] in usernames:
        usernames.remove(auth[0])

    if len(usernames) == 0:
        print('No active users.')
        quit()

    for i, username in enumerate(usernames):
        print('[{}] {}'.format(i, username))
    i = int(input('Choose opponent: '))

    color = chess.WHITE
    if args.color == 'black' or (args.color == 'random'
                                 and random.uniform(0, 1) < 0.5):
        color = chess.BLACK

    game_id = server.send_invitation(usernames[i], color)

    winner_color, win_reason, game_history = play_remote_game(
        args.server_url, game_id, auth, UIPlayer())

    winner = 'Draw' if winner_color is None else chess.COLOR_NAMES[winner_color]
    timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    game_history.save('{}_{}_{}.json'.format(timestamp, game_id, winner))