better printout
This commit is contained in:
parent
88c386d440
commit
250649d439
34
index.html
34
index.html
@ -26,19 +26,19 @@
|
|||||||
</nav>
|
</nav>
|
||||||
<section class="pyscript">
|
<section class="pyscript">
|
||||||
<div class="font-mono">Simulating 100 Games for 1000 Players: <label id="outputDiv"></label></div>
|
<div class="font-mono">Simulating 100 Games for 1000 Players: <label id="outputDiv"></label></div>
|
||||||
<br>
|
|
||||||
<div id="outputDiv2" class="font-mono"></div>
|
|
||||||
<div id="outputDiv3" class="font-mono"></div>
|
|
||||||
<center>
|
<center>
|
||||||
<div id="hist"></div>
|
<div id="outputDiv2" class="font-mono"></div>
|
||||||
</center>
|
</center>
|
||||||
|
<br>
|
||||||
|
<div id="outputDiv3" class="font-mono"></div>
|
||||||
|
<br>
|
||||||
<py-config>
|
<py-config>
|
||||||
packages = [
|
packages = [
|
||||||
"pyroulette",
|
"pyroulette",
|
||||||
"matplotlib"
|
"matplotlib"
|
||||||
]
|
]
|
||||||
</py-config>
|
</py-config>
|
||||||
<py-script output="hist">
|
<py-script output="outputDiv2">
|
||||||
import pyroulette as pr
|
import pyroulette as pr
|
||||||
|
|
||||||
# seed(59)
|
# seed(59)
|
||||||
@ -59,14 +59,30 @@ players = pr.play_roulette(players, games=100)
|
|||||||
|
|
||||||
# get the wallet values for all players as a list
|
# get the wallet values for all players as a list
|
||||||
wallets = [player.wallet for player in players]
|
wallets = [player.wallet for player in players]
|
||||||
# plot the wallet values as a histogram
|
# 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}")
|
||||||
</py-script>
|
</py-script>
|
||||||
<py-script>
|
|
||||||
|
<py-script output="outputDiv3">
|
||||||
for p in sorted(players, reverse=True):
|
for p in sorted(players, reverse=True):
|
||||||
print(p, "\n<br>")
|
print("\n<br>", p)
|
||||||
</py-script>
|
</py-script>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user