chipiron.league package
Submodules
chipiron.league.league module
This module defines the League class, which represents a league of players in a game.
- class chipiron.league.league.League(folder_league: str, seed: int, players_elo: ~sortedcollections.recipes.ValueSortedDict = <factory>, players_args: dict[str, chipiron.players.player_args.PlayerArgs] = <factory>, players_number_of_games_played: dict[str, int] = <factory>, id_for_next_player: int = 0, K: int = 10, ELO_HISTORY_LENGTH: int = 500, games_already_played: int = 0)[source]
Bases:
objectRepresents a league of players in a game.
- folder_league
The folder path where the league is located.
- Type:
str
- seed
The seed value for random number generation.
- Type:
int
- players_elo
A dictionary that stores the Elo ratings of the players.
- Type:
ValueSortedDict
- players_args
A dictionary that stores the arguments of the players.
- Type:
dict[str, players.PlayerArgs]
- players_number_of_games_played
A dictionary that stores the number of games played by each player.
- Type:
dict[str, int]
- id_for_next_player
The ID for the next player to join the league.
- Type:
int
- K
The K-factor used in the Elo rating system.
- Type:
int
- ELO_HISTORY_LENGTH
The length of Elo rating history to keep for each player.
- Type:
int
- games_already_played
The number of games already played in the league.
- Type:
int
- ELO_HISTORY_LENGTH: int
- K: int
- check_for_players() None[source]
Checks for new players joining the league.
This method checks if there are any new player files in the ‘new_players’ folder and adds them to the league.
- folder_league: str
- games_already_played: int
- id_for_next_player: int
- new_player_joins(file_player: str) None[source]
Adds a new player to the league.
- Parameters:
file_player (str | os.PathLike[str]) – The path to the player file.
This method adds a new player to the league by reading the player file, assigning a unique ID to the player, and updating the necessary attributes.
- players_args: dict[str, chipiron.players.player_args.PlayerArgs]
- players_elo: ValueSortedDict
- players_number_of_games_played: dict[str, int]
- print_info() None[source]
Prints information about the league.
This method prints information about the league, such as the players and their Elo ratings.
- run() None[source]
Runs a game in the league.
This method selects two players from the league, plays a game between them, updates the Elo ratings, and saves the results.
- save() None[source]
Saves the league.
This method saves the league by serializing its state to a file.
- seed: int
- select_two_players() tuple[chipiron.players.player_args.PlayerArgs, chipiron.players.player_args.PlayerArgs][source]
Selects two players from the league.
- Returns:
A tuple containing the arguments of the two selected players.
- Return type:
tuple[players.PlayerArgs, players.PlayerArgs]
This method randomly selects two players from the league to participate in a game.
- update_elo(match_results: MatchResults, path_logs_file: str | PathLike[str]) None[source]
Updates the Elo ratings of the players based on the match results.
- Parameters:
match_results (MatchResults) – The results of the match.
path_logs_file (path) – The path to the log file.
This method calculates the Elo rating changes for the players based on the match results and updates their ratings. It also logs the changes in the log file.