From 7200fcf3f4e4c22193b5b96452f9aa5131b1bc1c Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 19 Feb 2023 12:57:27 +0100 Subject: refactor: Move to src --- src/strategy.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/strategy.py (limited to 'src/strategy.py') diff --git a/src/strategy.py b/src/strategy.py new file mode 100644 index 0000000..6713299 --- /dev/null +++ b/src/strategy.py @@ -0,0 +1,40 @@ +from typing import Protocol + +from src.game import Game +from src.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 -- cgit v1.3