roulette/index.html

104 lines
3.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Roulette Demo</title>
<!-- <link rel="icon" type="image/png" href="favicon.png" /> -->
<link rel="stylesheet" href="https://pyscript.net/releases/2022.09.1/pyscript.css" />
<script defer src="https://pyscript.net/releases/2022.09.1/pyscript.js"></script>
<link rel="stylesheet" href="./assets/css/examples.css" />
<link rel="stylesheet" href="./assets/prism/prism.css" />
<script defer src="./assets/prism/prism.js"></script>
</head>
<body>
<nav class="navbar" style="background-color: #000000;">
<div class="app-header">
<!-- <a href="/">
<img src="./logo.png" class="logo">
</a> -->
<a class="title" href="" style="color: #0d88c2;">Roulette</a>
<a href="https://git.clfx.cc/mm/roulette/src/branch/main/pyroulette/roulette.py" style="color: #ffffff;">(roulette.py)</a>
<a href="https://git.clfx.cc/mm/roulette/src/branch/main/index.html" style="color: #a6dc28;">(index.html)</a>
</div>
</nav>
<section class="pyscript">
<div class="font-mono">
<h1 align="center">Let's Hack Roulette!</h1>
<h2 align="center">
Simulating 100 Games for 500 Players
</h2>
<p>
Note: winnings are re-invested, each player starts with $100 and chooses a strategy at random.
</p>
<label id="outputDiv"></label>
</div>
<center>
<div id="outputDiv2" class="font-mono"></div>
</center>
<br>
<div id="outputDiv3" class="font-mono"></div>
<br>
<py-config>
packages = [
"pyroulette",
]
</py-config>
<py-script output="outputDiv2">
import pyroulette as pr
# seed(59)
from random import random, randint
players = []
# iterations * num_per_group = num_players
for _ in range(1, 50):
c = random()
if c < 0.25:
min_games = randint(1, 100)
elif c < 0.5:
min_games = randint(1, 25)
else: # bold half
min_games = randint(1, 2)
# min_games = 100 # this caps out at about $250 wallet. need to bet bigger to win bigger.
players.extend(pr.generate_players(num_players=10, 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 some statistics
avg_wallet = sum(wallets) / len(wallets)
median_wallet = sorted(wallets)[len(wallets) // 2]
# calculate winnings
winnings = [p.wallet - p.budget for p in players]
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])
# 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}")
</py-script>
<py-script output="outputDiv3">
for p in sorted(players, reverse=True):
print("\n<br>", p)
</py-script>
</section>
</body>
</html>