diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-02-19 12:47:44 +0100 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-02-19 12:47:44 +0100 |
| commit | 99f7e18c12945e9fbe22524a84a85e5733898dd2 (patch) | |
| tree | 9915227803f007bd4886ce2e997959e4cd30516c /strategy.py | |
| parent | af087e34e7a60e75db349aa9b3bb671b2aa70bfc (diff) | |
refactor: Split files
Diffstat (limited to 'strategy.py')
| -rw-r--r-- | strategy.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/strategy.py b/strategy.py new file mode 100644 index 0000000..85ea3e0 --- /dev/null +++ b/strategy.py @@ -0,0 +1,36 @@ +from typing import Protocol + +from game import Game +from player import Player + + +class GameEloChangeStrategy(Protocol): + def proccess_game( + self, game: Game, current_elo: dict[Player, int] + ) -> dict[Player, float]: + ... + + +class SimpleEloChangeStrategy(GameEloChangeStrategy): + D = 400 + K = 32 + + def proccess_game( + self, game: Game, current_elo: dict[Player, int] + ) -> dict[Player, float]: + players_elo_updates = {player: 0.0 for player in game.scores} + + for player_1, score_1 in game.scores.items(): + for player_2, score_2 in game.scores.items(): + if player_1 != player_2: + expected_score = 1 / ( + 1 + + 10 + ** ((current_elo[player_2] - current_elo[player_1]) / self.D) + ) + result = ( + 1.0 if score_1 > score_2 else 0.0 if score_1 < score_2 else 0.5 + ) + players_elo_updates[player_1] += self.K * (result - expected_score) + + return players_elo_updates |
