packages = [
"pyroulette",
"matplotlib"
]
import pyroulette as pr
# seed(59)
from random import randint
players = []
for _ in range(1, 20):
c = randint(0, 3)
if c == 0:
min_games = randint(1, 100)
elif c == 1:
min_games = randint(1, 25)
else:
min_games = randint(1, 2)
players.extend(pr.generate_players(num_players=50, min_num_games=min_games, total_budget=100))
players = pr.play_roulette(players, games=100)
# get the wallet values for all players as a list
wallets = [player.wallet for player in players]
# calculate the average wallet value
avg_wallet = sum(wallets) / len(wallets)
median_wallet = sorted(wallets)[len(wallets) // 2]
# calculate winnings
winnings = [p.wallet - p.budget for p in players]
# calculate the number of players who lost all their money
num_losers = len([w for w in winnings if w <= 0])
num_winners = len([w for w in winnings if w > 0])
num_bankrupt = len([l for l in wallets if l == 0])
# calculate the number of players who won more than they started with
# print the results
print(f"Average wallet value: {avg_wallet}\n")
print(f"Median wallet value: {median_wallet}\n")
print(f"Number of players who lost money: {num_losers}, proportion: {num_losers / len(players):.2f}")
print(f"Number of players who went bankrupt: {num_bankrupt}, proportion: {num_bankrupt / len(players):.2f}")
print()
print(f"Number of players who won more than they started with: {num_winners}, proportion: {num_winners / len(players):.2f}")
for p in sorted(players, reverse=True):
print("\n ", p)