Create functional ELO tracker

main
Bram van den Heuvel 2026-06-23 19:42:18 +02:00
parent eabf15ddbe
commit bb3bb36665
3 changed files with 10 additions and 9 deletions

9
elo.py
View File

@ -5,9 +5,6 @@
from elo_tracker import EloTracker from elo_tracker import EloTracker
from pyclient.games import TicTacToe from pyclient.games import TicTacToe
import pyclient
import time
GAME_FILE = "games.jsonl" GAME_FILE = "games.jsonl"
PLAYER_FILE = "known_players.json" PLAYER_FILE = "known_players.json"
@ -20,14 +17,14 @@ def main() -> int:
tracker.start_periodic_matches( tracker.start_periodic_matches(
game=TicTacToe.empty(), game=TicTacToe.empty(),
interval_seconds=60, interval_seconds=10 * 60,
player_count=2, player_count=2,
) )
try: try:
while True: tracker.start_server(import_name=__name__)
pass
except KeyboardInterrupt: except KeyboardInterrupt:
print("Noticed KeyboardInterrupt, stopping match daemon...")
tracker.stop_periodic_matches() tracker.stop_periodic_matches()
return 0 return 0

View File

@ -206,7 +206,7 @@ class Match:
participants : list[tuple[PlayerIdentifier, FinishState]] = [] participants : list[tuple[PlayerIdentifier, FinishState]] = []
for i, agent in enumerate(players): for i, agent in enumerate(players):
finish_state = results.get(i, None) finish_state = results.get(i + 1, None)
if finish_state is None: if finish_state is None:
continue continue
@ -395,6 +395,9 @@ class EloTracker:
rating_1 = self.__get_stat(player_id=player_id1).elo rating_1 = self.__get_stat(player_id=player_id1).elo
for player_id2, result2 in m.participants: for player_id2, result2 in m.participants:
if player_id1 == player_id2:
continue
rating_2 = self.__get_stat(player_id=player_id2).elo rating_2 = self.__get_stat(player_id=player_id2).elo
expected_score = 1 / (1 + 10 ** ((rating_2 - rating_1) / STD_DEV_DIFF)) expected_score = 1 / (1 + 10 ** ((rating_2 - rating_1) / STD_DEV_DIFF))
@ -583,7 +586,7 @@ class EloTracker:
:rtype: pyclient.GameReplay :rtype: pyclient.GameReplay
:raises ValueError: One of the URLs could not be accessed. :raises ValueError: One of the URLs could not be accessed.
""" """
agents = [ agents : list[Any] = [
pyclient.Agent.from_url(url, debug=self.debug) pyclient.Agent.from_url(url, debug=self.debug)
for url in players for url in players
] ]

View File

@ -1,5 +1,6 @@
{ {
"players": [ "players": [
"https://bmt001.noordstar.me" "https://bmt001.noordstar.me",
"https://bmt002.noordstar.me"
] ]
} }