-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
52 lines (41 loc) · 1.75 KB
/
Copy pathexample.py
File metadata and controls
52 lines (41 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
PyElo Library Example
This example demonstrates how to use the PyElo library to set up an Elo rating system,
create players, record game results, and rank players.
Author: Tony Cardillo
"""
from pyelo import (
set_mean, set_K, set_RPA, set_home_adv_amount,
create_player, add_game_results, rank_players, get_player_odds,
WIN, LOSS, DRAW, HOME_ADVANTAGE, NO_HOME_ADVANTAGE, AWAY_ADVANTAGE
)
# Step 1: Set up the Elo system
set_mean(1000) # Set the starting Elo of all players
set_K(30) # Set the K-factor for rating adjustments
set_RPA(400) # Set the RPA (Rating Point Adjustment) value
set_home_adv_amount(50) # Set the home advantage amount (additional points for the home team)
# Step 2: Create players
alice = create_player("Alice")
bob = create_player("Bob")
charlie = create_player("Charlie")
# Step 3: Record game results
# Alice plays Bob, Alice wins with a home advantage
add_game_results(alice, WIN, bob, LOSS, home_advantage=HOME_ADVANTAGE)
# Alice plays Charlie in a neutral game, and it's a draw
add_game_results(alice, DRAW, charlie, DRAW, home_advantage=NO_HOME_ADVANTAGE)
# Bob plays Charlie, Charlie wins with an away disadvantage
add_game_results(charlie, WIN, bob, LOSS, home_advantage=AWAY_ADVANTAGE)
# Step 4: Calculate the odds of Alice beating Bob
alice_vs_bob_odds = get_player_odds(alice, bob)
print(f"Odds of Alice beating Bob: {alice_vs_bob_odds:.2f}%")
# Step 5: Rank players by their current Elo ratings
ranked_players = rank_players()
print("Player Rankings:")
for player in ranked_players:
print(player)
# Output:
# Odds of Alice beating Bob: 56.53%
# Player Rankings:
# Name: Alice (Elo: 1016.4)
# Name: Charlie (Elo: 1012.8)
# Name: Bob (Elo: 970.8)