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()
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