def test_stability():
    '''
    Test completely CPU-driven games.

    Expansions and number of CPU players are randomly selected for each game.
    '''
    game = Game()
    # Add a randomly selected set of expansions into the game
    num_expansions = random.randint(0, len(EXPANSIONS))
    expansions_to_include = random.sample(EXPANSIONS, num_expansions)
    for expansion in expansions_to_include:
        game.add_expansion(expansion)
    # Add a random number (2-4) players into the game
    num_players = random.randint(2, 4)
    for _ in range(num_players):
        game.add_player(interactions_class=AutoInteraction)
    game.start()
示例#2
0
def play_game(card_set, num_players, verbose):
    """Plays a game of Dominion, displaying the initial game state and then
    running the game simulation.
    """
    agent_dict = {'Human Player 1': HMIAgent()}
    demo_game = Game(n_players=num_players,
                     agents=agent_dict,
                     card_set=card_set,
                     verbose=verbose)

    demo_game.players[0].display_deck()
    print("")

    demo_game.players[0].display_hand()
    print("")

    demo_game.players[0].display_draw_pile()
    print("")

    demo_game.players[0].display_discard_pile()
    print("")

    demo_game.play_game()
示例#3
0
def create_room(sid, data):
    username = data['username']
    try:
        if data['client_type'] == 'browser':
            interaction_class = BrowserInteraction
    except KeyError:
        interaction_class = NetworkedCLIInteraction
    characters = string.ascii_uppercase + string.digits
    # Create a unique room ID
    room = ''.join(random.choice(characters) for i in range(4))
    while room in games:
        room = ''.join(random.choice(characters) for i in range(4))
    # Add the user to the room
    socketio.enter_room(sid, room)
    sids[sid] = (room, data)
    # Create the game object
    game = Game(socketio=socketio, room=room)
    # Add the game object to the global dictionary of games
    games[room] = game
    # Add the player to the game
    game.add_player(username, sid, interactions_class=interaction_class)
    socketio.send(f'{username} has created room {room}\n', room=room)
    return room  # This activates the client's set_room() callback