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: object

Represents a league of players in a game.

Variables:
  • folder_league (str) – The folder path where the league is located.

  • seed (int) – The seed value for random number generation.

  • players_elo (ValueSortedDict) – A dictionary that stores the Elo ratings of the players.

  • players_args (dict[str, players.PlayerArgs]) – A dictionary that stores the arguments of the players.

  • players_number_of_games_played (dict[str, int]) – A dictionary that stores the number of games played by each player.

  • id_for_next_player (int) – The ID for the next player to join the league.

  • K (int) – The K-factor used in the Elo rating system.

  • ELO_HISTORY_LENGTH (int) – The length of Elo rating history to keep for each player.

  • games_already_played (int) – The number of games already played in the league.

ELO_HISTORY_LENGTH: int
K: int
__post_init__() None[source]

Initializes the league object.

This method is called after the object is created and initializes the necessary attributes. It also creates the required folders for logging and storing game data.

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.

update_elo_graph() None[source]

Updates the Elo rating graph.

This method updates the Elo rating graph by plotting the Elo ratings of all players in the league.

Module contents